[R-sig-Geo] Reducing the size of the R-produced maps while saving

Roger Bivand Roger.Bivand at nhh.no
Fri Feb 3 23:09:15 CET 2012


On Fri, 3 Feb 2012, Karl Ove Hufthammer wrote:

> fr. den 03. 02. 2012 klokka 20.25 (+0100) skreiv Roger Bivand:
>>> Couldn’t (part of) the problem also be that the map object contains much
>>> more information than what is displayed? I have experienced this when
>>> plotting small parts of large maps using xlim and ylim. The resulting map
>>> displayed on screen and saved in a vector format (e.g., PDF) would show just
>>> the few countries within the xlim and ylim boundaries, but the file would
>>> actually contain (for example) the entire Eurasia continent (this could be
>>> seen by opening the file in Inkscape and moving map outlines or changing the
>>> boundary box).
>>
>> Could you provide an example?
>
> I think one example is the GSHHS map (especially the non-coarse
> versions) if you *don’t* clip it to the bounding box. But when I tried
> reproducing it now, I only get an error message:
>
> $ library(maptools)
> $ x=getRgshhsMap(xlim=c(0,30), ylim=c(55,75), no.clip=TRUE)


I'll look into the issue in getRgshhsMap() later. Using the more general 
Rgshhs(), there is a small difference in size:

> library(maptools)
> x=Rgshhs(system.file("share/gshhs_c.b", package= "maptools"), 
+ xlim=c(0,30), ylim=c(55,75), no.clip=TRUE)$SP
Data are polygon data
> pdf("gshhs_noclip.pdf")
> plot(x, xlim=c(0,30), ylim=c(55,75))
> dev.off()
null device
           1
> file.info("gshhs_noclip.pdf")[1]
                  size
gshhs_noclip.pdf 9426
> x=Rgshhs(system.file("share/gshhs_c.b", package= "maptools"), 
xlim=c(0,30), ylim=c(55,75), no.clip=FALSE)$SP
Data are polygon data
Rgshhs: clipping 9 of 126 polygons ...
null polygon: [[2]]
null polygon: [[24]]
> pdf("gshhs_clip.pdf")
> plot(x, xlim=c(0,30), ylim=c(55,75))
> dev.off()
null device
           1
> file.info("gshhs_clip.pdf")[1]               size
gshhs_clip.pdf 8529

Roger


> Data are polygon data
> Data are polygon data
> Feil: TopologyException: side location conflict at -178.44555049573185
> 65.525617234053172
>
> With ‘no.clip=FALSE’, it works fine.
>
> $ sessionInfo()
> R version 2.14.1 (2011-12-22)
> Platform: x86_64-suse-linux-gnu (64-bit)
>
> locale:
> [1] LC_CTYPE=nn_NO.UTF-8       LC_NUMERIC=C               LC_TIME=nn_NO.UTF-8
> [4] LC_COLLATE=nn_NO.UTF-8     LC_MONETARY=nn_NO.UTF-8    LC_MESSAGES=nn_NO.UTF-8
> [7] LC_PAPER=C                 LC_NAME=C                  LC_ADDRESS=C
> [10] LC_TELEPHONE=C             LC_MEASUREMENT=nn_NO.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
>  [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
>  [1] rgeos_0.2-2     stringr_0.6     maptools_0.8-14 lattice_0.20-0  sp_0.9-94       foreign_0.8-48
>
> loaded via a namespace (and not attached):
>  [1] grid_2.14.1  plyr_1.7.1   tools_2.14.1
>
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
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


More information about the R-sig-Geo mailing list