| spatial_construct | R Documentation |
Constructs one geometry (or a tessellation) from a whole set of features –
the constructions a per-feature spatial_map() cannot express because they
need every feature in scope at once. Like spatial_dissolve() it rides the
partition tier: x is spilled once and routed into one disjoint shard per
by group in a single bounded pass, then each shard's geometry is combined
and the construction built with sf. With no by, the whole layer yields
one construction. Peak memory is the routing budget during the pass, then one
group's geometry while it is built – partition on a key whose groups fit in
memory.
spatial_construct(
x,
kind = .CONSTRUCT_KINDS,
by = NULL,
geom = "geometry",
crs = NA,
ratio = 0.3,
allow_holes = FALSE,
tolerance = 0,
flush_rows = NULL
)
x |
A |
kind |
The construction to build; one of the values above. |
by |
Character vector of attribute columns to construct within: one
construction (or tessellation) per distinct combination of their values.
|
geom |
Name of the input geometry column holding hex-WKB or WKT strings.
Default |
crs |
Coordinate reference system of the input geometry, in any form
|
ratio |
For |
allow_holes |
For |
tolerance |
Distance tolerance for the kinds that take one
( |
flush_rows |
Transformed rows buffered before a spill flush. Larger
values mean fewer, bigger temporary files. |
kind selects the construction:
"convex_hull"the convex hull of the set.
"concave_hull"the concave hull (ratio, allow_holes).
"envelope"the axis-aligned bounding rectangle.
"oriented_box"the minimum-area rotated bounding rectangle.
"enclosing_circle"the minimum bounding circle.
"inscribed_circle"the maximum inscribed circle (largest circle that fits inside the set's union).
"pole"the pole of inaccessibility – the centre of the maximum inscribed circle, the point inside the shape farthest from its edges.
"voronoi"the Voronoi tessellation, one polygon per cell.
"delaunay"the Delaunay triangulation, one polygon per triangle.
The enclosing kinds and pole emit one feature per group; voronoi and
delaunay emit one feature per cell, each carrying the group's by values.
Geometry travels through the engine as hex-encoded WKB in a string column and
the CRS is carried on the returned node; use collect_sf() to materialize.
Topology is sf/GEOS throughout (an optional dependency, Suggests); some
constructions need projected coordinates.
A vectra_node of the construction – one row per group for the
enclosing kinds, one row per cell for the tessellations – carrying the
by columns and the input CRS, backed by temporary .vtr spills removed
when the node is garbage-collected.
spatial_dissolve() to merge a group into one feature,
spatial_map() for per-feature transforms, collect_sf() to materialize.
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
nc$band <- nc$SID74 > 5
f <- tempfile(fileext = ".vtr")
write_vtr(data.frame(
band = nc$band,
geometry = sf::st_as_binary(sf::st_geometry(nc), hex = TRUE)
), f)
# One convex hull per band.
tbl(f) |>
spatial_construct("convex_hull", by = "band", crs = sf::st_crs(nc)) |>
collect_sf()
unlink(f)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.