How can I create a SpatialPolygons object from SpatialPolygonsDataFrame object in R?

1.1k views Asked by At

I am working on creating a species distribution model using R-INLA, and I want to use a shapefile(.shp) that I have created in ArcPro as a barrier in the spatial mesh. In order to do so, I think the shapefile must be in the 'SpatialPolygons' format.

When I read in the shapefile (which is made up of 6 polygons), using st_read(), it is imported as a SpatialPolygonsDataFrame (see attached pictures).

Additionally, i tried to get shapefiles using worldhire, thinned them and tried to remove all the extra wee islands, but the mesh wouldn't run on INLA.

Long story short, is there: a) A way I can import the .shp file as a SpatialPolygons object (would it need to be a separate shapefile for each polygon, or a different function)? b) A way I can convert the SpatialPolygonsDataFrame object to a SpatialPolygons object? c) Use a SpatialPolygonsDataFrame object when constructing a spatial autocorrelation mesh in R-INLA?

I appreciate any advice you can provide, please let me know if I can provide any more information

Link to image of shapefile plotted using plot() function

Link to image of the SpatialPolygonsDataFrame

1

There are 1 answers

1
Micha On

I'm not sure this will help regarding your underlying problem, but to create a Spatial* object from a Spatial*DataFrame, you use the geometry() function:

library(sp)
library(rgdal)
seas = readOGR("il_seas.shp")

class(seas)
[1] "SpatialPolygonsDataFrame"
attr(,"package")
[1] "sp"
> seas_geom = geometry(seas)
> class(seas_geom)
[1] "SpatialPolygons"
attr(,"package")
[1] "sp"

That simply strips off all attribute columns from the SPDF.