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

Roger Bivand Roger.Bivand at nhh.no
Thu Jan 29 13:08:12 CET 2009


On Thu, 29 Jan 2009, Hans-Jörg Bibiko wrote:

>
> 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?

Set the pbg= argument to set the "bg" (background) to something other than 
"transparent" - if it is transparent, the previously plotted larger and 
encompassing polygon is still visible. I'm afraid that the documentation, 
which should be in ?"SpatialPolygons-class" where the plot method is 
described, is in the maptools package, in ?plot.polylist - this will be 
fixed.

Roger



>
>
> 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"
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, 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