【发布时间】:2015-06-06 07:22:23
【问题描述】:
注意:在 Edzer Pebesma 的建议下,这个问题已被交叉发布到 R-sig-geo,here,并得到了一些很好的回应。
我在使用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也被改变了。这个结果在我看来像是一个错误,还是我错过了什么?
P.S.:之前用checkPolygonsHoles编辑的对象shape_with_hole,仍然表现得很奇怪:
# 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
【问题讨论】:
-
请将此问题发布到 r-sig-geo,以便 Roger 可以查看。
-
在第 1 步中,预期的结果不会是让孔洞变白吗?在第二个和第三个中,孔被填满,我的机器上的形状没有改变。您将需要更广泛地了解您正在获得什么以及您的系统设置是什么。我的是 R 3.1.2 的 Mac SL 叉子;地图工具 0.8-30; sp 1.0-17; rgeos 版本:0.3-8,(SVN 修订版 460); GEOS 运行时版本:3.3.3-CAPI-1.7.4
-
在第 1 步中,这些孔被保持为白色,这是可以预期的。但是在执行 checkPolygonsHoles 之后 - 不再有,即使是原始形状,也没有改变(至少是故意的)。 R 版本:3.1.1(我在 3.1.2 上得到了相同的结果)和 rgeos_0.3-8、maptools_0.8-30、sp_1.0-16
-
平台:x86_64-w64-mingw32/x64(64位)
标签: r spatial polygons maptools sp