[R-sig-Geo] Reducing the size of the R-produced maps while saving
Roger Bivand
Roger.Bivand at nhh.no
Fri Feb 3 20:25:43 CET 2012
On Fri, 3 Feb 2012, Karl Ove Hufthammer wrote:
> Roger Bivand wrote:
>
>>> However, once the map is saved, I am getting a huge .emf file (e.g., 74
>>> MB). Is there any way to save it in a smaller size?
>>
>> If you have to use a vector output format, then you should simplify the
>> input, which has extremely detailed coastlines but coarser resolution
>> administrative boundaries. Maybe try gSimplify() in rgeos.
>
> 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? On F16 x86 I see:
> library(maptools)
> data(wrld_simpl)
> pdf("wrld_simpl_base.pdf")
> plot(wrld_simpl)
> dev.off()
> file.info("wrld_simpl_base.pdf")[1]
size
wrld_simpl_base.pdf 141093
> pdf("wrld_simpl_nor.pdf")
> plot(wrld_simpl, xlim=c(3,31), ylim=c(58,71))
> dev.off()
> file.info("wrld_simpl_nor.pdf")[1]
size
wrld_simpl_nor.pdf 13222
So something is being clipped, isn't it? If there is more that can be
done, a use case would be needed to show when we had reduced the file
size. In this case, converting the output object to SpatialLines makes
little difference.
Interested in your issue,
Roger
>
> The best solution is to crop the map object before saving. Note that for
> detailed map objects, this can be a *very* slow process. And the polygons
> are actually closed, so you will see black horizontal or vertical lines in
> the margin. I guess you could could crop the map to slightly outside the
> xlim and ylim boundaries before saving it to avoid this last problem.
>
> --
> Karl Ove Hufthammer
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
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