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")

这里一个恼人的副作用是原始对象wrld_simpl也被改变了。这个结果在我看来就像一个错误,还是我错过了什么?

PS:之前shape_with_hole编辑的对象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

1

这份清晰的报告揭示了 R 包 sp 中的一个错误,该错误仅在 R 3.1.x 中出现,更多详细信息请参见此处sp可从 CRAN 获得的 1.1-0 已解决此问题。

于 2015-04-10T14:48:27.633 回答