# [R-sig-Geo] Calculating distance to nest with spDistsN1

Anna-Marie Corman annajess at gmx.de
Mon Sep 29 12:40:25 CEST 2014

```Dear list,

I have a question regarding the spDistsN1 function. I want to calculate
the distance of each flight position to the relevant nest position. My
dataset consists of several birds with a differing number of trips.
There is a unique trip_id with the first number regarding to the bird
and the second number regarding to the trip.

coordinates       Date     Time Speed Direction col_lat col_long dist_col
1 (7.87248, 54.1866) 04.07.2014 09:25:00  0.02    314.57 54.1866   7.8724      0.0
2 (7.87148, 54.1869) 04.07.2014 09:30:00 19.11      1.31 54.1866   7.8724      0.1
3  (7.87166, 54.185) 04.07.2014 09:35:00 14.98    224.79 54.1866   7.8724      0.2
4 (7.88635, 54.1569) 04.07.2014 09:40:00 11.44    136.97 54.1866   7.8724      3.4
5 (7.92096, 54.1363) 04.07.2014 09:45:00  0.28    262.14 54.1866   7.8724      6.4
6  (7.91931, 54.136) 04.07.2014 09:50:00  0.42    218.89 54.1866   7.8724      6.4
trip_no bird_id trip_id                  DT           date_time
1       1       1     1.1 04.07.2014 09:25:00 2014-07-04 09:25:00
2       1       1     1.1 04.07.2014 09:30:00 2014-07-04 09:30:00
3       1       1     1.1 04.07.2014 09:35:00 2014-07-04 09:35:00
4       1       1     1.1 04.07.2014 09:40:00 2014-07-04 09:40:00
5       1       1     1.1 04.07.2014 09:45:00 2014-07-04 09:45:00
6       1       1     1.1 04.07.2014 09:50:00 2014-07-04 09:50:00

Formerly, when I only had one bird and so only one nest position (here
col_lat & col_long), I did the following:

spDistsN1(coordinates(dat at coords), matrix(c(8.3495235,54.7042698), nrow
= 1), longlat = T)

and this worked fine.

But now I want to calculate the distance from nest for each bird
simultaneously. Must be simple, but I do not get it. I thought I could
simply use

spDistsN1(coordinates(dat at coords), matrix(c(dat\$col_long,dat\$col_lat),
nrow = 1), longlat = T)

instead, but it does not work.

Do you have any idea how to solve the "problem"?