Learn R Programming

trip (version 1.1-1)

trip-methods: Function to handle animal track data, organized as "trip"s

Description

Create an object of class "trip", extending the basic functionality of SpatialPointsDataFrame by specifying the data columns that define the "TimeOrdered" quality of the records.

Arguments

obj
A SpatialPointsDataFrame, or an object that can be coerced to one, containing at least two columns with the DateTime and ID data as per TORnames. It can also be a
TORnames
Either a TimeOrderedRecords object, or a 2-element character vector specifying the DateTime and ID column of obj

Value

  • A trip object, with the usual slots of a SpatialPointsDataFrame and the added TimeOrderedRecords. For the most part this can be treated as a data.frame with Spatial coordinates.

See Also

speedfilter, and tripGrid for simple(istic) speed filtering and spatial time spent gridding.

Examples

Run this code
d <- data.frame(x=1:10, y=rnorm(10), tms=Sys.time() + 1:10, id=gl(2, 5))
coordinates(d) <- ~x+y
## this avoids complaints later, but these are not real track data (!)
proj4string(d) <- CRS("+proj=laea")
(tr <- trip(d, c("tms", "id")))

## don't want adehabitatMA to be loaded as a requirement here
## a simple example with the common fixes required for basic track data

dat <- read.csv("trackfile.csv")
names(dat)  ## e.g. [1] "long" "lat" "seal" "date" "local" "lq"
library(sp)
coordinates(dat) <- c("long", "lat")

## date/times may be in a particular time zone, please check
dat$gmt <- as.POSIXct(strptime(paste(dat$date, dat$local),
                      "%d-%b-%y %H:%M:%S"), tz="GMT")

## if there are problems in the data, this will error
tr <- trip(dat, c("gmt", "seal"))

## the following code tries to fix common problems

## remove completely-duplicated rows
dat <- dat[!duplicated(dat), ]
## order the rows by seal, then by time
dat <- dat[order(dat$seal, dat$gmt), ]
## fudge duplicated times
dat$gmt <- adjust.duplicateTimes(dat$gmt, dat$seal)

## finally, convert to Spatial and create trip object
coordinates(dat) <- c("long", "lat")
tr <- trip(dat, c("gmt", "seal"))


if (require(adehabitatLT)) {
     data(porpoise)
     porpoise <- as.trip(porpoise)
     proj4string(porpoise) <- CRS("+proj=utm +zone=21 +ellps=WGS84 +units=m +no_defs")
     summary(porpoise)

   }


   ## extended example to check that our projection metadata is correct
   library(maptools)
   data(wrld_simpl)
   library(rgeos)
   library(raster)

   ## 3 degrees either side (for half a zone . . .)
   ext <- as(extent(spTransform(porpoise, CRS(proj4string(wrld_simpl)))) + 3, "SpatialPolygons")
   proj4string(ext) <- CRS(proj4string(wrld_simpl))
   ## crop to the buffered tracks, and project to its native CRS
   w <- spTransform(gIntersection(wrld_simpl[grep("United States", wrld_simpl$NAME), ], ext),
    CRS(proj4string(porpoise)))

   plot(w)
   lines(porpoise)

Run the code above in your browser using DataLab