[R-sig-Geo] plotKML and time stamp

Tomislav Hengl hengl at spatial-analyst.net
Wed Oct 3 13:40:54 CEST 2012


try:

 > library(plotKML)
 > data(HRtemp08)
# format the time column:
 > HRtemp08$ctime <- as.POSIXct(HRtemp08$DATE, format="%Y-%m-%dT%H:%M:%SZ")
## Not run: # 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, labels = TEMP, shape = shape, 
colour = TEMP, colour_scale=rep("#FFFF00", 2), kmz = TRUE)

See also:

http://plotkml.r-forge.r-project.org/tutorial.php#sp_classes
http://plotkml.r-forge.r-project.org/layer.STIDF.html

Note that, when using 'kml' method, you need to open the KML file yourself.

T. Hengl

On 02/10/2012 15:01, Struve,Juliane wrote:
> Hello,
>
> The attribute I am interested in is a site number. When I use the
> site number as attribute data the size of the bubble is proportional
> to the number, which does not really make sense given that the data
> are just site numbers. But when I make it a constant I lose the site
> number information. How can I get a plot that shows all the locations
> with the same size bubble but displays also the site number
> information, say like a label ? It seems that the attribute data need
> to be numeric.
>
> Thank you for your time,
>
> Juliane
>
> -----Original Message----- From: Edzer Pebesma
> [mailto:edzer.pebesma at uni-muenster.de] Sent: Monday, October 01, 2012
> 4:55 PM To: Struve,Juliane; r-sig-geo at r-project.org Subject: Re:
> [R-sig-Geo] plotKML and time stamp
>
>
>
> On 10/01/2012 05:47 PM, Struve,Juliane wrote:
>> Edzer,
>>
>> Thank you for your help, this works nicely. When xy.sp are the
>> points and tc is the date/time stamp, why is df needed  ?
>>
>
> You can create an STI object with just the space-time points, leaving
> out the df, but plotKML does not (yet) have a method to display STI
> objects -- it wants STIDF with attributes. To work around this, you
> could try giving the attribute a constant value, if you don't have
> sth that varies.
>
>> Regards,
>>
>> Juliane
>>
>>
>> -----Original Message----- From: r-sig-geo-bounces at r-project.org
>> [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Edzer
>> Pebesma Sent: Sunday, September 30, 2012 6:06 AM To:
>> r-sig-geo at r-project.org Subject: Re: [R-sig-Geo] plotKML and time
>> stamp
>>
>> Juliane, try
>>
>> xc = round(runif(10,-1,1)+27.2, 2) yc = round(runif(10,-1,1)+-82.5,
>> 2) xy = cbind(xc, yc) tc = Sys.time() + 3600 * (1:10) df =
>> data.frame(z1 = round(5 + rnorm(10), 2), z2 = 20:29)
>>
>> library(sp) xy.sp = SpatialPoints(xy) proj4string(xy.sp) =
>> CRS("+proj=longlat +datum=WGS84")
>>
>> library(spacetime) ST = STIDF(xy.sp, tc, df)
>>
>> library(plotKML) plotKML(ST)
>>
>> see also
>>
>> vignette(spacetime)
>>
>>
>> On 09/30/2012 03:39 AM, Struve,Juliane wrote:
>>> Dear list,
>>>
>>> After plotting this toy example on Google Earth I would like to
>>> add a date/time stamp to it so that the locations will be shown
>>> in sequence using the time slider. I am not quite sure how to
>>> approach this, can I add a date/time to my spatial points and
>>> then submit it to plotKML ? What format does the date/time stamp
>>> have to be in to be plotted on Google Earth ?
>>>
>>> Many thanks for any suggestions.
>>>
>>> Regards,
>>>
>>> Juliane
>>>
>>>
>>> xc = round(runif(10,-1,1)+27.2, 2) yc =
>>> round(runif(10,-1,1)+-82.5, 2) xy = cbind(xc, yc) xy.sp =
>>> SpatialPoints(xy) df = data.frame(z1 = round(5 + rnorm(10), 2),
>>> z2 = 20:29) SP.spdf = SpatialPointsDataFrame(xy.sp, df)
>>> plot(SP.spdf) #add a projection proj4string(SP.spdf) =
>>> CRS("+proj=longlat +datum=WGS84") plotKML(SP.spdf,kmz = FALSE)
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> _______________________________________________ R-sig-Geo mailing
>>> list R-sig-Geo at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>> -- Edzer Pebesma Institute for Geoinformatics (ifgi), University of
>> Münster Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
>> 8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
>> http://www.52north.org/geostatistics      e.pebesma at wwu.de
>>
>> _______________________________________________ R-sig-Geo mailing
>> list R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> -- Edzer Pebesma Institute for Geoinformatics (ifgi), University of
> Münster Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
> 8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
> http://www.52north.org/geostatistics      e.pebesma at wwu.de
>
> _______________________________________________ R-sig-Geo mailing
> list R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list