weights2gdf
cellseg_gsontools.links.weights2gdf(gdf, w, parallel=False)
¶
Convert a libpysal
weights object to a geopandas.GeoDataFrame
.
Add class names and node centroids to the dataframe.
Note
if w.neighbors
is empty, this will return None.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gdf |
GeoDataFrame
|
GeoDataFrame of the nodes. |
required |
w |
W
|
PySAL weights object. |
required |
parallel |
bool, default=False
|
Whether to use parallel processing. |
False
|
Returns:
Type | Description |
---|---|
GeoDataFrame
|
gpd.GeoDataFrame: GeoDataFrame of the links. |
Examples:
Convert libpysal
weights from InterfaceContext
to geopandas.GeoDataFrame
.
>>> from cellseg_gsontools.spatial_context import InterfaceContext
>>> from cellseg_gsontools.links import weights2gdf
>>> iface_context = InterfaceContext(
... area_gdf=areas,
... cell_gdf=cells,
... top_labels="area_cin",
... bottom_labels="areastroma",
... silence_warnings=True,
... min_area_size=100000.0,
... )
>>> iface_context.fit(verbose=False)
>>> w = iface_context.context2weights("border_network")
>>> link_gdf = weights2gdf(cells, w)