momepy.weighted_character#
- momepy.weighted_character(y, area, graph)[source]#
Calculates the weighted character.
Character weighted by the area of the objects within neighbors defined in
graph
. Results are index based ongraph
.\[\frac{\sum_{i=1}^{n} {character_{i} * area_{i}}}{\sum_{i=1}^{n} area_{i}}\]Adapted from [Dibble et al., 2017].
- Parameters:
- yNDArray[np.float64] | Series
The character values to be weighted.
- areaNDArray[np.float64] | Series
The area values to be used as weightss
- graphlibpysal.graph.Graph
A spatial weights matrix for values and areas.
- Returns:
- Series
A Series containing the resulting values.
Notes
The index of
y
andarea
must match the index along which thegraph
is built.Examples
Area-weighted elongation within 5 nearest neighbors:
>>> from libpysal import graph >>> path = momepy.datasets.get_path("bubenec") >>> buildings = geopandas.read_file(path, layer="buildings") >>> buildings.head() uID geometry 0 1 POLYGON ((1603599.221 6464369.816, 1603602.984... 1 2 POLYGON ((1603042.88 6464261.498, 1603038.961 ... 2 3 POLYGON ((1603044.65 6464178.035, 1603049.192 ... 3 4 POLYGON ((1603036.557 6464141.467, 1603036.969... 4 5 POLYGON ((1603082.387 6464142.022, 1603081.574...
Measure elongation (or anything else):
>>> elongation = momepy.elongation(buildings) >>> elongation.head() 0 0.908244 1 0.581318 2 0.726527 3 0.838840 4 0.727294 Name: elongation, dtype: float64
Define spatial graph:
>>> knn5 = graph.Graph.build_knn(buildings.centroid, k=5) >>> knn5 <Graph of 144 nodes and 720 nonzero edges indexed by [0, 1, 2, 3, 4, ...]>
Measure the area-weighted character:
>>> momepy.weighted_character(elongation, buildings.area, knn5) focal 0 0.808190 1 0.817309 2 0.627589 3 0.794769 4 0.806403 ... 139 0.780744 140 0.875046 141 0.753670 142 0.440000 143 0.901127 Name: sum, Length: 144, dtype: float64