[R-sig-Geo] sub-selecting spatial data by distance from a different (point) set

Adrian.Baddeley at csiro.au Adrian.Baddeley at csiro.au
Sun Nov 15 22:23:38 CET 2009


"Sean O'Riordain" seanpor at acm.org<mailto:seanpor at acm.org> writes:

> I've read the Spatial Data task view, "Analysing spatial point
> patterns in R" by Bradley

      who?!?!    :-)

> I have a data.frame (call it A) of about 2 million X,Y points each
> with info with various characteristics, numeric and factor.  I have a
> separate much smaller data.frame (call it B) of say 500 rows of X,Y
> and I'd like to be able to pull a subset of A, so that for each B[i,]
> I will get all rows from A that are within a given straight line
> distance (i.e. within a short 'as the crow flies' radius).

    In the package spatstat you can use the function closepairs() to do this.

Convert the data frames to objects of class 'ppp'. Then closepairs(A, B, r)
will return a list of all pairs i,j such that A[i] and B[j] are within a distance r.
The return value is a list containing vectors named i, j, d (and a few other things).

regards
Adrian Baddeley



More information about the R-sig-Geo mailing list