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

Anna-Marie Corman annajess at gmx.de
Tue Sep 30 20:10:01 CEST 2014


Hi Robert,

thanks a lot. Your solution worked very well!!!

Best,
Anna

Am 30.09.2014 18:16, schrieb Robert J. Hijmans:
> Anna-Marie,
>
> If I (and Frede) understand the problem, then you can use the
> raster::pointDistance function or similar functions in the geosphere
> package.
>
> dat <- read.table(text =
> "lon lat Date Time Speed Direction col_lat col_long dist_col trip_no
> bird_id trip_id DT date_time
> 7.87248 54.1866 '04.07.2014' '09:25:00' 0.02 314.57 54.1866 7.8724 0.0
> 1 1 1.1 '04.07.2014 09:25:00' '2014-07-04 09:25:00'
> 7.87148 54.1869 '04.07.2014' '09:30:00' 19.11 1.31 54.1866 7.8724 0.1
> 2 1 2.1 '04.07.2014 09:30:00' '2014-07-04 09:30:00'
> 7.87166 54.1850 '04.07.2014' '09:35:00' 14.98 224.79 54.1866 7.8724
> 0.2 3 1 3.1 '04.07.2014 09:35:00' '2014-07-04 09:35:00'
> 7.87168 54.1851 '04.07.2014' '09:35:00' 14.98 224.79 54.1866 7.8724
> 0.2 4 1 4.1 '04.07.2014 09:35:00' '2014-07-04 09:35:00'
> 7.88635 54.1569 '04.07.2014' '09:40:00' 11.44 136.97 54.2 7.9 3.4 1 2
> 1.2 '04.07.2014 09:40:00' '2014-07-04 09:40:00'
> 7.92096 54.1363 '04.07.2014' '09:45:00' 0.28 262.14 54.2 7.9 6.4 2 2
> 2.2 '04.07.2014 09:45:00' '2014-07-04 09:45:00'
> 7.91931 54.1360 '04.07.2014' '09:50:00' 0.42 218.89 54.2 7.9 6.4 3 2
> 3.2 '04.07.2014 09:50:00' '2014-07-04 09:50:00'",
>                    h = TRUE, sep = " ")
>
>
> library(raster)
> dat$distance <- pointDistance(dat[, c('lon', 'lat')], dat[,
> c('col_long', 'col_lat')], lonlat=TRUE)
> dat
>
>
> Robert
>
>



More information about the R-sig-Geo mailing list