[R-sig-Geo] bad position of png & klm file in google earth
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Fri Oct 24 12:59:18 CEST 2008
2008/10/24 Marta Rufino <mrufino at cripsul.ipimar.pt>:
> 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=""))
When I do this, I get the following in my KML file:
<LatLonBox><north>-10.72</north><south>-38.59</south><east>188.158103454744</east><west>165.67</west></LatLonBox>
which corresponds (near enough) to the bounding box of the data:
> bbox(qk)
min max
long 165.67 188.13
lat -38.59 -10.72
Does the KML for your data have the right LatLonBox coords?
> 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?
You'll need to edit the KML file, and do a search-and-replace. Or if
you want to be really smart, since the KML format is an XML format,
you could write an XSLT file to do the transformation. XSLT is another
XML format for doing transformations on XML files. Personally, I think
life is too short to do everything in XML, and it is probably quicker
to load it into your favourite editor and do a search-and-replace!
If you need to do it in a program, you could read the XML into R with
the R XML tools, and then tweak it....
Barry
More information about the R-sig-Geo
mailing list