Converts an sf object (points or polygons) into the plain data frame that
travel_matrix() and select_units() expect: a column unit, the
coordinates lat/lon (centroids for polygons, in WGS 84) and, for
polygons, their area in square kilometres, next to the other columns of
the object. Nothing spatial is kept: use as_sf() to put the results back
on the geometries.
Examples
if (requireNamespace("sf", quietly = TRUE)) {
sq <- sf::st_sfc(sf::st_polygon(list(rbind(c(0, 0), c(0, 1), c(1, 1), c(1, 0), c(0, 0)))),
crs = 4326
)
cells <- sf::st_sf(crop = 3, geometry = sf::st_make_grid(sq, n = 3))
as_frame(cells)
}
#> # A tibble: 9 × 5
#> unit lat lon area crop
#> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 u1 0.167 0.167 1374. 3
#> 2 u2 0.167 0.500 1374. 3
#> 3 u3 0.167 0.833 1374. 3
#> 4 u4 0.500 0.167 1374. 3
#> 5 u5 0.500 0.500 1374. 3
#> 6 u6 0.500 0.833 1374. 3
#> 7 u7 0.833 0.167 1374. 3
#> 8 u8 0.833 0.500 1374. 3
#> 9 u9 0.833 0.833 1374. 3