libpysal.weights.
Queen
(polygons, **kw)[source]¶Construct a weights object from a collection of pysal polygons that share at least one vertex.
a collection of PySAL shapes to build weights from
a list of names to use to build the weights
optional arguments for pysal.weights.W
See also
libpysal.weights.weights.W
__init__
(self, polygons, **kw)[source]¶Initialize self. See help(type(self)) for accurate signature.
Methods
|
Initialize self. |
|
Asymmetry check. |
|
|
|
Return an adjacency list representation of a weights object. |
|
Construct a weights object from a pandas dataframe with a geometry column. |
|
|
|
Construct a weights object from a collection of arbitrary polygons. |
|
Convert a networkx graph to a PySAL W object. |
|
Queen contiguity weights from a polygon shapefile. |
|
Generate a full numpy array. |
|
Getter for transform property. |
|
Plot spatial weights objects. |
|
In place modification throughout W of id values from w.id_order to new_ids in all |
|
Adding meta data for writing headers of gal and gwt files. |
|
Transformations of weights. |
|
Construct a symmetric KNN weight. |
|
Generate a WSP object. |
|
Compute an adjacency list representation of a weights object. |
|
Convert a weights object to a networkx graph |
Attributes
|
List of id pairs with asymmetric weights. |
|
Number of neighbors for each observation. |
|
Store the graph component in which each observation falls. |
|
Diagonal of \(WW\). |
|
Diagonal of \(W^{'}W\). |
|
Diagonal of \(W^{'}W + WW\). |
|
Cardinality histogram as a dictionary where key is the id and value is the number of neighbors for that unit. |
|
Dictionary where the key is an ID and the value is that ID’s index in W.id_order. |
|
Returns the ids for the observations in the order in which they would be encountered if iterating over the weights. |
|
Returns True if user has set id_order, False if not. |
|
List of ids without any neighbors. |
|
Largest number of neighbors. |
|
Average number of neighbors. |
|
Minimum number of neighbors. |
|
Number of units. |
|
Store whether the adjacency matrix is fully connected. |
|
Given the current id_order, neighbor_offsets[id] is the offsets of the id’s neighbors in id_order. |
|
Number of nonzero weights. |
|
Percentage of nonzero weights. |
|
s0 is defined as |
|
s1 is defined as |
|
s2 is defined as |
|
Individual elements comprising s2. |
|
Standard deviation of number of neighbors. |
|
Sparse matrix object. |
|
Getter for transform property. |
|
Trace of \(WW\). |
|
Trace of \(W^{'}W\). |
|
Trace of \(W^{'}W + WW\). |
from_dataframe
(df, geom_col='geometry', **kwargs)[source]¶Construct a weights object from a pandas dataframe with a geometry column. This will cast the polygons to PySAL polygons, then build the W using ids from the dataframe.
a :class: pandas.DataFrame containing geometries to use for spatial weights
the name of the column in df that contains the geometries. Defaults to geometry
the name of the column to use as IDs. If nothing is provided, the dataframe index is used
a list of ids to use to index the spatial weights object. Order is not respected from this list.
an ordered list of ids to use to index the spatial weights object. If used, the resulting weights object will iterate over results in the order of the names provided in this argument.
See also
libpysal.weights.weights.W
libpysal.weights.contiguity.Queen
from_iterable
(iterable, sparse=False, **kwargs)[source]¶Construct a weights object from a collection of arbitrary polygons. This will cast the polygons to PySAL polygons, then build the W.
a collection of of shapes to be cast to PySAL shapes. Must support iteration. Contents may either be a shapely or PySAL shape.
optional arguments for pysal.weights.W
from_shapefile
(filepath, idVariable=None, full=False, **kwargs)[source]¶Queen contiguity weights from a polygon shapefile.
name of polygon shapefile including suffix.
name of a column in the shapefile’s DBF to use for ids.
If True return WSP instance If False return W instance
instance of spatial weights
See also
libpysal.weights.weights.W
libpysal.weights.contiguity.Queen
Examples
>>> from libpysal.weights import Queen
>>> import libpysal
>>> wq=Queen.from_shapefile(libpysal.examples.get_path("columbus.shp"))
>>> "%.3f"%wq.pct_nonzero
'9.829'
>>> wq=Queen.from_shapefile(libpysal.examples.get_path("columbus.shp"),"POLYID")
>>> "%.3f"%wq.pct_nonzero
'9.829'
>>> wq=Queen.from_shapefile(libpysal.examples.get_path("columbus.shp"), sparse=True)
>>> pct_sp = wq.sparse.nnz *1. / wq.n**2
>>> "%.3f"%pct_sp
'0.098'
Notes
Queen contiguity defines as neighbors any pair of polygons that share at least one vertex in their polygon definitions.