[R-sig-Geo] bad position of png & klm file in google earth

Tomislav Hengl T.Hengl at uva.nl
Fri Oct 24 12:26:16 CEST 2008


Dear Marta,

I am not sure what is the projection system you use for the Algarve case study? If it is different
from CRS("+proj=longlat +datum=WGS84"), then you do need to first reproject your maps.

You should really look at the examples from the book by Bivand et al.:
http://www.asdar-book.org/code.php?chapter=3&figure=1
http://www.asdar-book.org/code.php?chapter=3&figure=2 

Here you will find small examples of how to export any raster map to GE (it reprojects a map using
the MapResample method of ILWIS GIS):
http://geomorphometry.org/R.asp 

I personally do not use much the maptools to generate GE KMLs, but instead write directly a KML file
from R e.g. to export a time-series of interpolated temperature images to KML in a loop:

> filename = "croclim12.kml"
> write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", filename)
> write("<kml xmlns=\"http://earth.google.com/kml/2.2\">", filename, append = TRUE)
> write("<Folder>", filename, append = TRUE)
> write("\t<name>Mean Daily TEMP</name>", filename, append = TRUE)
> write("\t<open>1</open>", filename, append = TRUE)
> for (i in slices) {
 slice = floor(unclass(as.POSIXct(i))/86400)[[1]]
 write("\t\t<GroundOverlay>", filename, append = TRUE)
 write(paste("\t\t<name>", i, "</name>", sep = ""),
 filename, append = TRUE)
 write("\t\t<TimeSpan>", filename, append = TRUE)
 write(paste("\t\t\t<begin>", slice, "</begin>", sep = ""),
 filename, append = TRUE)
 write(paste("\t\t\t<end>", slice + 1, "</end>", sep = ""),
 filename, append = TRUE)
 write("\t\t</TimeSpan>", filename, append = TRUE)
 write("\t\t<color>99ffffff</color>", filename, append = TRUE)
 write("\t\t<Icon>", filename, append = TRUE)
 write(paste("\t\t\t<href>", getwd(), "/MDTEMP", slice, ".png</href>", sep = ""), filename, append =
TRUE)
 write("\t\t\t<viewBoundScale>0.75</viewBoundScale>",
 filename, append = TRUE)
 write("\t\t</Icon>", filename, append = TRUE)
 write("\t\t<altitude>50</altitude>", filename, append = TRUE)
 write("\t\t<altitudeMode>relativeToGround</altitudeMode>",
 filename, append = TRUE)
 write("\t\t<LatLonBox>", filename, append = TRUE)
 write(paste("\t\t\t<north>", grids.kml$ylim[[2]],
 "</north>", sep = ""), filename, append = TRUE)
 write(paste("\t\t\t<south>", grids.kml$ylim[[1]],
 "</south>", sep = ""), filename, append = TRUE)
 write(paste("\t\t\t<east>", grids.kml$xlim[[2]],
 "</east>", sep = ""), filename, append = TRUE)
 write(paste("\t\t\t<west>", grids.kml$xlim[[1]],
 "</west>", sep = ""), filename, append = TRUE)
 write("\t\t</LatLonBox>", filename, append = TRUE)
 write("\t</GroundOverlay>", filename, append = TRUE)
}
> write("<ScreenOverlay>", filename, append = TRUE)
> write(paste(" <name>values from", MDTEMPxlim[[1]], " to ", MDTEMPxlim[[2]], "</name>", sep = ""),
filename, append = TRUE)
> write(" <Icon>", filename, append = TRUE)
> write(paste("\t\t\t<href>", getwd(), "/legend.png</href>", sep = ""), filename, append = TRUE)
> write(" </Icon>", filename, append = TRUE)
> write(" <overlayXY x=\"0\" y=\"1\" xunits=\"fraction\" yunits=\"fraction\"/>", filename, append =
TRUE)
> write(" <screenXY x=\"0\" y=\"1\" xunits=\"fraction\" yunits=\"fraction\"/>", filename, append =
TRUE)
> write(" <rotationXY x=\"0\" y=\"0\" xunits=\"fraction\" yunits=\"fraction\"/>", filename, append =
TRUE)
> write(" <size x=\"0\" y=\"0\" xunits=\"fraction\" yunits=\"fraction\"/>", filename, append = TRUE)
> write(" </ScreenOverlay>", filename, append = TRUE)
> write("</Folder>", filename, append = TRUE)
> write("</kml>", filename, append = TRUE)


I guess you need to read the KML tutorial
(http://code.google.com/apis/kml/documentation/kml_tut.html) to find out what exactly you need to
use.
 
hth

Tom Hengl 
http://spatial-analyst.net 


-----Original Message-----
From: r-sig-geo-bounces at stat.math.ethz.ch [mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf Of
Marta Rufino
Sent: Friday, October 24, 2008 11:50 AM
To: r-sig-geo at stat.math.ethz.ch
Subject: [R-sig-Geo] bad position of png & klm file in google earth

Dear list,

I would like to start by acknowledging the wonderful work of this 
support list :-)
I have  a question, which should be prety dummy,... but I was looking 
around in the net, in reports, etc. and could not sort it out.

I am trying to export a image plot to google earth. I manage to do it 
with  points data... ok. but when I do it with the images, they simply 
go to Fiji (which I am sure it is a nice place... but a bit far from the 
Algarve, where it should be).
Even the example given in the help file, the image goes to the same 
place. What am I doing wrong?


require(maptools); require(rgdal)
# This is the example, in the file
opt_exask <- options(example.ask=FALSE)
qk <- SpatialPointsDataFrame(quakes[, c(2:1)], quakes)
proj4string(qk) <- CRS("+proj=longlat")
tf <- tempfile()
SGqk <- GE_SpatialGrid(qk)
png(file=paste(tf, ".png", sep=""), width=SGqk$width, 
height=SGqk$height, bg="transparent")
par(mar=c(0,0,0,0), xaxs="i", yaxs="i")
plot(qk, xlim=SGqk$xlim, ylim=SGqk$ylim, setParUsrBB=TRUE)
dev.off()
kmlOverlay(SGqk, paste(tf, ".kml", sep=""), paste(tf, ".png", sep=""))

# than the files produced are in
tf()

I go to the file, pick it the two of them and drag it in google earth... 
and there they are, in Fiji!!! I am sure it is silly, but it is my first 
steps in googleearth--R :-(
If I open it through google earth, it is the same...

A second doubt I have is if we can set apriori, in R the markers 
projected in google earth... how do I do if instead of the pins, I want 
a ball? Do I have to change one by one?


Thank you very much in advance,
Best wishes,
Marta

I am in windows, R 2.7.1, maptools, version 0.7-15, 2008-08-14...
GDAL 1.5.2, released 2008/05/29

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo




More information about the R-sig-Geo mailing list