[R-sig-Geo] Holes in polygons disappear after performing checkPolygonsHoles from maptools

Edzer Pebesma edzer.pebesma at uni-muenster.de
Thu Apr 2 14:50:44 CEST 2015



On 04/01/2015 08:03 PM, Grigory Alexandrovich wrote:
> Hello all,
> 
> I encountered the following unexpected result using checkPolygonsHoles:
> 
> # attach the worldmap as SpatialPolygonsDataFrame from the package maptools
> library(sp)
> library(maptools)
> data(wrld_simpl)
> 
> # get a polygon with a hole
> shape_with_hole <- wrld_simpl[5,]
> 
> # plot it (hole is left white, surrounded by blue color)
> plot(shape_with_hole, col = "blue")
> 
> # perform checkPolygonsHoles
> shape_with_hole at polygons <- lapply(shape_with_hole at polygons,
> checkPolygonsHoles)
> 
> # plot again, now holes aren't recognized as such
> plot(shape_with_hole, col = "blue")
> 
> # and even the original SpatialPolygonsDataFrame object is changed !?
> plot(wrld_simpl[5,], col = "blue")
> 
> One irritating side effect here is that the original object wrld_simpl
> is also changed. This result looks to me like a bug, or have I missed
> something?
> 

It looks as if it is related to rgeos, as

avoidGEOS = FALSE
library(sp)
library(maptools)
data(wrld_simpl)
x = wrld_simpl

shape_with_hole <- wrld_simpl[5,]

if (avoidGEOS)
	gpclibPermit()
shape_with_hole at polygons <- lapply(shape_with_hole at polygons,
checkPolygonsHoles,
	avoidGEOS = avoidGEOS)

data(wrld_simpl)
all.equal(x, wrld_simpl)

returns a difference, but TRUE if avoidGEOS = TRUE.
-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi),  University of Münster,
Heisenbergstraße 2, 48149 Münster, Germany; +49 251 83 33081
Journal of Statistical Software:   http://www.jstatsoft.org/
Computers & Geosciences:   http://elsevier.com/locate/cageo/
Spatial Statistics Society http://www.spatialstatistics.info

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20150402/a4af2d3c/attachment.bin>


More information about the R-sig-Geo mailing list