| spatial_map | R Documentation |
Applies a per-feature sf operation (buffer, centroid, area, CRS
transform, simplify, ...) to a lazy vectra query one batch at a time and
returns a new lazy node. The engine pulls one batch, hands it to fn as an
sf object, encodes the result back into the stream, and spills to disk, so
peak memory is one batch regardless of result size. This is the streaming,
larger-than-RAM counterpart to running the same sf call on a whole
in-memory table.
spatial_map(
x,
fn,
geom = "geometry",
coords = NULL,
crs = NA,
out_geom = NULL,
flush_rows = NULL
)
x |
A |
fn |
A function (or purrr-style formula such as |
geom |
Name of the input geometry column holding hex-WKB or WKT strings.
Default |
coords |
Optional length-2 character vector naming the x and y
coordinate columns to assemble point geometry from (e.g. |
crs |
Coordinate reference system of the input geometry, in any form
|
out_geom |
Name of the output geometry column. Defaults to |
flush_rows |
Transformed rows buffered before a spill flush. Larger
values mean fewer, bigger temporary files. |
Geometry travels through the engine as hex-encoded WKB in an ordinary string
column (vectra has no native geometry type), and the coordinate reference
system is carried on the returned node rather than in the .vtr file. Use
collect_sf() to materialize the result as an sf object, or collect()
to get the underlying data.frame with the WKB string column.
Topology is delegated entirely to sf/GEOS; vectra only supplies the
streaming. The sf package is an optional dependency (Suggests).
A vectra_node backed by temporary .vtr spills (removed when the
node is garbage-collected), carrying the output CRS for collect_sf().
spatial_join() to join a streamed side against a resident sf
object, collect_sf() to materialize as sf.
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_centroid(sf::st_geometry(nc)),
hex = TRUE)
), f)
# Buffer every county centroid by 0.1 degree, streaming.
buffered <- tbl(f) |>
spatial_map(~ sf::st_buffer(.x, 0.1), crs = sf::st_crs(nc))
collect_sf(buffered)
unlink(f)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.