pysal.explore.spaghetti.Network.allneighbordistances

Network.allneighbordistances(sourcepattern, destpattern=None, fill_diagonal=None, n_processes=None, gen_tree=False, snap_dist=False)[source]

Compute either all distances between i and j in a single point pattern or all distances between each i from a source pattern and all j from a destination pattern.

Parameters:
sourcepattern : str or spaghetti.network.PointPattern

The key of a point pattern snapped to the network OR the full spaghetti.network.PointPattern object.

destpattern : str

(Optional) The key of a point pattern snapped to the network OR the full spaghetti.network.PointPattern object.

fill_diagonal : float, int

(Optional) Fill the diagonal of the cost matrix. Default in None and will populate the diagonal with numpy.nan Do not declare a destpattern for a custom fill_diagonal.

n_processes : int, str

(Optional) Specify the number of cores to utilize. Default is 1 core. Use (int) to specify an exact number or cores. Use (“all”) to request all available cores.

gen_tree : bool

rebuild shortest path {True}, or skip {False}

snap_dist : bool

include the distance from the original location to the snapped location along the network. Default is False.

Returns:
nearest : numpy.ndarray

An array of shape (n,n) storing distances between all points.

tree_nearest : dict

nearest network node to point pattern node shortest path lookup

Examples

>>> import pysal.explore.spaghetti as spgh
>>> ntw = spgh.Network(examples.get_path('streets.shp'))
>>> ntw.snapobservations(examples.get_path('crimes.shp'),
...                                        'crimes',
...                                         attribute=True)
>>> s2s_dist = ntw.allneighbordistances('crimes')
>>> s2s_dist[0,0], s2s_dist[1,0]
(nan, 3105.189475447081)
>>> ntw.snapobservations(examples.get_path('schools.shp'),
...                                        'schools',
...                                        attribute=False)
>>> s2d_dist = ntw.allneighbordistances('crimes',
...                                     destpattern='schools')
>>> s2d_dist[0,0], s2d_dist[1,0]
(4520.72353741989, 6340.422971967316)
>>> s2d_dist, tree = ntw.allneighbordistances('schools',
...                                           gen_tree=True)
>>> tree[(6, 7)]
(173, 64)