3

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.

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

1 Answer 1

4

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:

library(raster)
x <- brick('somefile.tif')
plotRGB(x)

And here's a concrete example from the manual:

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

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.

2
  • 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
    Commented Feb 13, 2014 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
    Commented Feb 13, 2014 at 7:39

Your Answer

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

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