Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

polygon2spatial_polygon

Convert a Polygon to a Spatial Polygons Object


Description

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

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

Author(s)

Albert Y. Kim

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.

Examples

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")

SpatialEpi

Methods and Data for Spatial Epidemiology

v1.2.3
GPL-2
Authors
Cici Chen [ctb], Albert Y. Kim [aut, cre], Michelle Ross [ctb], Jon Wakefield [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.