[R-sig-Geo] projection of ggmap:get_map() output
Oscar Perpiñan
oscar.perpinan at upm.es
Fri Apr 25 12:13:23 CEST 2014
> On 04/24/2014 03:52 PM, Barry Rowlingson wrote:
>> So do you mean (and I've not tried your code yet, sorry) that the
>> corners may well be at the given lat-long points but half way along any
>> edge might not be at the halfway-point in lat-long?
> Indeed:
>
> library(ggmap)
> ggmap(get_map(matrix(c(-10,20,40,80),2,2)))
>
> and look at the tics along the y-axis: they're not linear, neither are
> they drawn by google (at least, they're not on the ggmapTemp.png file
> written).
>
> http://journal.r-project.org/archive/2013-1/kahle-wickham.pdf
>
> mention on p. 146 that "... the coordinate system is fixed to the
> Mercator projection."
Just as additional confirmation: inspecting the code, ggmap uses the
mercator projection for displaying the "raster":
https://github.com/dkahle/ggmap/blob/master/R/ggmap.R#L562
>> if you convert the bbox coords to epsg:3857 then maybe you have a
>> correctly projected raster in those coordinates?
> The google API wants long/lat in WGS84, and what gets returned has a
> different bbox anyway, but I believe that a long/lat aligned "box" in
> WGS84 remains a box in Mercator.
I have been playing with code to show the differences. If my code is
correct, the differences are very small, at least for the bounding box
I have chosen:
library(geosphere) ## provides a mercator function
## Bounding box: lower-left and upper-right
ll <- c(-10, 30)
ur <- c(10, 50)
## Bounding box in mercator projection
llxy <- mercator(ll)
urxy <- mercator(ur)
## Matrix of coordinates in mercator projection
xy <- expand.grid(x=seq(llxy[1], urxy[1], length=100),
y=seq(llxy[2], urxy[2], length=100))
## Matrix of lon-lat values using bounding box
lonlat <- expand.grid(x=seq(ll[1], ur[1], length=100),
y=seq(ll[2], ur[2], length=100))
## Mercator coordinates using matrix of lon-lat
xyproj <- mercator(lonlat)
## Differences between xy and xyproj
dif <- 1 - xyproj/xy
names(dif) <- paste0('dif', names(dif))
summary(dif)
library(lattice)
difXY <- cbind(xy, dif)
levelplot(difx + dify ~ x*y, data=difXY)
>> I've avoided ggmap et al because I've been unconvinced about their
>> geographic rigour vs their prettiness....
IMHO ggmap and friends are useful only when you need an easy way to
add an attractive context or "decorative" material to a graphic.
Best,
Oscar.
More information about the R-sig-Geo
mailing list