2

注: Edzer Pebesma の提案により、この質問は R-sig-geo (こちら) にクロスポストされ、いくつかの良い反応がありました。


を使用すると、次の予期しない結果が発生しました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")

ここで厄介な副作用の 1 つは、元のオブジェクトwrld_simplも変更されることです。この結果は私にはバグのように見えますか、それとも何か見逃していますか?

shape_with_holePS: 以前に編集されたオブジェクトcheckPolygonsHolesは、引き続き奇妙な動作をします:

# 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
4

1 に答える 1