Search code examples
rpnggdalrgooglemaps

how to convert RgoogleMaps PNG to SpatialGridDataFrame in R?


I have derived a 'static map' using the GetMap() function from the RgoogleMaps package. I can save it (MyMap) to my harddrive as a PNG. However, then it looses the spatial reference.

Has anybody succeeded in creating a spatial object (in the sense of a GDAL-readable data format) from such a PNG?


Solution

  • Get your RGoogleMaps object as MyMap. Make it download the tile to MyTile1.png Use the raster package.

    bb = MyMap$BBOX
    t = stack("MyTile.png")
    extent(t)=extent(bb$ll[,2],bb$ur[,2],bb$ll[,1],bb$ur[,1])
    

    Now t is a raster stack. Do plotRGB(t) and you should see it. Now you can try writeRaster to create a GDAL data source. GeoTIFF perhaps?

    And watch out for that pesky Google image usage agreement...