[R-sig-Geo] question about plotKML() - Google Earth

Tomislav Hengl hengl at spatial-analyst.net
Mon Oct 22 16:46:32 CEST 2012



On 12/10/2012 15:37, Struve,Juliane wrote:
> Hi,
>
> These are the files and the code I used.
>
> Thanks for help plotting the data with correct IDs.
>
> Juliane
>
> filename <- "1647"
> Data <- read.csv(filename,header=TRUE,sep=",")
> Data <- na.omit(Data)
> head(Data)
> Data$Fish_ID <- as.numeric(Data$Fish_ID)
> Data$Date <- with(Data, as.POSIXct(paste(as.character(Date), substring(as.character(Time), 12))))
> library(sp)
> Data.sp <- SpatialPoints(cbind(Data$Xcoordinate,Data$Ycoordinate))
> proj4string(Data.sp) = CRS("+proj=longlat +datum=WGS84")
> Data.spdf <- (SpatialPointsDataFrame(Data.sp, data.frame(Data$Fish_ID)))
> plot(Data.spdf,pch=16,col="blue")
> title(filename)
> library(spacetime)
> Data.ST <- STIDF(Data.sp, Data$Date, data.frame(Data$Fish_ID))
> head(Data.ST)
> library(plotKML)
> plotKML(Data.ST,colour_scale=rep("#FFFF00", 2),kmz=FALSE)
>

The rounding of numbers is on purpose. If you send a numeric vector, I 
noticed that I need to round up numbers before writing to KML, otherwise 
the text in the KML does not look nice, e.g. you get the 32-bit computer 
numbers:

 > paste(1/3)
[1] "0.333333333333333"
 > paste(signif(1/3, 3))
[1] "0.333"

Your data set is in fact a BIG data set (although you have only 5 
points!), so I would advise you to start with a subset, then improve. To 
get the point ID's in Google Earth, I would simply use the 
"points_names" argument e.g.:

 > filename <- "1647"
 > Data <- read.csv(filename,header=TRUE,sep=",")
 > Data <- na.omit(Data)
 > Data$ID <- as.factor(Data$ID)
 > Data$Date <- with(Data, as.POSIXct(paste(as.character(Date), 
substring(as.character(Time), 12))))
 > library(sp)
 > coordinates(Data) <- ~ Xcoordinate + Ycoordinate
 > proj4string(Data) = CRS("+proj=longlat +datum=WGS84")
 > library(spacetime)
 > Data.ST <- STIDF(Data, Data$Date, data.frame(Data$ID))
 > library(plotKML)
 > Data.ST.10 <- Data.ST[1:10]
 > plotKML(Data.ST.10, points_names=Data.ST.10$Data.ID, 
colour_scale=rep("#FFFF00", 2))

HTH

T. Hengl
http://www.wewur.wur.nl/popups/vcard.aspx?id=HENGL001

>
> -----Original Message-----
> From: Tomislav Hengl [mailto:hengl at spatial-analyst.net]
> Sent: Friday, October 12, 2012 3:49 AM
> To: Struve,Juliane
> Subject: Re: [R-sig-Geo] question about plotKML() - Google Earth
>
>
> No. Please better use "hengl at spatial-analyst.net" (and please do not
> send big files etc).
>
> I plan to work on plotKML next week Monday/Tuesday.
>
> On 11/10/2012 14:23, Struve,Juliane wrote:
>> Good morning,
>>
>> Did you receive the files that I sent to your other address ?
>>
>> Thanks and best wishes,
>>
>> Juliane
>>
>> -----Original Message-----
>> From: Tomislav Hengl [mailto:hengl at spatial-analyst.net]
>> Sent: Tuesday, October 09, 2012 4:13 AM
>> To: Struve,Juliane
>> Cc: r-sig-geo at r-project.org
>> Subject: Re: [R-sig-Geo] question about plotKML() - Google Earth
>>
>>
>> On 08/10/2012 22:11, Struve,Juliane wrote:
>>> Dear list members,
>>>
>>> I am using plotKML() to plot some animal tracks on Google Earth. The
>>> attribute data that I am using are individual IDs, which consist of 4
>>> figures, e.g. 1145. In the STDIF object that I create these data
>>> appear correct in the "data" slot. However, in the plot on Google
>>> Earth the numbers are rounded, 1145 e.g. becomes 1150.
>>>
>>> Does anyone know what causes this/how to prevent it ?
>>>
>>> Thanks a lot for your time,
>>>
>>> Juliane
>>
>> I need to see your code and the KML file. Please send it outside the
>> R-sig-geo and I will try to fix.
>>
>> The original function is at:
>>
>> https://r-forge.r-project.org/scm/viewvc.php/pkg/R/layer.STTDF.R?view=markup&root=plotkml
>>
>> thanks for your e-mail,
>>
>> T. Hengl
>> http://www.wewur.wur.nl/popups/vcard.aspx?id=HENGL001
>>
>>>
>>> [[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
>>>



More information about the R-sig-Geo mailing list