View source: R/pts2poly_vertices.R
pts2poly_vertices | R Documentation |
Create polygon(s) from a data frame with the coordinates of the polygon vertices
pts2poly_vertices(x, ...)
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 |
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
.
Object of class sfc
with the geometry type POLYGON
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.