points_to_polygon: Given a table of x and y coordinates data generate a...

View source: R/sf.R

points_to_polygonR Documentation

Given a table of x and y coordinates data generate a sfc_POLYGON

Description

Given a table of x and y coordinates data generate a sfc_POLYGON

Usage

points_to_polygon(
  x = dplyr::tibble(x = c(1, 2, 1, 0), y = c(0, 1, 2, 1)),
  crs = "WGS84"
)

Arguments

x

table or matrix of x and y column of coordinates

crs

character or numeric coordinate ref system flag

Value

sfc_POLYGON object

Examples

## Not run: 
# An example of interating over a number of sets of points in a grouped table
 x <- dplyr::tibble(
                    name = c('a', 'a', 'a', 'a', "b", "b", "b", "b"),
                    x = c(1,2,1,0, 3,4,4,5), 
                    y = c(0,1,2,1, 8,8,9,9))
 make_one_polygon <- function(x, y, ...){
   cat(str(x, "\n"))
   points_to_polygon(x, ...)
 } 
 p <- x |>
   dplyr::group_by(name) |>
   dplyr::group_map(make_one_polygon, crs = "WGS84") |>
   dplyr::bind_rows()

## End(Not run)m

BigelowLab/twinkle documentation built on Jan. 26, 2025, 6:34 a.m.