pysal

Next topic

weights.Distance — Distance based Spatial Weights

This Page

weights.Contiguity — Contiguity based Spatial weights for PySAL: Python Spatial Analysis Library

The weights.Contiguity. module provides for the construction and manipulation of spatial weights matrices based on contiguity criteria.

New in version 1.0.

Contiguity based spatial weights

pysal.weights.Contiguity.buildContiguity(polygons, criterion='rook', ids=None)

Build contiguity weights from a source

Parameters:

polygons : an instance of a pysal geo file handler

Any thing returned by pysal.open that is explicitly polygons

criterion : string

contiguity criterion (“rook”,”queen”)

ids : list

identifiers for i,j

Returns:

w : W instance

Contiguity weights object

Examples :

——- :

>>> w = buildContiguity(pysal.open(‘../examples/10740.shp’,’r’)) :

>>> w[0] :

{1: 1.0, 4: 1.0, 101: 1.0, 85: 1.0, 5: 1.0} :

>>> w = buildContiguity(pysal.open(‘../examples/10740.shp’,’r’),criterion=’queen’) :

>>> w.pct_nonzero :

0.031926364234056544 :

>>> w = buildContiguity(pysal.open(‘../examples/10740.shp’,’r’),criterion=’rook’) :

>>> w.pct_nonzero :

0.026351084812623275 :

>>> fips = pysal.open(‘../examples/10740.dbf’).by_col(‘STFID’) :

>>> w = buildContiguity(pysal.open(‘../examples/10740.shp’,’r’),ids=fips) :

>>> w[‘35001000107’] :

{‘35001003805’: 1.0, ‘35001003721’: 1.0, ‘35001000111’: 1.0, ‘35001000112’: 1.0, ‘35001000108’: 1.0} :

See also

pysal.weights.W

Notes

The types of sources supported will expand over time.