包含面的空间点的子集 [英] Subset spatial points with a polygon
本文介绍了包含面的空间点的子集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用
选择位于多边形内的点fall.within.poly <- spointdf[spolydf,]
如何选择位于多边形外的点?已尝试
fall.outside.poly <- spointdf[-spolydf,]
但不起作用。我错过了一件简单的事情--请帮忙。
推荐答案
有点晚了,但我今天遇到了同样的问题,所以我想我应该使用rgeos
包中的gDifference()
发布我的解决方案:
require(rgeos)
require(sp)
##create spdf
coords=expand.grid(seq(150,151,0.1),seq(-31,-30,0.1))
spdf=data.frame("lng"=coords[,1],"lat"=coords[,2])
coordinates(spdf) = ~lng+lat
proj4string(spdf)<- CRS("+init=epsg:4326")
plot(spdf)
##create poly
poly1 = SpatialPolygons(list(Polygons(list(Polygon(cbind(c(150.45,150.45,150.75,150.75,150.45),c(-30.75,-30.45,-30.45,-30.75,-30.75)))),ID=1)))
proj4string(poly1)<- CRS("+init=epsg:4326")
lines(poly1)
##get difference
out = gDifference(spdf,poly1)
points(out,col="red",pch=16)
这篇关于包含面的空间点的子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文