[R-sig-Geo] kml generation question

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Mon Jul 13 17:09:07 CEST 2009


On Mon, Jul 13, 2009 at 3:26 PM, Matt Oliver<moliver at udel.edu> wrote:
> Dear r-sig-geo,
>
> I am trying to generate a kml for an image I am producing using image().
> After reading about kml generation, I'm unsure if I sould be using
> kmlOverlay() or writeOGR, or some other function.
>
> This is the data
>
> http://www.ceoe.udel.edu/cms/moliver/20071003.276.0237.n17.nc
>
> require(ncdf)
> require(fields)
> f <- open.ncdf("20071003.276.0237.n17.nc")
>
> lon <- get.var.ncdf(f, "lon")
> lat <- get.var.ncdf(f, "lat")
> mcsst <- get.var.ncdf(f, "mcsst")
> plot(diff(lon)) #####notice decreasing
> par(mar=c(0, 0, 0, 0))
> par(bty="n")
>
> image(lon, lat, mcsst, col = tim.colors(64)) #####image I want to make kml
> for
>
> I don't seem to be able to make a proper "Spatial" object because of the
> unequally spaced geographic coordinates.This seems to be necessary to to
> proceed with a kml generation.
>
> I'm probably missing something simple so any help or example code would be
> wonderful
>

 KML does this kind of image overlay by taking an image file (PNG,
jpeg etc) and it's bounding box in lat-long. It can't cope with
irregular grids.

 My first thought as a workaround was to turn every pixel into a
rectangular polygon. But then I got the data and saw we were dealing
with 1445626 pixels and that google earth would probably crawl...

 So I think you'll need to resample your data onto a regular lat-long
grid, then save it as an image, and then write the relevant KML with
the bounds. The KML is quite simple:

 http://code.google.com/apis/kml/documentation/kml_tut.html#ground_overlays

 but the resampling might not be. I think I've written some resampling
code somewhere, it just works out where in the old array a bunch of
regularly spaced points are that will make the new array are, and
samples. There may be R code for doing interpolation - maybe the
rimage or RImageJ packages...

 But no, I don't think anything existing can do it [waits for Roger to
prove him wrong again...].

Barry



More information about the R-sig-Geo mailing list