Learn R Programming

plotKML (version 0.2-4)

kml_layer.STIDF: Write irregular spatio-temporal observations (points, lines and polygons) to KML

Description

Writes an object of class "STIDF" (unstructured/irregular spatio-temporal data) to a KML file with a possibility to parse attribute variables using several aesthetics arguments.

Usage

kml_layer.STIDF(obj, dtime = "", ...)

Arguments

obj
space-time object of class "STID" (spatio-temporal irregular data frame)
dtime
temporal support size (in seconds)
...
additional arguments that can be passed to the kml_layer.Spatial method

encoding

latin1

Details

An object of class "STIDF" contains a slot of type "Spatial*", which is parsed via the kml_layer method depending on the type of spatial object (points, lines, polygons). 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

kml_layer.STTDF

Examples

Run this code
data(HRtemp08)
# format the time column:
HRtemp08$ctime <- as.POSIXct(HRtemp08$DATE, format="%Y-%m-%dT%H:%M:%SZ")
# create a STIDF object:
library(spacetime)
sp <- SpatialPoints(HRtemp08[,c("Lon","Lat")])
proj4string(sp) <- CRS("+proj=longlat +datum=WGS84")
HRtemp08.st <- STIDF(sp, time = HRtemp08$ctime, data = HRtemp08[,c("NAME","TEMP")])
# write to a KML file:
HRtemp08_jan <- HRtemp08.st[1:500]
shape = "http://maps.google.com/mapfiles/kml/pal2/icon18.png"
kml(HRtemp08_jan, dtime = 24*3600, colour = TEMP, shape = shape, labels = "", kmz = TRUE)
## North Carolina SIDS data set:
library("maptools")
fname <- system.file("shapes/sids.shp", package="maptools")[1]
nc <- readShapePoly(fname, proj4string=CRS("+proj=longlat +datum=NAD27"))
time <- as.POSIXct(strptime(c(rep("1974-01-01", length(nc)), 
   rep("1979-01-01", length(nc))), format="data <- data.frame(BIR = c(nc$BIR74, nc$BIR79), NWBIR = c(nc$NWBIR74, nc$NWBIR79), 
SID = c(nc$SID74, nc$SID79))
# copy polygons:
nc.poly <- rep(slot(nc, "polygons"), 2)
# fix the polygon IDs:
for(i in 1:length(row.names(data))) { nc.poly[[i]]@ID = row.names(data)[i] }
sp <- SpatialPolygons(nc.poly, proj4string=CRS("+proj=longlat +datum=NAD27"))
# create a STIDF object:
nct <- STIDF(sp, time = time, data = data)
# write to a KML file:
kml(nct, colour = SID)

Run the code above in your browser using DataLab