[R-sig-Geo] png() and pdf() alignment problems

Roland Kaiser roland.kaiser at sbg.ac.at
Fri Feb 1 00:19:03 CET 2008


Hi all!

My aim is to print a thematic map containing
vector output and an image backdrop (six orthophoto tiles).
The size of one image tile is 2500 rows and 2500 columns.
The are six tiles to be printed.

Of course this is far to much for sending the job to a pdf() device.
The raster image would consist of 37500000 squares,
each representing a raster cell.

So my a attempt was to separate vector and image output,
and overlay it afterwards.

Doing so I found that png() and pdf() do not register corectly.

The following script shows that a custom device size (not square)
can be responsible for the missing preccesion.

require(grDevices)
x <- y <- seq(-4*pi, 4*pi, len=27)
r <- sqrt(outer(x^2, y^2, "+"))
z <- cos(r^2)*exp(-r/6), col=gray((0:32)/32)

# example1
# standard device size
pdf("pdf_fit.pdf")
image(z)
dev.off()
png("png_fit.png", res = 96)
image(z)
dev.off()

# both files overlay with high precision
# as known from R grtaphics output
# see attached example example1.pdf

# example2
# custom device size
pdf("pdf.pdf", width = 8, height = 4)
image(z)
dev.off()
png("png.png", width = 8, height = 4, units = "in", res = 96)
image(z)
dev.off()

# png output is somewhat larger
# and aligning them is a bit nasty
# see attached example example2.pdf

I attached the two files
showing the overlay of the examples above.

Is there anything I'm missing?

Thanks for any advice,

Roland
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example1.pdf
Type: application/pdf
Size: 65735 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20080201/4a7928d7/attachment.pdf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example2.pdf
Type: application/pdf
Size: 56994 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20080201/4a7928d7/attachment-0001.pdf>


More information about the R-sig-Geo mailing list