coordsToPoly: Convert coordinates to spatial polygon(s) or spatial line(s)

Description Usage Arguments Value Functions See Also Examples

View source: R/coordsToPoly.r

Description

This function converts coordinates to a SpatialPolygon object. To close the polygon the last set of coordinates must be equal to the first. If they are not, then the first set is added to the end. Note that it is possible to create an improper polygon (i.e., that crosses itself).

Usage

1
2
3
4
5
coordsToPoly(x, crs, closePoly = TRUE, id = 1)

coordsToLine(x, crs, id = 1)

coordsToLines(x, crs, id = seq_along(x))

Arguments

x

Either a two-column matrix or data frame with coordinates (first column is longitude, second is latitude), or a list of matrices or data frames, or an object from which coordinates can be extracted using link[sp]{coordinates}.

crs

A character string or an object of class CRS which species the coordinate reference system (proj4string) for the polygon. If the object in x is a spatial object the CRS will be obtained from it unless crs is specified.

closePoly

Logical, if TRUE (default), then close the polygon.

id

Integer or character, ID value for the object(s).

Value

A spatial polygon object.

Functions

See Also

SpatialPolygons

Examples

1
2
3
4
5
6
7
8
x <- c(-116.57, -99.13, -62.95, -65.21, -90.08)
y <- c(62.09, 75.50, 73.29, 68.34, 66.43)
xy <- cbind(x, y)
poly <- coordsToPoly(xy, getCRS('wgs84'))
line <- coordsToLine(xy, getCRS('wgs84'))
par(mfrow=c(1, 2))
plot(poly)
plot(line)

adamlilith/birdsEye documentation built on May 23, 2020, 4:40 p.m.