# polygon2spatial_polygon

0th

Percentile

##### 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.

Keywords
file
##### Usage
polygon2spatial_polygon(poly, coordinate.system, area.names = NULL, nrepeats = NULL)
##### Arguments
poly

a 2-column matrix of coordinates, where each complete subpolygon is separated by NA's

coordinate.system

the coordinate system to use

area.names

names of all areas

nrepeats

number of subpolygons for each area

##### Details

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 '+proj=utm' or '+proj=longlat'.

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.

##### Value

An object of class SpatialPolygons (See SpatialPolygons-class from the sp package).

##### References

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.

##### Aliases
• polygon2spatial_polygon
##### Examples
# NOT RUN {
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[23]