spatial-data-frame

Convert data frame to spatial lines data frame in R with x,y x,y coordintates

爷,独闯天下 提交于 2019-12-12 04:24:10
问题 I have a data frame in R, one of the columns contains the coordinates for points along a line in the form: x,y x,y x,y x,y So the whole data frame looks like id dist speed coord 1 45 6 1.294832,54.610240 -1.294883,54.610080 -1.294262,54.6482757 2 23 34 2.788732,34.787940 6.294883,24.567080 -5.564262,-45.7676757 I would like to convert this to a spatial lines data frame, and I assume that the fist step would be to separate the coordinates into two columns in the from: x, x, x, x y, y, y, y But

Creating spatialpolygons dataframe from list of polygons

痴心易碎 提交于 2019-12-11 05:07:10
问题 I am currently trying to create a polygon shapefile from a list of polygons (study areas for biodiversity research). Currently these polygons are stored in a list in this format: $SEW22 [,1] [,2] [1,] 427260.4 5879458 [2,] 427161.4 5879472 [3,] 427175.0 5879571 [4,] 427273.9 5879557 [5,] 427260.4 5879458 $SEW23 [,1] [,2] [1,] 418011.0 5867216 [2,] 417912.0 5867230 [3,] 417925.5 5867329 [4,] 418024.5 5867315 [5,] 418011.0 5867216 I tried to simply write them as shpfile with writeOGR but the

mapping by ggplot2 geom_polygon goes crazy after merging data

自古美人都是妖i 提交于 2019-12-08 02:37:52
问题 I am trying to make a grid containing maps of megaregions in the us. I create a SpatialPolygonDataframe from a shape file. then convert it into a data.frame to use ggplot2. as soon as I add the data into the frame, the polygon plots. the file containing SpatialPolygon and the data frame are here: https://drive.google.com/open?id=1kGPZ3CENJbHva0s558vWU24-erbqWUGo the code is as follow: load("./data.rda") prop.test <- proptest.result[which(proptest.result$variable=="Upward N"),] #transforming

Crop a RasterLayer with a SpatialPolygonDataFrame

杀马特。学长 韩版系。学妹 提交于 2019-12-06 15:20:18
问题 I have a raster grid I want to crop according to land borders of the world map provided by the data of the package 'maptools'. By doing some reasearch, I found that I have to use the crop() function and then the mask() function, but I get an error message. Here is my code : # load the worldmap SpatialPolygonDataFrame library(maptools) data(wrld_simpl) ll=CRS("+init=epsg:4326") world<-spTransform(wrld_simpl, ll) ext<-extent(-10.417,31.917,34.083,71.083) # get only region covering europe world

mapping by ggplot2 geom_polygon goes crazy after merging data

房东的猫 提交于 2019-12-06 08:36:22
I am trying to make a grid containing maps of megaregions in the us. I create a SpatialPolygonDataframe from a shape file. then convert it into a data.frame to use ggplot2. as soon as I add the data into the frame, the polygon plots. the file containing SpatialPolygon and the data frame are here: https://drive.google.com/open?id=1kGPZ3CENJbHva0s558vWU24-erbqWUGo the code is as follow: load("./data.rda") prop.test <- proptest.result[which(proptest.result$variable=="Upward N"),] #transforming the data # add to data a new column termed "id" composed of the rownames of data shape@data$id <-

Crop a RasterLayer with a SpatialPolygonDataFrame

只谈情不闲聊 提交于 2019-12-04 21:15:29
I have a raster grid I want to crop according to land borders of the world map provided by the data of the package 'maptools'. By doing some reasearch, I found that I have to use the crop() function and then the mask() function, but I get an error message. Here is my code : # load the worldmap SpatialPolygonDataFrame library(maptools) data(wrld_simpl) ll=CRS("+init=epsg:4326") world<-spTransform(wrld_simpl, ll) ext<-extent(-10.417,31.917,34.083,71.083) # get only region covering europe world@bbox<-as.matrix(ext) # create the origin in WGS84 CRS ll = CRS("+init=epsg:4326") origin =

How do I extract raster values from polygon data then join into spatial data frame?

牧云@^-^@ 提交于 2019-12-04 08:43:38
I would like to merge polygon data and raster data into one dataframe for purposes of then using randomForests package in R. This involves first extracting the mean raster value per polygon. So far, I have the following: #load libraries library(raster) library(rgdal) library(sp) library(maptools) #import raster data r <- raster("myRasterdata.tif") #import polygon data p <- readShapePoly("myPolydata.shp") #extract mean raster value for each polygon ExtractMyData <- extract(r, p, small=TRUE, fun=mean, na.rm=TRUE, df=FALSE, nl=1, sp=TRUE) # note I have also tried this with df=TRUE and sp=FALSE