[R-sig-Geo] Marginless plot output for georegistration of output graphics

David Forrest drf5n at maplepark.com
Wed Jan 17 17:40:16 CET 2007


On Wed, 17 Jan 2007, Roger Bivand wrote:
>
> Although the output PNG looks nice with "+proj=longlat"-induced vertical
> stretch, I think the CRS should be reset to as.character(NA) to keep the
> original geographical coordinates aspect ratio (maybe this doesn't
> matter, the PNGs insert alike in GE).

For the quakes data example, I assigned a CRS to make use of mapasp() to 
set the png() device sizes, otherwise it thinks the lat/long is "iso"  GE 
does do a vertical stretch.  Here's an example on the NC data.

library(maptools)
xx <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1],
IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
xx.p<-spplot(xx,'AREA',
        par.settings=theme.novpadding, # lattice theme from prior
        scales=list(axs='i',draw=FALSE),
        xlim=bbox(xx)[1,],ylim=bbox(xx)[2,])

tf2<-tempfile()

mywidth<-myheight<-600
if(mapasp(xx)>1)  mywidth<-myheight  /mapasp(xx)
if(mapasp(xx)<1)  myheight <-mywidth *mapasp(xx)
myheight<-myheight*(1-.045)  # key size hack

png(file=tf2,width=mywidth,height=myheight,bg='transparent')
print(xx.p)
dev.off()
system(paste("display", tf2))

I feel really close with this, except for the key.

> Getting the background transparent is an open issue, bg="transparent" in
> xfig() doesn't help, but there is a -g color argument to fig2dev, which
> needs investigation.
>
> Roger
>
>>
>> If anyone has lots of time to spare, a SpatialGridDataFrame device with
>> red, green, blue and alpha channels would be nice (or a GDAL MEM device,
>> or whatever).
>>
>> Roger
>>
>>>
>>> Dave
>>>
>>
>>
>
>

-- 
  Dr. David Forrest
  drf at vims.edu                                    (804)684-7900w
  drf5n at maplepark.com                             (804)642-0662h
                                    http://maplepark.com/~drf5n/




More information about the R-sig-Geo mailing list