| collect_sf | R Documentation |
Collects a vectra_node (typically the result of spatial_map() or
spatial_join()) into memory and rebuilds an sf object from its hex-WKB
geometry column. The CRS defaults to the one carried on the node.
collect_sf(x, geom = "geometry", crs = NULL)
x |
A |
geom |
Name of the geometry column. Default |
crs |
Override the coordinate reference system. Defaults to the CRS the node carries, or unknown. |
This is the spatial counterpart to collect(): use it when the final result
fits in memory as sf. For a result still larger than RAM, keep it as a node
and write it out with write_vtr() (the geometry stays as a WKB string
column) or reduce it with collect_chunked().
An sf object.
spatial_map(), spatial_join(), collect().
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
f <- tempfile(fileext = ".vtr")
write_vtr(data.frame(
NAME = nc$NAME,
geometry = sf::st_as_binary(sf::st_geometry(nc), hex = TRUE)
), f)
result <- tbl(f) |> spatial_map(~ sf::st_centroid(.x), crs = sf::st_crs(nc))
collect_sf(result)
unlink(f)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.