Here is one approach:

rgeo <- projectRaster(rr, crs="+proj=longlat +datum=WGS84")
KML(rgeo, "file.kml")

Best, Robert


On Wed, Oct 19, 2011 at 10:00 AM, Anthony Fischbach <afischbach@usgs.gov>wrote:

> In my previous post I happily handled the binary National Snow and Ice Data
> Center sea ice imagery and cast it into a GeoTiff.
> My next challenge is to wrap the GeoTiff into a kml overlay.
> Continuing the code from the previous post, I pick it up just after writing
> the raster object to the geoTiff.
>
> ...
>  rr <- writeRaster(rr, geoTiffFile)
>
> >From there I sought to use the maptools package functions
> GE_SpatialGrid and kmlOverlay to create the kml,
> but first I needed to cast my raster into a spatial points dataframe
> and project to geographic coordinates.
>
> spdf <- rasterToPoints(rr, fun=NULL, spatial=TRUE) ## cast as a spatial
> points data frame
> xyWGS84 <- project(coordinates(spdf), inv=TRUE, proj=prj) ## Project to
> WGS84 geographic
>
> But this generates an error:
>
> Traceback:
>  1: .C("project_inv", as.integer(nc), as.double(xy[, 1]), as.double(xy[,
> 2]), x = double(nc), y = double(nc), proj, NAOK = TRUE, PACKAGE = "rgdal")
>  2: project(coordinates(spdf), inv = TRUE, proj = prj)
> Error in project(coordinates(spdf), inv = TRUE, proj = prj) :
>  caught access violation - continue with care
>
> Apparently rgdal's project function is failing to invert the projection
> from
> the NSIDC projection,
> here referenced as
> prj <- CRS('+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0
> +a=6378273 +b=6356889.449 +units=m +no_defs')
>
> Any suggestions?
>
> -----
> Tony Fischbach, Wildlife Biologist
> Walrus Research Program
> Alaska Science Center
> U.S. Geological Survey
> 4210 University Drive
> Anchorage, AK 99508-4650
>
> AFischbach@usgs.gov
> http://alaska.usgs.gov/science/biology/walrus
> --
> View this message in context:
> http://r-sig-geo.2731867.n2.nabble.com/Reading-National-Snow-and-Ice-Data-Center-binary-files-tp6882737p6909541.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

