| spatial_network | R Documentation |
Builds the node-edge graph a shortest-path query needs: nodes at line
endpoints, edges weighted by geometry length or a cost column. The graph is
held resident in an external pointer and passed to spatial_route() and
spatial_service_area(), which stream origin (and destination) batches past
it. This is the network counterpart of a resident sf y in spatial_knn():
the graph is the resident budget (bounded by the network size), while the
query side scales by streaming.
spatial_network(
lines,
weight = NULL,
directed = FALSE,
direction = NULL,
weight_to = NULL,
tolerance = 0,
geom = "geometry",
crs = NA
)
lines |
An |
weight |
Name of a column in |
directed |
If |
direction |
Name of a column of one-way codes, used when |
weight_to |
Name of a column holding the reverse-direction cost on a
two-way edge of a directed graph. |
tolerance |
Endpoints within this distance (CRS units) are snapped to one
node. |
geom, crs |
Geometry column name and CRS, as in |
Endpoints within tolerance of each other are snapped to a single node, so a
layer whose touching lines do not share exactly-equal endpoint coordinates
still connects. The input must be (multi)linestrings; a MULTILINESTRING is
split into its parts, each becoming one edge with the source attributes. Lines
are treated as already split at their junctions (the usual road-network
convention); two lines that merely cross in their interiors are not connected
unless they share an endpoint. The graph and the Dijkstra solver are native C;
sf (an optional dependency, Suggests) supplies only the geometry.
A vectra_network object: the resident graph (an external pointer
plus the node coordinates, edge table, and source-line geometry needed to
snap queries and rebuild routes). Print it to see the node, edge, and
connected-component counts.
spatial_route() for shortest paths and origin-destination costs,
spatial_service_area() for reachability and isochrones.
# A small grid of streets.
mk <- function(x1, y1, x2, y2)
sf::st_linestring(rbind(c(x1, y1), c(x2, y2)))
streets <- sf::st_sfc(
mk(0, 0, 1, 0), mk(1, 0, 2, 0), mk(0, 0, 0, 1),
mk(0, 1, 1, 1), mk(1, 0, 1, 1), mk(1, 1, 2, 1), mk(2, 0, 2, 1))
net <- spatial_network(streets)
net
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.