corridor_graph: Build a Corridor Graph for Cached Routing

View source: R/route_corridor.R

corridor_graphR Documentation

Build a Corridor Graph for Cached Routing

Description

Pre-build the routing graph from a cost surface so that multiple route_corridor calls can skip graph construction. The returned object is a snapshot of the cost surface at build time; subsequent edits to the raster do not affect the graph.

Usage

corridor_graph(cost_surface, neighbours = 8L, resolution_factor = 1L)

Arguments

cost_surface

A terra SpatRaster (single band). Same requirements as route_corridor.

neighbours

Integer. Cell connectivity: 4, 8 (default), or 16. Fixed at build time.

resolution_factor

Integer, default 1L. If > 1, the surface is aggregated before graph construction. Fixed at build time.

Details

The object retains both the CSR graph (in Rust) and an independent copy of the raster (for coordinate mapping). The printed graph_storage reflects only the CSR arrays, not the raster copy.

Value

An opaque spopt_corridor_graph object for use with route_corridor.

Examples


library(terra)
r <- rast(nrows = 500, ncols = 500, xmin = 0, xmax = 500000,
          ymin = 0, ymax = 500000, crs = "EPSG:32614")
values(r) <- runif(ncell(r), 0.5, 2.0)

g <- corridor_graph(r, neighbours = 8L)
print(g)
path <- route_corridor(g, c(50000, 50000), c(450000, 450000))



spopt documentation built on April 22, 2026, 9:07 a.m.