elwood_spatial.network
Spatial network construction from GeoDataFrames. Builds distance-band neighbor graphs using libpysal, where each device is connected to others within a threshold distance.

Network Type
Network = dict[str, dict[str, list]]
# Format: {device_id: {"neighbors": [...], "weights": [...]}} build_network(gdf, threshold, id_column, ...)
Build a spatial network from a GeoDataFrame of device locations.
| Parameter | Type | Default | Description |
|---|---|---|---|
gdf | gpd.GeoDataFrame | Device locations with point geometry | |
threshold | float | Distance threshold for neighbor inclusion | |
id_column | str | Column containing device identifiers | |
max_neighbors | int | 20 | Maximum neighbors per device |
min_neighbors | int | 3 | Minimum neighbors required |
projected_crs | str | int | None | None | CRS to project to before distance calc |
Returns Network.
import geopandas as gpd
from elwood_spatial.network import build_network
gdf = gpd.read_file("sensors.geojson")
network = build_network(gdf, threshold=50_000, id_column="sensor_id") filter_network(network, active_ids, min_neighbors=3)
Filter a network to only include active devices, removing any that fall below the minimum neighbor count.
| Parameter | Type | Default | Description |
|---|---|---|---|
network | Network | Full network | |
active_ids | set[str] | list[str] | IDs of currently active devices | |
min_neighbors | int | 3 | Minimum neighbors to retain a device |
Returns Network.
get_neighbors(network, device_id)
Get the neighbor list for a device.
| Parameter | Type | Description |
|---|---|---|
network | Network | Spatial network |
device_id | str | Target device |
Returns list[str]. Empty list if device not found.