View source: R/spatial_topology.R
| spatial_line_merge | R Documentation |
Sews the line segments of each group into the longest possible linestrings
(sf::st_line_merge, the line counterpart of a dissolve): segments that meet
end to end become one chain, and each chain is emitted as its own row. Where a
plain union of lines returns a single multilinestring of all the parts, this
joins the parts through their shared endpoints; at a crossing where more than
two segments meet the merge is ambiguous and the segments stay separate. 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 group's segments are merged together. Peak memory is the routing budget
during the pass, then one group's geometry while it is merged. With no by,
the whole layer is merged at once.
spatial_line_merge(
x,
by = NULL,
geom = "geometry",
crs = NA,
flush_rows = NULL
)
x |
A |
by |
Character vector of attribute columns to merge within: one set of
maximal lines 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
|
flush_rows |
Transformed rows buffered before a spill flush. Larger
values mean fewer, bigger temporary files. |
Each merged line is new geometry built from the whole group, so it carries the
by columns only, not the attributes of any single source segment. Geometry
travels through the engine as hex-encoded WKB in a string column and the CRS
is carried on the returned node. The sf package is an optional
dependency (Suggests).
A vectra_node of one row per maximal merged line, carrying the by
columns and the input CRS, backed by temporary .vtr spills removed when
the node is garbage-collected.
spatial_dissolve() to union geometries by group,
spatial_explode() for the opposite direction (multipart to single part),
collect_sf() to materialize as sf.
seg <- sf::st_sfc(
sf::st_linestring(rbind(c(0, 0), c(1, 0))),
sf::st_linestring(rbind(c(1, 0), c(2, 0))),
sf::st_linestring(rbind(c(2, 0), c(3, 0))))
f <- tempfile(fileext = ".vtr")
write_vtr(data.frame(
geometry = sf::st_as_binary(seg, hex = TRUE)
), f)
# The three end-to-end segments become one line.
tbl(f) |> spatial_line_merge() |> collect_sf()
unlink(f)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.