pts2poly_vertices {eSDM}R Documentation

Create polygons from vertex coordinates

Description

Create polygon(s) from a data frame with the coordinates of the polygon vertices

Usage

pts2poly_vertices(x, ...)

Arguments

x

data frame with at least two columns; the first two columns must contain longitude and latitude coordinates, respectively. See 'Details' section for how additional columns are handled

...

passed to st_sfc, e.g. for passing named argument crs

Details

Vertices of different polygons must be demarcated by rows with values of NA in both the first and second columns (i.e. the longitude and latitude columns).

All columns in x besides the first two columns are ignored.

If a crs is not specified in ..., then the crs attribute of the polygon(s) will be NULL.

Value

Object of class sfc with the geometry type POLYGON

Examples

x <- data.frame(
  lon = c(40, 40, 50, 50, 40),
  lat = c(0, 10, 10, 0, 0)
)
pts2poly_vertices(x, crs = 4326)

# Create an sf object
x <- data.frame(
  lon = c(40, 40, 50, 50, 40, NA, 20, 20, 30, 30, 20),
  lat = c(0, 10, 10, 0, 0, NA, 0, 10, 10, 0, 0)
)
sf::st_sf(Pred = 1:2, geometry = pts2poly_vertices(x, crs = 4326))


[Package eSDM version 0.4.1 Index]