[R-sig-Geo] overplotting on png map tile in R

Greg Snow Greg.Snow at imail.org
Mon Mar 9 20:52:20 CET 2009


I don't know of any functions to load and display a .png file, but if you can convert it to .jpg (Imagemagick is one way) then you can read it and plot it with the rimage package.  You can then use updateusr from the TeachingDemos package to change the user coordinates to match the latitude and longitude information and add whatever you want to the graph (given that the distortion from curved earth to flat plot is small enough).

For example:

library(TeachingDemos)
library(rimage)

# file ccc.jpg from: http://terraserver-usa.com/ImageInfo.aspx?T=4&S=12&Z=12&X=531&Y=5643&W=1
tmp <- read.jpeg('ccc.jpg')
plot(tmp)

tmp2 <- locator(2) # click on ll and ur corners

latlon <- c(40.77707, -111.90064, 40.79148, -111.87239)

updateusr(tmp2, x2=latlon[ c(2,4) ], y2=latlon[ c(1,3) ] )

with(ccc, lines(Lon, Lat, col='red') )




Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-sig-geo-bounces at stat.math.ethz.ch [mailto:r-sig-geo-
> bounces at stat.math.ethz.ch] On Behalf Of Markus Loecher
> Sent: Sunday, March 08, 2009 10:33 AM
> To: r-sig-geo at stat.math.ethz.ch
> Subject: [R-sig-Geo] overplotting on png map tile in R
> 
> Dear R geo wizards,
> while I am very happy with the kmloverlay() function from the maptools
> package to create overlays from R in Google Earth, I often would like
> to perform an even simpler task.
> Given a png image with a known lat/lon bounding box, such as a map
> tile or some other geographically aligned image, I would like to
> (i)  load the image into R,
> (ii) plot the image, and
> (iii) overlay e.g. lat/lon referenced points on top of this image
> 
> The points should be plotted with respect to the coordinates of the
> image.
> 
> Is this possible at all ?
> 
> Thanks !
> 
> Markus
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list