% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/add_spatial_relations.R
\name{add_spatial_queen}
\alias{add_spatial_queen}
\title{Add queen adjacency from polygons}
\usage{
add_spatial_queen(x, geometry = NULL, name = "queen", weight = 1)
}
\arguments{
\item{x}{A \code{Problem} object created with
\code{\link{create_problem}} or another object containing aligned
planning-unit polygons.}

\item{geometry}{Optional \code{sf} object with planning-unit polygons and an
\code{id} column. If \code{NULL}, \code{x$data$pu_sf} is used.}

\item{name}{Character string giving the key under which the relation is
stored.}

\item{weight}{Numeric scalar giving the edge weight assigned to each queen
adjacency.}
}
\value{
An updated \code{Problem} object.
}
\description{
Build and register a queen adjacency relation from planning-unit polygons.

Two planning units are queen-adjacent if their boundaries touch, either along
a shared edge or at a shared vertex.
}
\details{
Use this function when neighbourhood should include both shared edges and
corner-touching polygon contacts.

This constructor derives an adjacency graph from polygon geometry using a
queen criterion. If planning units \eqn{i} and \eqn{j} touch at any boundary
point, then an edge \eqn{(i,j)} is added to the relation.

Let \eqn{G = (\mathcal{I}, E)} denote the resulting graph. Then:
\deqn{
(i,j) \in E \quad \Longleftrightarrow \quad
\partial i \cap \partial j \neq \varnothing.
}

Thus, queen adjacency includes all rook neighbours plus corner-touching
neighbours.

All edges receive the same user-supplied weight.

The resulting relation is stored as an undirected spatial relation.
}
\examples{
\donttest{
library(terra)

data("sim_pu_sf", package = "multiscape")
sim_features <- load_sim_features_raster()

p <- create_problem(
  pu = sim_pu_sf,
  features = sim_features,
  cost = "cost"
)

p <- add_spatial_queen(
  x = p,
  geometry = sim_pu_sf,
  name = "queen",
  weight = 1
)

head(p$data$spatial_relations$queen)
}

}
\seealso{
\code{\link{add_spatial_rook}},
\code{\link{add_spatial_boundary}}
}
