On Tue, 28 Nov 2006, F.Tusell wrote:
> I have read in Paul Murrell's book R Graphics about how to use a bitmap
> as background for a plot (page 107). Also, I routinely use function
> read.shape() in package maptools to read maps in shapefile format. Now,
> I would like to overlay an aerial photograph in .jpg format and a map. I
> think I could do the alignment manually for each case, but wonder if
> there is a better, automated way. I notice that the .jpg file has a
> companion .jgw file which may be of help.
The most direct route for data with spatial coordinate reference systems
is to use classes defined in the sp package and functions in the rgdal
package to fill them. Assuming that your image and shapefile are in the
same coordinate reference system:
library(rgdal)
x <- readGDAL("image.jpg")
will read the image into a SpatialGridDataFrame x. If image.jpg is
three-band rather than single-band, the next release of rgdal will show
how to do this on the help pages of the RGB2PCT and SGDF2RBG functions.
If the *.jpw file is read correctly, summary(x) should display the
coordinate reference system among other things. Next read the shapefile
with:
y <- readOGR(".", "shapefile")
where the first argument is the directory containing the shapefile and the
second is the name of the shapefile with no extension. If the shapefile
has a coordinate reference system, summary(y) should show it. If it
doesn't have one, but you know what it is, add it in PROJ.4 notation. If x
and y differ in coordinate reference system, use the spTransform method to
transform y to the same CRS as x. Then:
image(x)
plot(y, add=TRUE)
will do what you need.
Perhaps follow-up on the R-sig-geo list?
Roger
>
> If someone has written code for such kind of alignments or can direct me
> to detailed instructions on how to go about, I would be grateful. ft.
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no