Network.allneighbordistances(self, 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.
The key of a point pattern snapped to the network OR
the full spaghetti.network.PointPattern object.
(Optional) The key of a point pattern snapped to the network
OR the full spaghetti.network.PointPattern object.
(Optional) Fill the diagonal of the cost matrix. Default is
None and will populate the diagonal with numpy.nan.
Do not declare a destpattern for a custom
fill_diagonal.
(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.
Rebuild shortest path True, or skip False.
Flag as True to include the distance from the original
location to the snapped location along the network. Default
is False.
An array of shape (n,n) storing distances between all points.
Nearest network node to point pattern vertex shortest
path lookup. The values of the dictionary are a tuple
of the nearest source vertex and the near destination
vertex to query the lookup tree. If two observations are
snapped to the same network arc a flag of -.1 is set for
both the source and destination network vertex
indicating the same arc is used while also raising an
IndexError when rebuilding the path.
Examples
>>> import 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)