spacenet.helpers.node_node_distance#

spacenet.helpers.node_node_distance(spatial_network, sources=None, weight='Distance', limit=inf, low_memory=False, verbose=False)#

Computes the shortest path distances from a set of source nodes to all other nodes in a spatial network, with optional caching to avoid redundant computations. The function can use a low-memory implementation of Dijkstra’s algorithm that computes distances in batches, which can be useful for large networks that do not fit in memory. The computed distances are stored in the network’s distance cache for future use, and the function checks the cache before performing any computations to see if the requested distances are already available.

Parameters:
spatial_networkNetworkX graph

The spatial network for which to compute node-node distances.

sourcesarray-like

A list or array of source node indices for which to compute shortest path distances to all other nodes in the graph. If None, distances will be computed for all nodes in the graph. Default is None.

weightstr, optional

The name of the edge attribute to use as the weight for computing shortest path distances. Default is ‘Distance’.

limitfloat, optional

The maximum distance to consider when computing shortest path distances. Nodes that are farther than this distance from the source will be ignored. Default is np.inf (no limit).

low_memorybool, optional

Whether to use a low-memory implementation of Dijkstra’s algorithm that computes distances in batches. This can be useful for large networks that do not fit in memory. Default is False.

verbosebool, optional

Whether to print progress messages during computation. Default is False.

Returns:
node_node_distancesdict

A dictionary mapping each source node to a dictionary of shortest path distances to all other nodes in the graph. The inner dictionary maps target node indices to their corresponding shortest path distances from the source node.