| spatial_snap_grid | R Documentation |
Rounds every coordinate of a streamed layer to a regular grid of spacing
size (in CRS units) and repairs the result, one batch at a time. This is the
fixed-precision snap-rounding the overlay noder
(spatial_overlay()) applies internally, exposed as a standalone verb: it
merges near-coincident vertices and removes the slivers that floating-point
coordinates leave between shared boundaries, so a layer can be cleaned (or
pre-noded to a common precision) without running a full overlay. Snapping is
done in C straight off the hex-WKB column; one cleaned geometry comes back per
input feature, so attributes ride through untouched.
spatial_snap_grid(
x,
size,
geom = "geometry",
crs = NA,
out_geom = NULL,
flush_rows = NULL
)
x |
A |
size |
Grid spacing in CRS units (a positive number). Coordinates are
rounded to the nearest multiple; a larger |
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
|
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 a string column and
the CRS is carried on the returned node; use collect_sf() to materialize.
The sf package is an optional dependency (Suggests).
A vectra_node of the snapped geometry with x's attributes, backed
by temporary .vtr spills (removed when the node is garbage-collected) and
carrying the input CRS.
spatial_snap() to snap toward another layer instead of a grid,
spatial_overlay() whose noding uses the same snap-rounding, collect_sf().
p <- sf::st_polygon(list(rbind(c(0.04, 0.03), c(1.02, 0.01),
c(0.98, 1.03), c(0.01, 0.97), c(0.04, 0.03))))
f <- tempfile(fileext = ".vtr")
write_vtr(data.frame(
id = 1L, geometry = sf::st_as_binary(sf::st_sfc(p), hex = TRUE)
), f)
# Snap the jittered corners back onto a 0.1 grid.
tbl(f) |> spatial_snap_grid(0.1) |> collect_sf()
unlink(f)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.