2

Note: At Edzer Pebesma's suggestion, this question has been crossposted to R-sig-geo, here, where it has received some good responses.


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@polygons <- lapply(shape_with_hole@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?

P.S.: the object shape_with_hole edited with checkPolygonsHoles before, continues to behave strange:

# we check which polygons are marked as holes. The flags are still set 
# properly, although the `plot` function didn't recognize them:
sapply(shape_with_hole@polygons[[1]]@Polygons, slot, "hole")

[1] FALSE  TRUE  TRUE  TRUE

# load library rgdal for reprojection
library(rgdal)

# reproject with `spTransform`, just for testing
shape_with_hole <- spTransform(shape_with_hole, 
CRS("+proj=longlat +ellps=WGS84 +datum=WGS84"))

# after reprojection all flags are set to FALSE 
sapply(shape_with_hole@polygons[[1]]@Polygons, slot, "hole")

[1] FALSE FALSE FALSE FALSE
Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455
Grigory
  • 21
  • 3
  • Please post this problem to r-sig-geo, so that Roger can take a look at it. – Edzer Pebesma Apr 01 '15 at 17:52
  • In step 1 wouldn't the expected result be leaving the holes white? In the second and third the holes get filled in and the shape does nto change on my machine. You will need to be more expansive about what you are getting and what your system set up is. Mine is Mac SL fork of R 3.1.2; maptools 0.8-30; sp 1.0-17; rgeos version: 0.3-8, (SVN revision 460); GEOS runtime version: 3.3.3-CAPI-1.7.4 – IRTFM Apr 01 '15 at 20:56
  • In step 1 the holes are beeing left white, which is ok and expected. But after performing checkPolygonsHoles - no more, even in the original shape, which wasn't changed (at least deliberately). R version: 3.1.1 (I had the same result on 3.1.2) and rgeos_0.3-8, maptools_0.8-30, sp_1.0-16 – Grigory Apr 01 '15 at 21:07
  • Platform: x86_64-w64-mingw32/x64 (64-bit) – Grigory Apr 01 '15 at 21:12

1 Answers1

1

This clear report has revealed a bug in R package sp, that became only manifest in R 3.1.x See here for more detail. sp 1.1-0, available from CRAN, has fixed this.

Edzer Pebesma
  • 3,814
  • 16
  • 26