Build and register a rook adjacency relation from planning-unit polygons.
Two planning units are rook-adjacent if they share a boundary segment of positive length. Corner-only contact does not count as rook adjacency.
Arguments
- x
A
Problemobject created withcreate_problemor another object containing aligned planning-unit polygons.- geometry
Optional
sfobject with planning-unit polygons and anidcolumn. IfNULL,x$data$pu_sfis used.- name
Character string giving the key under which the relation is stored.
- weight
Numeric scalar giving the edge weight assigned to each rook adjacency.
Details
Use this function when neighbourhood should be defined by shared polygon edges rather than by point-touching or coordinate-based proximity.
This constructor derives an adjacency graph from polygon geometry using a rook criterion. If planning units \(i\) and \(j\) share a common edge of non-zero length, then an edge \((i,j)\) is added to the relation.
Let \(G = (\mathcal{I}, E)\) denote the resulting graph. Then: $$ (i,j) \in E \quad \Longleftrightarrow \quad \mathrm{length}(\partial i \cap \partial j) > 0. $$
All edges receive the same user-supplied weight.
The resulting relation is stored as an undirected spatial relation.
Examples
# \donttest{
# Load a complete simulated planning problem.
example_data <- load_sim_multiaction()
p <- create_problem(
pu = example_data$planning_units,
features = example_data$features,
dist_features = example_data$dist_features,
cost = "cost"
)
p <- add_spatial_rook(
x = p,
geometry = example_data$planning_units,
name = "rook",
weight = 1
)
head(p$data$spatial_relations$rook)
#> internal_pu1 internal_pu2 weight pu1 pu2 source relation_name directed
#> 1 1 2 1 1 2 rook_sf rook FALSE
#> 2 1 9 1 1 9 rook_sf rook FALSE
#> 3 2 3 1 2 3 rook_sf rook FALSE
#> 4 2 10 1 2 10 rook_sf rook FALSE
#> 5 3 4 1 3 4 rook_sf rook FALSE
#> 6 3 11 1 3 11 rook_sf rook FALSE
# }
