On Thu, 2 Apr 2015, Roger Bivand wrote:
On Thu, 2 Apr 2015, Edzer Pebesma wrote:
On 04/01/2015 08:03 PM, Grigory Alexandrovich wrote:
I encountered the following unexpected result using
# attach the worldmap as SpatialPolygonsDataFrame from the
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
plot(wrld_simpl[5,], col = "blue")
One irritating side effect here is that the original object
is also changed. This result looks to me like a bug, or have I
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)
No, but:
library(sp)
library(maptools)
data(wrld_simpl)
x = wrld_simpl
shape_with_hole <- wrld_simpl[5,]
pls <- slot(shape_with_hole, "polygons")
pls1 <- lapply(pls, checkPolygonsHoles, avoidGEOS = FALSE)
isTRUE(all.equal(pls, pls1))
# TRUE
gpclibPermit()
pls1 <- lapply(pls, checkPolygonsHoles, avoidGEOS = TRUE)
isTRUE(all.equal(pls, pls1))
# FALSE
where the Polygon objects are re-ordered and plotted out of order, so
the deprecated gpclib code may be broken here. However, this isn't
the problem,
The gpclib code is OK, it re-orders the Polygon objects, but the plot
order is correct. The problem is as described below.
Roger
but rather (perhaps) graphics::polypath. If it is used (by default it
is), and with the default path fill mode:
plot(x[5,], col="blue", usePolypath=TRUE, rule="winding")
does not whiten the holes. However:
plot(x[5,], col="blue", usePolypath=TRUE, rule="evenodd")
does. Using:
plot(x[5,], col="blue", pbg="white", usePolypath=FALSE)
also works by overpainting the island with the holes in white.
Please summarise the your SO thread.
By the way, in R it is unusual for changes in one object to propagate
in an unintended way to another object, and this is not happening
here. The visual impression is being driven by polypath doing
different things depending on its rule setting. Look at ?polypath for
details.
Well, this doesn't clarify, but it explains what is happeing, I hope ...
Roger
returns a difference, but TRUE if avoidGEOS = TRUE.