spaghetti.Network.nearestneighbordistances

Network.nearestneighbordistances(self, sourcepattern, destpattern=None, n_processes=None, gen_tree=False, all_dists=None, snap_dist=False, keep_zero_dist=True)[source]

Compute the interpattern nearest neighbor distances or the intrapattern nearest neighbor distances between a source pattern and a destination pattern.

Parameters
sourcepatternstr

The key of a point pattern snapped to the network.

destpatternstr

(Optional) The key of a point pattern snapped to the network.

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_treebool

Rebuild shortest path True, or skip False.

all_distsnumpy.ndarray

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

snap_distbool

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

keep_zero_distbool

Include zero values in minimum distance True or exclude False. Default is True. If the source pattern is the same as the destination pattern the diagonal is filled with numpy.nan.

Returns
nearestdict

key is source point id, value is tuple of list containing nearest destination point ids and distance.

Examples

>>> import spaghetti as spgh
>>> ntw = spgh.Network(examples.get_path('streets.shp'))
>>> ntw.snapobservations(examples.get_path('crimes.shp'),
...                      'crimes')
>>> nn = ntw.nearestneighbordistances('crimes',
...                                   keep_zero_dist=True)
>>> nn[11], nn[18]
(([18, 19], 165.33982412719126), ([19], 0.0))
>>> nn = ntw.nearestneighbordistances('crimes',
...                                   keep_zero_dist=False)
>>> nn[11], nn[18]
(([18, 19], 165.33982412719126), ([11], 165.33982412719126))