sf-utils: Utilities for 'sf'

Description Usage Arguments Examples

Description

Utilities for 'sf'

Usage

1
coordinates_to_column(x, col_names = NULL, fun = sf::st_centroid)

Arguments

x

sf object.

col_names

Column names.

fun

Function to calcuate POINT from the geometry.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
points_sfc <- sf::st_sfc(
  sf::st_point(c(1, 1)),
  sf::st_point(c(2, 2))
)

points_sf <- sf::st_sf(
  value = c(10, 20),
  geometry = points_sfc
)

# For POINT, add the coordinates of the points.
coordinates_to_column(points_sf)
coordinates_to_column(points_sf, col_names = c("long", "lat"))

# For other features, add the coordinates of the centroids of them.
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
nc_3857 <- sf::st_transform(nc, 3857)
coordinates_to_column(nc_3857)

# You can specify other functions that return one POINT per geometry.
coordinates_to_column(nc_3857, fun = sf::st_point_on_surface)

yutannihilation/yutanutils documentation built on May 20, 2019, 8:24 p.m.