[R-sig-Geo] (no subject)

Roger Bivand Roger.Bivand at nhh.no
Thu Apr 9 22:42:01 CEST 2009


On Thu, 9 Apr 2009, x wong wrote:

> I do use Windows, and thank you very much for the help!
>
> I know how to do this in GIS as Jonathan suggested; however, I haven't tried
> it in R with the solution Rick recommended since i am still cleaning my
> input data.
>
> The problem of this task is very obvious: it will be super inefficient if
> all the distances have to be calculated. My initial thought was to locate
> the target points and subset the dataset before any calculations being made,
> but it may require quite a bit coding...... What you described sounds great
> to me, and i am looking forward to seeing it.
>
> b.t.w. the link you provided doesn't work, would you please double check it?

The link works:

http://spatial.nhh.no/R/etc/ann*

means look in:

http://spatial.nhh.no/R/etc/

for all files with names beginning with ann. The build for R 2.8.* is at:

http://spatial.nhh.no/R/etc/ann_0.3-2.zip

You will have to subset your data into two matrices of planar coordinates, 
one matrix for the data= argument, the other for the query= argument to 
ann(). The output object contains the k nearest neighbours in data= for 
each point in query=, and their distances. See ?ann after installing the 
package.

Roger

>
> X.W.
>
>
>
>
>
>
> On Thu, Apr 9, 2009 at 3:07 AM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
>
>> 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 <reeves at nceas.ucsb.edu>
>>> 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
>>>>>> R-sig-Geo at stat.math.ethz.ch
>>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>> R-sig-Geo mailing list
>>>>> R-sig-Geo at stat.math.ethz.ch
>>>>> 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
>>> R-sig-Geo at stat.math.ethz.ch
>>> 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: Roger.Bivand at nhh.no
>>
>>
>

-- 
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: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list