2.1 Contiguity-Based Weights
Contiguity means that two spatial units share a common border of non-zero length. Operationally, we can further distinguish between a rook and a queen criterion of contiguity, in analogy to the moves allowed for the such-named pieces on a chess board.
The rook criterion defines neighbors by the existence of a common edge between two spatial units. The queen criterion is somewhat more encompassing and defines neighbors as spatial units sharing a common edge or a common vertex.
For more information, please read: https://geodacenter.github.io/workbook/4a_contig_weights/lab4a.html
CONTENTS
queen_weights()
rook_weights()
weights_astext()
save weights
queen_weights()
Synopsis
Short version:
Full Version:
queen_weights() is a WINDOW SQL function, which performs weights creation across a set of table rows. Unlike the regular AGGREGATE function, a WINDOW function does not cause rows to become grouped into a single output row -- the rows retain their separate identities. A WINDOW function call always contains an OVER() clause.
Arguments
Input Arguments
Type
Description
gid
integer
the feature id of geometry: e.g. gid, fid, ogcfid, cartodb_id
the_geom
geometry
the geometry (only points and polygons are supported)
ord
integer
order of contiguity. Default is 1.
include_lowerorder
boolean
boolean value indicates whether or not the lower order neighbors should be included in the weights structure. Default is FALSE.
precision_threshold
boolean
(for polygons only) the distance of precision to determine which polygons are neighbors when the underlying geometries are insufficient to allow for an exact match of coordinates. Default is 0.0.
Return
Value
Description
bytea
the weights structure for each observation in binary format, which is defined in table 2.1.
Examples
Table 2.1: The binary format of weights structure
Bytes
Data Type
Length
Description
0-3
uint32_t
4 bytes
index of i-th observation/row
4-5
uint16_t
2 bytes
number of neighbors of i-th observation
6-9
uint32_t
4 bytes
index of first neighbor
10-13
float
4 bytes
weights value of first neighbor
...
...
...
index of n-th neighbor
...
...
...
weights value of n-th neighbor
rook_weights()
Synopsis
Short version:
Full Version:
weights_astext()
The help function to view the content of the weights information.
Synopsis
Examples
Save Weights
To save the results of queen_weights(), the best practice is to save the results with the feature id, e.g. gid
, in a new table. For example:
Or, one can create a new bytea
column, and update its values from the results of queen_weights() function. For example:
The second approach is much slower than the first one when updating a large table, e.g. with millions of records.
Last updated