coords2Polygons: Convert Points to SpatialPolygons*

coords2PolygonsR Documentation

Convert Points to SpatialPolygons*

Description

Create a SpatialPolygons* object from a Polygon object or set of point coordinates in one go, i.e. without being required to run through the single steps outlined in sp::SpatialPolygons().

Usage

## S4 method for signature 'matrix'
coords2Polygons(coords, hole = NA, ID, data, match.ID = TRUE, ...)

## S4 method for signature 'Polygon'
coords2Polygons(coords, ID, data, match.ID = TRUE, ...)

Arguments

coords

Polygon object or 2-column numeric matrix with x and y coordinates.

hole

logical, see sp::Polygon().

ID

character, see sp::Polygons().

data

data.frame with data to add to the output SpatialPolygons* object (optional).

match.ID

logical, see sp::SpatialPolygonsDataFrame().

...

Further arguments passed on to sp::SpatialPolygons(), i.e. p0 and proj4string.

Value

If 'data' is missing, a SpatialPolygons object; else a SpatialPolygonsDataFrame object.

Examples

library(sp)

coords1 <- cbind(c(2, 4, 4, 1, 2), c(2, 3, 5, 4, 2))
spy1 <- coords2Polygons(coords1, ID = "A")

coords2 <- cbind(c(5, 4, 2, 5), c(2, 3, 2, 2))
spy2 <- coords2Polygons(coords2, ID = "B")

plot(spy1, col = "grey75")
plot(spy2, col = "grey25", add = TRUE)


Orcs documentation built on Jan. 6, 2023, 5:14 p.m.