Learn R Programming

plotKML (version 0.2-4)

kml_layer.STTDF: Write a space-time trajectory to KML

Description

Writes an object of class "STTDF" to a KML file with a possibility to parse attribute variables using several aesthetics arguments.

Usage

kml_layer.STTDF(obj, id.name = names(obj@data)[which(names(obj@data)== "burst")],
       dtime = "", extrude = FALSE, 
       start.icon = paste(get("home_url", envir = plotKML.opts), "3Dballyellow.png", sep = ""), 
       end.icon = paste(get("home_url", envir = plotKML.opts), "golfhole.png", sep = ""), 
       LabelScale = 0.8 * get("LabelScale", envir = plotKML.opts), z.scale = 1,
       metadata = NULL, html.table = NULL, ...)

Arguments

obj
space-time object of class "STTDF" (spatio-temporal irregular data.frames trajectory)
id.name
trajectory ID column name
dtime
temporal support size (in seconds)
extrude
logical; extrude GPS vertices?
start.icon
start icon name (3Dballyellow.png)
end.icon
destination icon name (golfhole.png)
LabelScale
the default size of icons
z.scale
vertical exaggeration
metadata
(optional) specify the metadata object
html.table
optional description block (html) for each GPS point (vertices)
...
other optional arguments

encoding

latin1

Details

The dateTime is defined as yyyy-mm-ddThh:mm:sszzzzzz, where T is the separator between the date and the time, and the time zone is either Z (for UTC) or zzzzzz, which represents {+-}hh:mm in relation to UTC. For more info on how Time Stamps work see http://kml-samples.googlecode.com. If the time is measured at block support, then: tags will be inserted. Temporal support ($\Delta t$) is estimated using the xts::periodicity function (median time between observations). The begin time is then derived as $t_1 = t - .5\cdot \Delta t$.

References

  • Pebesma, E. (2011) Classes and Methods for Spatio-Temporal Data in R. Journal of Statistical Software.
  • spacetime package (http://CRAN.R-project.org/package=spacetime)

See Also

readGPX

Examples

Run this code
data(gpxbtour)
# format the time column:
gpxbtour$ctime <- as.POSIXct(gpxbtour$time, format="%Y-%m-%dT%H:%M:%SZ")
coordinates(gpxbtour) <- ~lon+lat
proj4string(gpxbtour) <- CRS("+proj=longlat +datum=WGS84")
# derive distance from origin:
library(fossil)
xy <- as.list(data.frame(t(coordinates(gpxbtour))))
gpxbtour$dist.km <- sapply(xy, function(x) 
  deg.dist(long1=x[1], lat1=x[2], long2=xy[[1]][1], lat2=xy[[1]][2]))
plot(gpxbtour$dist.km, gpxbtour$speed, type="l", 
  xlab="Distance from origin in km", ylab="speed in km per hour")
# convert to a STTDF class:
library(spacetime)
library(adehabitat)
gpx.ltraj <- as.ltraj(coordinates(gpxbtour), gpxbtour$ctime, id = "th")
gpx.st <- as(gpx.ltraj, "STTDF")
gpx.st$speed <- gpxbtour$speed
gpx.st@sp@proj4string <- CRS("+proj=longlat +datum=WGS84")
# open KML file:
kml_open("gpxbtour_speed.kml")
# plot trajectory with speed as colour attribute:
kml_layer(obj = gpx.st, colour = speed, z.lim = c(18,32))
# close KML:
kml_close("gpxbtour_speed.kml")
kml_compress("gpxbtour_speed.kml")

Run the code above in your browser using DataLab