5

I downloaded a 'Google Map' terrain map using dismo::gmap. The raster comes with a Mercator projection. I tried to re-project it to UTM but in doing so, all the colors are lost and the raster is not displayed the same way (add scale + coordinates). Could you explain me how to retain the original colors ?

library(dismo)
library(raster)

area  <- extent(678815, 709272, 5004393, 5028388)
proj4 <- "+proj=utm +zone=17 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"

r <- raster()
extent(r) <- area
proj4string(r) <- proj4

gm  <- gmap(x = r, type = "terrain", scale = 1)
gm2 <- projectRaster(gm, crs = proj4)


plot(gm)
plot(gm2)

the two output

1

1 Answer 1

7

I finally found the way with the option rgb = TRUE and the function plotRGB. It makes a lot of sense once you have the anwser.

library(dismo)
library(raster)

area  <- extent(678815, 709272, 5004393, 5028388)
proj4 <- "+proj=utm +zone=17 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"

r <- raster()
extent(r) <- area
proj4string(r) <- proj4

gm  <- gmap(x = r, type = "terrain", scale = 1, rgb = TRUE)
gm2 <- projectRaster(gm, crs = proj4)


plotRGB(gm)
plotRGB(gm2)
2
  • 1
    (It's primarily because the default return is a palette image, that can be unpicked as well by applying the raster values as an index into the colour table. Here's an example I've had, I use it for rgl texture mapping gist.github.com/mdsumner/7af4606fcbec6e110233b280974aba8f) Didn't know about the rgb argument, thanks!
    – mdsumner
    Sep 10, 2017 at 10:24
  • @mdsumner you should post as an answer with a bit more explanation :)
    – GISHuman
    Sep 10, 2017 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.