# NOT RUN {
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 +ellps=sphere")
(tr <- trip(d, c("tms", "id")))
## don't want adehabitatMA to be loaded as a requirement here
# }
# NOT RUN {
## 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"))
# }
# NOT RUN {
# }
# NOT RUN {
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