Reputation: 1
I am trying to create a mask for a project using the packages sf and RGDAL. I have a shapefile which is a SpatiallinesDataFrame and it needs to be a SpatialpolygonsDataFrame to continue.
I have tried these codes
fence1 <- as(fence1 ,"SpatialPolygonsDataFrame")
fence1 <- SpatialPolygonsDataFrame(fence1)
fence1 <- SpatialPolygonsDataFrame(fence1, match.ID = TRUE)
The fence1 is the SpatiallinesDataFrame that i imported from a shp. file using the code:
fence1 <- readOGR('/SECR/', layer = 'building')
The aim of this data is to create a mask so i can create a SECR analysis
Upvotes: 0
Views: 549
Reputation: 749
If you are using sf
, you could read in using:
fence1 <- st_read('/SECR/building.shp')
You could then do a buffer to make these lines polygons, choosing width in units of your projection:
fence_buf <- st_buffer(fence1, 50) # buffer unit of 50 as example
Then if you need your polygons as an sp
SpatialPolygonsDataFrame you could convert from sf
to sp
:
fence_buf <- as(fence_buf, 'Spatial')
Upvotes: 1