Skip to content

Even simpler TM_WORLD_BORDERS_SIMPLE

6 messages · Jonathan Callahan, Hans-Jörg Bibiko, Jim Burke +1 more

#
On 29.01.2009, at 16:49, Jonathan Callahan wrote:
A very quick solution would be to filter out all irrelevant small  
polygons (islands).
[to reduce the number of polygon points would lead to very unshaped  
boundaries, I mean]

What is an irrelevant polygon? My first approach is if a country  
consists of more than 2 polygons then draw only those which are  
greater than a given area let's say 0.1 .

To achieve that without recreating the entire SpatialPolygonsDataFrame  
one could simply change the plotOrder of each PolygonsList and save it.

Like that quick&dirty script:

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",]
for (i in (1:length(wrld_simpl at polygons))) {
   polyCnt <- length(wrld_simpl at polygons[[i]]@Polygons)
   if(polyCnt > 2) {
     pO <- sapply(wrld_simpl at polygons[[i]]@Polygons, function(x)  
{slot(x,'area')>0.1})
     new_pO <- pO[ wrld_simpl at polygons[[i]]@plotOrder ]
     wrld_simpl at polygons[[i]]@plotOrder <-  
wrld_simpl at polygons[[i]]@plotOrder[ new_pO ]
   }
}
save(wrld_simpl,'SIMPLEMAP.Rdata')



--Hans
#
OK I am on decaf coffee now. I reinstalled R and
all is well now.

Now Hans, below is what I get when I run your code.
Is this expected? Quick and certainly DIRTY.

 > library("maptools")
Loading required package: foreign
 > load(url("http://spatial.nhh.no/R/etc/TM_WORLD_BORDERS_SIMPL-0.2.RData"))
 > wrld_simpl <- wrld_simpl[wrld_simpl$NAME != "Antarctica",]
Warning message:
closing unused connection 3 
(gzcon(http://spatial.nhh.no/R/etc/TM_WORLD_BORDERS_SIMPL-0.2.RData))
 > for (i in (1:length(wrld_simpl at polygons))) {
+ polyCnt <- length(wrld_simpl at polygons[[i]]@Polygons)
+ if(polyCnt > 2) {
+ pO <- sapply(wrld_simpl at polygons[[i]]@Polygons, function(x) 
{slot(x,'area')>0.1})
+ new_pO <- pO[ wrld_simpl at polygons[[i]]@plotOrder ]
+ wrld_simpl at polygons[[i]]@plotOrder <- 
wrld_simpl at polygons[[i]]@plotOrder[ new_pO ]
+ }
+ }
 > save(wrld_simpl,'SIMPLEMAP.Rdata')
Error in save(wrld_simpl, "SIMPLEMAP.Rdata") :
object ?SIMPLEMAP.Rdata? not found




Thanks,
Jim Burke
Jim Burke wrote:
#
Jim Burke wrote:
How about taking a look at the help pages of the save command?
--
Edzer

  
    
#
On 30.01.2009, at 07:47, Edzer Pebesma wrote:

            
Jim, did you look at the help page?

I simply forgot to name an argument:

save(wrld_simpl,file='SIMPLEMAP.Rdata')

--Hans