[R-sig-Geo] seamless maps

Hans-Jörg Bibiko bibiko at eva.mpg.de
Fri Jan 30 16:42:32 CET 2009


Hi,

one simple possibility to draw seamless maps based on e.g.  
TM_WORLD_BORDERS_SIMPL-0.2 is to draw each polygon in question twice  
meaning first the 'normal' polygon and afterwards the transformed  
polygon by simply adding 360 to each x-value (for maps with lon from  
-180 to 540).

The following frugal example illustrates it:
< 
------------------------------------------------------------------------>
library("maptools")
load(url("http://spatial.nhh.no/R/etc/ 
TM_WORLD_BORDERS_SIMPL-0.2.RData"))

wrld_simpl <- wrld_simpl[wrld_simpl$NAME != "Antarctica",]

# Aruba is only a dummy to init the plot plus axes
plot(wrld_simpl[wrld_simpl$NAME=="Aruba",],
   xlim=c(130, 240), # which viewport
   ylim=c(-20, 90),  # should be displayed
   asp=1,
   axes=T, pbg='white')


nirvana <- sapply(wrld_simpl at polygons,
   function(x) sapply(x at Polygons,
     function(y) {
       # draw the normal polygon
       polygon(y at coords,
         col=colors()[which(wrld_simpl$ISO3==x at ID)*2+1],
         border=NA
       );
       # draw the transformed polygon (lon + 360deg)
       polygon(y at coords + rep(c(360, 0), each=dim(y at coords)[1]),
        col=colors()[which(wrld_simpl$ISO3==x at ID)*2+1],
        border=NA
       )
     }
   ))

#polygon's col setting is only for demonstration!
< 
------------------------------------------------------------------------>

or try to set the viewport to:
xlim=c(100, 435)
ylim=c(-90, 90)


etc.

--Hans




More information about the R-sig-Geo mailing list