This function converts spatial sp::SpatialPolygons() and sp::SpatialPolygonsDataFrame() objects to PBSmapping::PolySet() objects.

SpatialPolygons2PolySet(x, n_preallocate)

# S3 method for SpatialPolygonsDataFrame
SpatialPolygons2PolySet(x, n_preallocate = 10000L)

# S3 method for SpatialPolygons
SpatialPolygons2PolySet(x, n_preallocate = 10000L)



sp::SpatialPolygons() or sp::SpatialPolygonsDataFrame() object.


integer How much memory should be preallocated for processing? Ideally, this number should equal the number of vertices in the sp::SpatialPolygons() object. If data processing is taking too long consider increasing this value.


PBSmapping::PolySet() object.


Be aware that this function is designed to be as fast as possible, but as a result it depends on C++ code and if used inappropriately this function will crash R.

See also

For a slower, more stable equivalent see maptools::SpatialPolygons2PolySet.


# generate SpatialPolygons object sim_pus <- sim.pus(225L) # convert to PolySet x <- SpatialPolygons2PolySet(sim_pus)