| spatial_smooth | R Documentation |
Rounds the corners of every line and polygon in a streamed layer by Chaikin
corner-cutting, one batch at a time. Each iteration replaces every vertex with
two points a quarter and three-quarters of the way along its adjacent edges,
so sharp angles become a sequence of short chamfers that read as a smooth
curve; more iterations give a smoother result with more vertices. Open lines
keep their endpoints (keep_ends); polygon rings are cut cyclically and shrink
slightly, as Chaikin smoothing does. Point geometry passes through unchanged.
spatial_smooth(
x,
iterations = 2L,
keep_ends = TRUE,
geom = "geometry",
crs = NA,
out_geom = NULL,
flush_rows = NULL
)
x |
A |
iterations |
Number of corner-cutting passes (a positive integer). Each
pass roughly doubles the vertex count. Default |
keep_ends |
If |
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. |
The smoothing is computed directly on the coordinates (no GEOS call), so it is
dependency-light; sf is used only to decode and rebuild each batch.
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.
A vectra_node of the smoothed geometry with x's attributes, backed
by temporary .vtr spills (removed when the node is garbage-collected) and
carrying the input CRS.
spatial_map() for per-feature transforms such as densifying with
~ sf::st_segmentize(.x, dfMaxLength) or sampling points along a line with
~ sf::st_line_sample(.x, n), collect_sf() to materialize as sf.
zig <- sf::st_linestring(rbind(c(0, 0), c(1, 1), c(2, 0), c(3, 1), c(4, 0)))
f <- tempfile(fileext = ".vtr")
write_vtr(data.frame(
id = 1L, geometry = sf::st_as_binary(sf::st_sfc(zig), hex = TRUE)
), f)
# Smooth the zig-zag with three corner-cutting passes.
tbl(f) |> spatial_smooth(iterations = 3) |> collect_sf()
unlink(f)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.