| spatial_service_area | R Documentation |
Streams a layer of origins x past a resident spatial_network() and, for
each origin, finds every part of the network reachable within a cost budget -
the service area, or, with several budgets, nested travel-cost isochrone bands.
Each origin is snapped to its nearest graph node and a budget-bounded Dijkstra
(native C) collects the reachable nodes; the reachable set is returned as the
convex hull (output = "polygon", the generalised service area), the
reachable edges ("lines"), or the reachable nodes ("nodes").
spatial_service_area(
x,
network,
cost,
output = c("polygon", "lines", "nodes"),
band_col = "band",
geom = "geometry",
coords = NULL,
crs = NA,
out_geom = NULL,
flush_rows = NULL
)
x |
A |
network |
A |
cost |
A cost budget (scalar), or several budgets for nested isochrone
bands (e.g. |
output |
|
band_col |
Name of the output column holding each row's budget. Default
|
geom |
Name of the input geometry column holding hex-WKB or WKT strings.
Default |
coords |
Optional length-2 character vector naming the x and y
coordinate columns to assemble point geometry from (e.g. |
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. |
A vector cost returns one row per (origin, band), each band the area
reachable within that budget, so the rows nest from the smallest budget out.
Costs are in the network's weight units. The convex-hull polygon is a
generalisation; use output = "lines" for the exact reachable network. The
sf package is an optional dependency (Suggests).
A vectra_node: one row per (origin, band) carrying x's attributes,
the band value, and the service-area geometry. Backed by temporary .vtr
spills removed when the node is garbage-collected, and carrying the network
CRS.
spatial_network() to build the graph, spatial_route() for
shortest paths, collect_sf() to materialize as sf.
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)
f <- tempfile(fileext = ".vtr")
write_vtr(data.frame(id = 1L, x = 0, y = 0), f)
tbl(f) |>
spatial_service_area(net, cost = c(1, 2), output = "lines",
coords = c("x", "y")) |>
collect_sf()
unlink(f)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.