我一直在尝试使用geodataframe上的“intersects”功能,查看哪些点位于多边形内。但是,只有帧中的第一个特征将返回为true。我做错什么了?
from geopandas.geoseries import *
p1 = Point(.5,.5)
p2 = Point(.5,1)
p3 = Point(1,1)
g1 = GeoSeries([p1,p2,p3])
g2 = GeoSeries([p2,p3])
g = GeoSeries([Polygon([(0,0), (0,2), (2,2), (2,0)])])
g1.intersects(g) # Flags the first point as inside, even though all are.
g2.intersects(g) # The second point gets picked up as inside (but not 3rd)
使用下面的简单函数,您可以轻松检查多边形内的哪些点:
根据documentation:
你的例子不应该有用。因此,如果要测试单个多边形中的每个点,则必须执行以下操作:
输出:
或者如果要测试特定地理系列中的所有几何图形:
Geopandas依靠Shapely进行几何工作。直接使用它有时很有用(而且更容易阅读)。以下代码也适用于广告:
你也可以看看 How to deal with rounding errors in Shapely对于边界上的点可能出现的问题。
解决这个问题的一种方法似乎是获取一个特定的条目(它对我的应用程序不起作用,但可能对其他人的:
另一种方法(对我的应用程序更有用)是与第二层功能的一元并集相交:
相关问题 更多 >
编程相关推荐