iduedu.get_adj_matrix_gdf_to_gdf

iduedu.get_adj_matrix_gdf_to_gdf(gdf_from, gdf_to, nx_graph, weight='length_meter', dtype=<class 'numpy.float16'>, add_dist_tofrom_node=True, threshold=None, max_workers=None)[source]

Compute a shortest-path matrix between two GeoDataFrames over a weighted NetworkX graph.

Each origin (row of gdf_from) and destination (column of gdf_to) is snapped to its nearest graph node (KD-tree), then distances are computed with a batched, Numba-parallel Dijkstra on the graph’s CSR matrix. Result units follow weight: - “length_meter” → meters, - “time_min” → minutes.

Parameters:
  • gdf_from (geopandas.GeoDataFrame) – Origin geometries (any types; snapped via representative points).

  • gdf_to (geopandas.GeoDataFrame) – Destination geometries.

  • nx_graph (networkx.Graph) – Graph with graph[“crs”] and per-edge weight attribute present.

  • weight ({"length_meter", "time_min"}) – Edge attribute to minimize.

  • dtype (np.dtype) – Output matrix dtype (default np.float16 to save memory).

  • add_dist_tofrom_node (bool) – If True, adds straight-line distances from origin geometry → its snap node and from snap node → destination geometry: - if weight=”length_meter”: meters are added, - if weight=”time_min”: meters converted to minutes assuming 5 km/h (~83.33 m/min).

  • threshold (int | None) – Optional max path threshold in weight units; longer paths are treated as missing. Internally quantized by ×100 for integer CSR; None ⇒ no cutoff.

  • max_workers (int | None) – If set, limits Numba thread count (nb.set_num_threads(max_workers)).

Returns:

Matrix with index = gdf_from.index, columns = gdf_to.index.

Values are shortest-path distances; unreachable pairs are np.inf.

Return type:

(pd.DataFrame)

Raises:
  • ValueError – If the graph lacks graph[“crs”].

  • CRSError – If the graph CRS is invalid or reprojection fails.

Notes

  • The graph is first pruned to its largest strongly connected component to avoid spurious .

  • For performance, if len(gdf_from) > len(gdf_to), the computation is performed transposed and flipped back.

  • Internally, edge weights are converted to uint32 by multiplying by 100; results are divided by 100 before returning.