Converts a polygon (a matrix of coordinates with NA values to separate subpolygons) into a Spatial Polygons object.

1 | ```
polygon2spatial_polygon(poly, coordinate.system, area.names = NULL, nrepeats = NULL)
``` |

`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 |

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.

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[23]
plot(spatial.polygon[23],add=TRUE,col="red")
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.