I have a geo-referenced scanned Map in GeoTiff format, which I would like to load into R. My intention is to plot some vector data (points and polygons) over this map using maptools package.

Is there any way to do this in R?

I have tried the raster and rgdal packages, however they give a gridded raster file, rather than the original image. I would like to load the map as an image itself and not a gridded raster file to plot the vector data.

  • 2
    What distinction are you making between a "gridded raster file" and an "image"?
    – whuber
    Feb 12 '14 at 20:09

Assuming a 3-band RGB image:

With rgdal see ?SGDF2PCT, or with raster see ?plotRGB - both require a 3-band gridded data set, the raster pathway is simplest.

For example, note that we use brick to ensure multiple-bands are read:

x <- brick('somefile.tif')

And here's a concrete example from the manual:

b <- brick(system.file("external/rlogo.grd", package="raster"))

Now you can overplot other data, but note that there is no auto-reprojection in this process, the vector data need to share the coordinate system of the first plot to make sense:

plot(vecdata, add = TRUE)

Any more details really needs some more information from you about your data. There are fairly simple methods to plot palette images as well.

  • The brick() function did the trick. By changing the extent and projection, I was able to plot the vector data over the map. However is there any way to increase the resolution of the map. It seems to be lesser than the original one. Adjusting dim() and res() gave Error: hasValues(x) is not TRUE
    – Crops
    Feb 13 '14 at 6:36
  • Best to project the vector to the raster rather than the other way around. Plus we need details, see ?projectRaster for options (assuming you used that)
    – mdsumner
    Feb 13 '14 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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