[R-sig-Geo] projection of ggmap:get_map() output

Agustin Lobo alobolistas at gmail.com
Thu Apr 24 09:56:02 CEST 2014


(follow up of previous message, I pressed enter as if I were in the R
session and sent the message...)

On Wed, Apr 23, 2014 at 4:37 PM, Barry Rowlingson
<b.rowlingson at lancaster.ac.uk> wrote:
>  - I imagine the web services expect EPSG:4326.

What they expect, yes. But what about what we retrieve? The bbox
coordinates might be in geographic coordinates (epsg:4326) but
the actual projection of the matrix could be any other. Actually, I
think that no geographic object without CRS information should be
admitted in R.

In order to investigate this further, I've done the following:

mibb <- matrix(c(-69.88634, -48.78450, -34.05533, -18.63424),byrow=TRUE,nrow=2)
delme <- get_map(location = mibb, maptype = "hybrid", source=
"google", crop = FALSE, zoom = 5)

mgmap <- as.matrix(gmap)
vgmap <- as.vector(mgmap)
vgmaprgb <- col2rgb(vgmap)
gmapr <- matrix(vgmaprgb[1,],ncol=ncol(
mgmap),nrow=nrow(mgmap))
gmapg <- matrix(vgmaprgb[2,],ncol=ncol(mgmap),nrow=nrow(mgmap))
gmapb <- matrix(vgmaprgb[3,],ncol=ncol(mgmap),nrow=nrow(mgmap))
rgmaprgb <- brick(raster(gmapr),raster(gmapg),raster(gmapb))
projection(rgmaprgb) <- CRS("+init=epsg:4326")
extent(rgmaprgb) <- unlist(attr(gmap,which="bb"))[c(2,4,1,3)]
rgmaprgb
plotRGB(rgmaprgb)

This looks good, but when I save as GTiff
writeRaster(rgmaprgb,file="rgmaprgb",format="GTiff",overwrite=TRUE,datatype="INT1U")

and check with QGIS, there is a very significant shift versus the GM
layer that is downladed by plugin OpenLayers.

Thus I worry that my overlay using rasterVis:levelplot and ggmap:
layer could actually be wrong as well.

I'm going to test on a more local area and let you know.

Agus



More information about the R-sig-Geo mailing list