Revision dc000f2a5f006d137f66716b086025d618bf8306 authored by John M Chambers on 14 July 2008, 00:00:00 UTC, committed by Gabor Csardi on 14 July 2008, 00:00:00 UTC
1 parent 635622b
Raw File
GPSTrack.R

setClassUnion("DateTime", c("POSIXt", "POSIXct", "POSIXlt"))

setClass("GPSTrack",
  representation(latitude = "numeric", longitude = "numeric",
                 elevation = "numeric", time = "DateTime")
)

scanGPSTrack <- function(con, 
    fields = list(date = "", time = "",
                    lat = 0., lon = 0., el = 0.),
    dateTimeFormat = "%Y-%m-%d %H:%M:%S") {
    data <- scan(con, fields)
    txt <- textConnection(paste(data$date, data$time), "r")
    dateTime <- .scanDateTime(txt, dateTimeFormat)
    close(txt)
    new("GPSTrack", latitude = data$lat, longitude = data$lon,
          elevation = data$el, time = dateTime)
}

.scanDateTime <- function(con, dateTimeFormat) {
    as.POSIXct(strptime(readLines(con), dateTimeFormat))
}
back to top