On Wed, 8 Apr 2009, x wong wrote:
Thank you very much, that is very helpful.x.w. On Wed, Apr 8, 2009 at 12:47 PM, rick reeves <[email protected]> wrote:Assuming that this dataset fits within the confines of R, this could be done with sp package: spdistsN1() function See attached sample solution: http://nceas.ucsb.edu/scicomp/GISSeminar/UseCases/AssignClosestPointsR/AssignClosestPointsR.html Hope this helps! RR
Note that this will be inefficient in that it calculates all the distances. I have an off-CRAN package interfacing ANN, which - given two sets of points, returns the k nearest in the first set (with distances) for each point in the second set. ANN builds a tree of the first set, so searches for nearest neighbours efficiently. Look for:
http://spatial.nhh.no/R/etc/ann*The Windows binary wasn't built for the current release of R, so probably needs rebuilding - let me know if you use Windows, and I'll re-build it.
Hope this helps, Roger
Jonathan Greenberg wrote:It seems that a raster-based approach would make more sense, rather than the hugely computationally inefficient approach you are suggesting -- how about using a least cost path or euclidean distance approach? Both are available in many GIS packages (ArcMap, GRASS GIS, etc...) --j x wong wrote:dear all, I have a raster GIS map converted to points. Now, I am trying to calculate the nearest neighbor distance for every point to a cluster of points within this map. Since the number of points is more than two millions, I am wondering whether there is a computation efficient way to do this. The following is what the data looks like: point_id,x_coord,y_coord,class 675,-821292,6896866,GL 738,-819294,6895866,GL 803,-819294,6894867,GL 804,-818295,6894867,GL 805,-817296,6894867,GL 806,-816297,6894867,RCK 873,-818296,6893867,GL 874,-817297,6893867,GL 875,-816298,6893868,RCK 876,-815299,6893868,RCK 877,-814300,6893868,RCK 878,-813300,6893868,GL 945,-817297,6892867,GL 946,-816298,6892868,RCK 947,-815299,6892868,RCK 948,-814300,6892868,RCK 949,-813301,6892868,GL 950,-812302,6892869,GL 951,-811303,6892869,GL 1021,-816298,6891868,RCK 1023,-814300,6891868,RCK 1024,-813301,6891869,GL 1025,-812302,6891869,GL 1027,-810304,6891869,GL 1028,-809305,6891870,GL 1029,-808306,6891870,GL 1098,-816299,6890868,RCK 1099,-815300,6890868,RCK 1100,-814301,6890868,GL 1101,-813302,6890869,GL ............................................ I want to calculate, for example, the nearest distances for all GL points to the RCK class. X.W. [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-geo_______________________________________________ R-sig-Geo mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-geo-- Rick Reeves Scientific Programmer/Analyst and Data Manager National Center for Ecological Analysis and Synthesis UC Santa Barbara www.nceas.ucsb.edu 805 892 2533[[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
-- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: [email protected] _______________________________________________ R-sig-Geo mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
