Skip to content

geodalib / core/src / rookWeights

Function: rookWeights() ​

rookWeights(geometries, useCentroids?, precisionThreshold?, orderOfContiguity?, includeLowerOrder?): Promise<WeightsMeta>

Defined in: core/src/weights/contiguity-neighbors.ts:286

Description ​

Create Rook contiguity weights for GeoJSON features.

Rook contiguity defines neighbors as spatial units that only share common edge (border)

This is in contrast to Queen contiguity, which considers shared edges and vertices.

Example ​

ts
import { rookWeights } from '@geoda/core';

const geometries = [
  { type: 'Feature', geometry: { type: 'Point', coordinates: [0, 0] } },
  { type: 'Feature', geometry: { type: 'Point', coordinates: [1, 0] } },
  { type: 'Feature', geometry: { type: 'Point', coordinates: [0, 1] } },
];

const weights = await rookWeights(geometries);

console.log(weights);

Parameters ​

geometries ​

SpatialGeometry

The geometries used to create the rook contiguity weights. See SpatialGeometry for more information.

useCentroids? ​

boolean = false

If true, uses geometry centroids for calculations

precisionThreshold? ​

number = 0.0

Distance threshold for determining neighbors. Useful when geometries don't perfectly align

orderOfContiguity? ​

number = 1

Number of steps to consider for neighbor relationships. 1 means immediate neighbors only

includeLowerOrder? ​

boolean = false

If true, includes all neighbors from order 1 up to the specified order

Returns ​

Promise<WeightsMeta>

Spatial weights metadata including neighbor relationships