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.
The key of a point pattern snapped to the network.
(Optional) The key of a point pattern snapped to the network.
(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
.
An array of shape (n,n) storing distances between all points.
Flag as True
to include the distance from the original
location to the snapped location along the network. Default
is False
.
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
.
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))