[R-sig-Geo] RE : problem exporting map including both google map image and shape polygon

Bastien.Ferland-Raymond at mrnf.gouv.qc.ca Bastien.Ferland-Raymond at mrnf.gouv.qc.ca
Thu Oct 27 16:27:04 CEST 2011


Hello all,

Thank for the quick answer,

I feel a little bad, the answer was pretty simple, I had to change :

png(filename = "map.png",width=500, height=640 )

with

png(filename = "map.png",width=500, height=640, bg ="transparent")

It's pretty easy and was written in the help file...  Even if I red it multiple time, I skimmed this part.

Sorry and thanks for your help

Bastien


-----Message d'origine-----
De : Kemp, Michael [mailto:M.U.Kemp at uva.nl]
Envoyé : 27 octobre 2011 09:53
À : Ferland-Raymond, Bastien (DIF); r-sig-geo at r-project.org
Objet : RE: [R-sig-Geo] problem exporting map including both google map image and shape polygon

Hello Bastien,

See ?png to produce png output automatically.

Kind regards,
Michael

-----Original Message-----
From: r-sig-geo-bounces at r-project.org [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Bastien.Ferland-Raymond at mrnf.gouv.qc.ca
Sent: Thursday, October 27, 2011 3:45 PM
To: r-sig-geo at r-project.org
Subject: [R-sig-Geo] problem exporting map including both google map image and shape polygon


Dear R list,

I have a problem I've been working on for a while now and I'll try to explain it clearly.  It's highly visual and it would be easier to just import images, however I'm not sure I can do that on the list so I'll try to explain it well.

Here is what I'm trying to do:
1) import a satellite image from google map,
2) Put field station locations on the map,
3) Draw a polygon shape around the territory studied,
4) Automatically export the image as a (preferably) png file.

Point 4 is where my problem is.  I succeed at doing a pretty nice image using:

###
range<-qbbox(donn2$X$LATITUDE,donn2$X$LONGITUDE)
mamap<-GetMap.bbox(range$lonR,range$latR,destfile="mamap.png",maptype="satellite", size=c(500,640))
windows(width=6,height=7.68)
PlotOnStaticMap(mamap,lat=donn2$X$LATITUDE,lon=donn2$X$LONGITUDE,pch=21,col=1,bg="white",cex=1.3)

nc2 <- readShapePoly("shape/contour_carto06152.shp")
par(new=TRUE)
plot(nc2,border="blue",lwd=3)
###

I can then save this image directly in the menu : file -> save as -> png.  Which does work.  However, it's not automatic.

So I tried this way (line 3 and 9 are changed):

###
###
range<-qbbox(donn2$X$LATITUDE,donn2$X$LONGITUDE)
mamap<-GetMap.bbox(range$lonR,range$latR,destfile="mamap.png",maptype="satellite", size=c(500,640))
png(filename = "map.png",width=500, height=640 )
PlotOnStaticMap(mamap,lat=donn2$X$LATITUDE,lon=donn2$X$LONGITUDE,pch=21,col=1,bg="white",cex=1.3)

nc2 <- readShapePoly("shape/contour_carto06152.shp")
par(new=TRUE)
plot(nc2,border="blue",lwd=3)
dev.off()
###

It does save an image in my directory, however the image includes only the shape file (the territory polygon) and not the satellite image and field station location behind it.  Any idea why?

Another interesting point is that I had to use the option --  par(new=TRUE)  -- to get both the shape and the picture on the same plot.  Using the option  -- add=TRUE  --  like it is done in most example available on the internet didn't work for me (with plot(nc2,border="blue",lwd=3, add=TRUE)).  It didn't display any error message, but simply didn't had the polygon to the image.  I have a feeling the par(new=TRUE) statement is the problem.


I'm using R 2.11.0 on windows XP.


Any help would be appreciated.
Thanks!


Bastien Ferland-Raymond, M.Sc. Stat., M.Sc. Biol.
Division des orientations et projets spéciaux
Direction des inventaires forestiers
Ministère des Ressources naturelles et de la Faune
880, chemin Sainte-Foy, 5e étage
Québec (Québec) G1S 4X4

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list