Convert a Polygon to a Spatial Polygons Object
Converts a polygon (a matrix of coordinates with NA values to separate subpolygons) into a Spatial Polygons object.
a 2-column matrix of coordinates, where each complete subpolygon is separated by NA's
the coordinate system to use
names of all areas
number of subpolygons for each area
Just as when plotting with the
polygon function, it is assumed that each subpolygon is to be closed by joining the last point to the first point. In the matrix
poly, NA values separate complete subpolygons.
coordinate.system must be either
In the case with an area consists of more than one separate closed polygon,
nrepeats specifies the number of closed polygons associated with each area.
An object of class SpatialPolygons (See SpatialPolygons-class from the sp package).
Albert Y. Kim
Bivand, R. S., Pebesma E. J., and Gomez-Rubio V. (2008) Applied Spatial Data Analysis with R. Springer Series in Statistics.
E. J. Pebesma and R. S. Bivand. (2005) Classes and methods for spatial data in R. R News, 5, 9–13.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
data(scotland) polygon <- scotland$polygon$polygon coord.system <- '+proj=utm' names <- scotland$data$county.names nrepeats <- scotland$polygon$nrepeats spatial.polygon <- polygon2spatial_polygon(polygon,coord.system,names,nrepeats) par(mfrow=c(1,2)) # plot using polygon function plot(polygon,type='n',xlab="Eastings (km)",ylab="Northings (km)",main="Polygon File") polygon(polygon) # plot as spatial polygon object plot(spatial.polygon,axes=TRUE) title(xlab="Eastings (km)",ylab="Northings (km)",main="Spatial Polygon") # Note that area 23 (argyll-bute) consists of 8 separate polygons nrepeats plot(spatial.polygon,add=TRUE,col="red")
Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.