[R-sig-Geo] Polygon hole=TRUE not being preserved?

Don MacQueen macq at llnl.gov
Fri Feb 26 02:53:33 CET 2010


I'm puzzled by an apparent change of @hole from TRUE to FALSE when a 
Polygon object becomes part of a Polygons object.

Here's an example, adapted from ?overlay

r2 <- cbind(c(180042, 180545, 180553, 180314, 179955, 179142, 179437,
   179524, 179979, 180042),
   c(332373, 332026, 331426, 330889, 330683,
     331133, 331623, 332152, 332357, 332373))

r3 <- cbind( c( 179662.7, 179759.0, 180188.4, 180179.6, 179662.7),
   c(331630.3, 331270.5, 331428.4, 331674.1, 331630.3)
   )

sr2=Polygons(list(Polygon(r2)),"r2")

p3 <- Polygon(r3,hole=TRUE)
sr3=Polygons(list(p3),"r3")


Then check:

>  str(p3)
Formal class 'Polygon' [package "sp"] with 5 slots
   ..@ labpt  : num [1:2] 179930 331501
   ..@ area   : num 148546
   ..@ hole   : logi TRUE
   ..@ ringDir: int -1
   ..@ coords : num [1:5, 1:2] 179663 179759 180188 180180 179663 ...
>

Note that @hole is TRUE

>  str(sr3)
Formal class 'Polygons' [package "sp"] with 5 slots
   ..@ Polygons :List of 1
   .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
   .. .. .. ..@ labpt  : num [1:2] 179930 331501
   .. .. .. ..@ area   : num 148546
   .. .. .. ..@ hole   : logi FALSE
   .. .. .. ..@ ringDir: int 1
   .. .. .. ..@ coords : num [1:5, 1:2] 179663 180180 180188 179759 179663 ...
   ..@ plotOrder: int 1
   ..@ labpt    : num [1:2] 179930 331501
   ..@ ID       : chr "r3"
   ..@ area     : num 148546

@hole is now FALSE


This arose because when I continue with the adapted example from ?overlay:

sr=SpatialPolygons(list(sr2,sr3))
srdf=SpatialPolygonsDataFrame(sr, data.frame(i=cbind(1:2,4:3), 
row.names=c("r2","r3")))

And plot with

plot(srdf,col='red')

the red fills the entire outer polygon. I was expecting there to be a 
hole in the fill -- based on remembering this from last time I did 
this, which was *not* recent.

Am I doing something wrong?

Thanks
-Don

Session information:


Sampling[327]% R --no-save --vanilla

R version 2.10.1 (2009-12-14)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

<- cut ->


>  sessionInfo()
R version 2.10.1 (2009-12-14)
i386-apple-darwin8.11.1

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] maptools_0.7-29 lattice_0.17-26 sp_0.9-57       foreign_0.8-39

loaded via a namespace (and not attached):
[1] grid_2.10.1
Warning message:
'DESCRIPTION' file has 'Encoding' field and re-encoding is not possible


Note, finally, that although CRAN shows sp at 0.9-60, I have 
installed from three different mirrors and in all cases get 0.9-57. I 
don't know what the issue is there. I have not (yet) tried a manual 
download and install of 0.9-60.

I doubt that the warning message from sessionInfo() is relevant.


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062



More information about the R-sig-Geo mailing list