[R-sig-Geo] Problem with SpatialPolygons containing a hole

Hans-Jörg Bibiko bibiko at eva.mpg.de
Thu Jan 29 12:39:32 CET 2009


Hi,

I'm just preparing a SpatialPolygonsDataFrame for ISO3 = "PSE" which  
is missing in TM_BORDERS data.

I have three polygons: p1 p2 p3 whereby p2 is a hole inside of p1.

Then I did this:

P1 <- Polygon(p1)
P2 <- Polygon(p2)
P3 <- Polygon(p3)
pse <- list(P1,P2,P3)
pseP <- checkPolygonsHoles(Polygons(pse, "PSE"))
pseSP <- SpatialPolygons(list(pseP), proj4string=CRS(proj4string(wrld)))

Fine. I can plot this correctly BUT if I execute

plot(pseSP, col="red")

then p2 (the hole) will be also filled with 'red' but as far as I  
understood it p2 shouldn't be filled.

What am I doing wrong?


Thanks for any hint in advance.

--Hans

PS I tried to set pO in SpatialPolygons but pseP has length one.

My pseSP object looks like:

 > str(pseSP)
Formal class 'SpatialPolygons' [package "sp"] with 4 slots
   ..@ polygons   :List of 1
   .. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots
   .. .. .. ..@ Polygons :List of 3
   .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
   .. .. .. .. .. .. ..@ labpt  : num [1:2] 35.3 31.8
   .. .. .. .. .. .. ..@ area   : num 0.000317
   .. .. .. .. .. .. ..@ hole   : logi TRUE
   .. .. .. .. .. .. ..@ ringDir: int -1
   .. .. .. .. .. .. ..@ coords : num [1:10, 1:2] 35.2 35.2 35.2 35.3  
35.3 ...
   .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
   .. .. .. .. .. .. ..@ labpt  : num [1:2] 35.3 31.9
   .. .. .. .. .. .. ..@ area   : num 0.562
   .. .. .. .. .. .. ..@ hole   : logi FALSE
   .. .. .. .. .. .. ..@ ringDir: int 1
   .. .. .. .. .. .. ..@ coords : num [1:105, 1:2] 35.3 35.3 35.3 35.3  
35.3 ...
   .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
   .. .. .. .. .. .. ..@ labpt  : num [1:2] 34.4 31.4
   .. .. .. .. .. .. ..@ area   : num 0.037
   .. .. .. .. .. .. ..@ hole   : logi FALSE
   .. .. .. .. .. .. ..@ ringDir: int 1
   .. .. .. .. .. .. ..@ coords : num [1:20, 1:2] 34.6 34.6 34.5 34.5  
34.5 ...
   .. .. .. ..@ plotOrder: int [1:3] 2 3 1
   .. .. .. ..@ labpt    : num [1:2] 35.3 31.9
   .. .. .. ..@ ID       : chr "PSE"
   .. .. .. ..@ area     : num 0.6
   ..@ plotOrder  : int 1
   ..@ bbox       : num [1:2, 1:2] 34.2 31.2 35.6 32.5
   .. ..- attr(*, "dimnames")=List of 2
   .. .. ..$ : chr [1:2] "r1" "r2"
   .. .. ..$ : chr [1:2] "min" "max"
   ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
   .. .. ..@ projargs: chr " +proj=longlat +ellps=WGS84 +datum=WGS84  
+no_defs +towgs84=0,0,0"




More information about the R-sig-Geo mailing list