Network.nearestneighbordistances(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.

sourcepattern : str

The key of a point pattern snapped to the network.

destpattern : str

(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_tree : bool

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

all_dists : numpy.ndarray

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

snap_dist : bool

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

keep_zero_dist : bool

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 nans

nearest : dict

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


>>> import pysal.explore.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))