Hello again! Happy New Year! Here is the solution for this particular situation. Note: thanks to many people for the help. Anyhow, I started with looking at page 28 in the gstat vignette for krigeST. If you work through that, you obtain an object called DE_kriged, which is an STFDF.
I copied some code from the following website: (https://r-forge.r-project.org/scm/viewvc.php/pkg/R/coerce.R?view=markup&root=spacetime <https://r-forge.r-project.org/scm/viewvc.php/pkg/R/coerce.R?view=markup&root=spacetime&pathrev=25>) to get the as.STIDF.STFDF lines: # STFDF -> STIDF as.STIDF.STFDF = function(from) { as(as(from, "STSDF"), "STIDF") } setAs("STFDF", "STIDF", as.STIDF.STFDF) Now: > DE1 <- as.STIDF.STFDF(DE_kriged) DE1 is an STIDF object, which is good, but the @sp section is a Spatial Pixels object. Next I copied over the function kml_layer.STIDF to new_STIDF.R and added the following section (see the note) new.STIDF <- function (obj, dtime = "", ...) { if (all(dtime == 0)) { TimeSpan.begin = format(time(obj@time), "%Y-%m-%dT%H:%M:%SZ") TimeSpan.end = TimeSpan.begin } else { if (length(obj@time) > 1 & !nzchar(dtime)) { print(obj@time) period <- periodicity(obj@time) dtime <- period$frequency } TimeSpan.begin <- format(as.POSIXct(unclass(as.POSIXct(time(obj@time))) - dtime/2, origin = "1970-01-01"), "%Y-%m-%dT%H:%M:%SZ") TimeSpan.end <- format(as.POSIXct(unclass(as.POSIXct(time(obj@time))) + dtime/2, origin = "1970-01-01"), "%Y-%m-%dT%H:%M:%SZ") } if (class(obj@sp) == "SpatialPoints" | class(obj@sp) == "SpatialPointsDataFrame") { sp <- SpatialPointsDataFrame(obj@sp, obj@data) kml_layer.SpatialPoints(obj = sp, TimeSpan.begin = TimeSpan.begin, TimeSpan.end = TimeSpan.end, ...) } else { if (class(obj@sp) == "SpatialPolygons" | class(obj@sp) == "SpatialPolygonsDataFrame") { sp <- SpatialPolygonsDataFrame(obj@sp, obj@data) kml_layer.SpatialPolygons(obj = sp, TimeSpan.begin = TimeSpan.begin, TimeSpan.end = TimeSpan.end, ...) } else { if (class(obj@sp) == "SpatialLines" | class(obj@sp) == "SpatialLinesDataFrame") { sp <- SpatialLinesDataFrame(obj@sp, obj@data) kml_layer.SpatialLines(obj = sp, TimeSpan.begin = TimeSpan.begin, TimeSpan.end = TimeSpan.end, ...) } ########################################################### # New for Spatial Pixels # ########################################################## else { if (class(obj@sp) == "SpatialPixels" | class(obj@sp) == "SpatialPixelsDataFrame") { sp <- SpatialPixelsDataFrame(obj@sp, obj@data) kml_layer.SpatialPoints(obj = sp, TimeSpan.begin = TimeSpan.begin, TimeSpan.end = TimeSpan.end, ...) } else { stop("The STIDF object does not extend SpatialPoints*, SpatialLines* or SpatialPolygons*") } } } } } Finally, I ran this: > library(plotKML) plotKML version 0.4-0 (2013-11-15) URL: http://plotkml.r-forge.r-project.org/ Warning message: replacing previous import by zoo::as.zoo when loading gstat > library(gstat) Loading required package: sp > kml_open("stuff2.kml") KML file opened for writing... > new.STIDF(DE1,dtime=24*3600,colour=var1.pred) Parsing to KML... > kml_close("stuff2.kml") Closing stuff2.kml > All is well. Google Earth lets you run the kml file and show the time change, as it should. Hope this might help someone! Thanks, Erin [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo