Trying to find, for each point in a SpatialPointsDataFrame
, the distance to the closest point in a second SpatialPointsDataFrame
(equivalent to the "nearest" tool in ArcGIS for two SpatialPointDataFrames
).
I can do the naive implementation by calculating all pairwise distances using gDistance
and taking the min
(like answer 1 here), but I have some huge datasets and was looking for something more efficient.
For example, here's a trick with knearneigh
for points in same dataset.
Cross-posted on r-sig-geo
spDists
in thesp
package might work for what you want. It's first two arguments appear to be different matrices that could be used to represent two sets of points as in your example. Worth a look anyway. – Canella