[R-sig-Geo] nearest neighbour between locations in two data sets

Sasha Cuerda sasha.cuerda at gmail.com
Wed Apr 16 16:39:50 CEST 2014


Gabriele,

Check out the nncross function within spatstat. Should be what you are
looking for.

Sasha

On Wed, Apr 16, 2014 at 10:20 AM, Gabriele Cozzi <gab.cozzi at gmail.com> wrote:
> Dear list,
>
> I have two data sets sets:
> - one with lon lat coordinates of relocation events from GPS radio collared
> animals and
> - one with lon lat coordinates of villages.
>
> For each animal relocation (n = 50'000 ), I want to compute the distance to
> the nearest village (n = 40). I am failing to find a function that allows
> this calculation between two data sets and only find functions that return
> the neared neighbour from within a single data set such as
>  nndist{spatstat}.
>
> Is there a function that returns the distance between each location in a
> data frame and the closes location from another data frame?
>
> Alternatively I was considering, in turn (through a loop) pasting each
> animal relocation into the villages data set, calculate the nearest
> neighbour and then paste the distance to the nearest village back to the
> original animal relocation data set, but this seems an incredibly
> non-efficient solution...
>
> Any suggestion will be highly appreciated!
>
> Thanks,
> Gabriele
>
>
> --
> Gabriele Cozzi
> Postdoctoral Research Associate
> Population Ecology Research Group
> http://www.popecol.org
>
> Zurich University
> Institute of Evolutionary Biology and Environmental Studies
> Winterthurerstr. 190
> 8057 Zurich - Switzerland
> E-mail: gabriele.cozzi at uzh.ch
> Phone: +41(0)44 635 49 12
> Fax: +41(0)16355711
> http://www.ieu.uzh.ch
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list