怎么样gTouches
?gIntersects
_rgeos
library(rgeos)
library(maptools)
wc <- subset(wrld_simpl, NAME == "China")
world <- subset(wrld_simpl, !NAME == "China")
创建一个向量来存储测试:
tst <- logical(nrow(world))
做测试:
for (i in 1:nrow(world)) {
tst[i] <- gTouches(wc, world[i,])
}
查看结果:
levels(world$NAME)[world$NAME[tst]]
[1] "India" "Russia"
plot(wc)
plot(world[tst, ], add = TRUE, col = "grey")
(不会就世界事务进行进一步的通信,但 gIntersects 似乎给出了更好的答案)。
我强烈建议您谨慎对待这些内置数据集,如果您要将此类工具用于任何重要目的,您当然需要获得可靠的数据。几何和数据已经够棘手了。:)
for (i in 1:nrow(world)) {
tst[i] <- gIntersects(wc, world[i,])
}
length(levels(world$NAME)[world$NAME[tst]])
[1] 14
plot(world[tst, ], col = "firebrick")
plot(wc, add = TRUE, col = "grey")