sjoin 'contains'/'within' 似乎返回了一堆不正确的行
sjoin 'contains'/'within' seems to be returning a bunch of incorrect rows
我试图通过使用 geopandas 连接来找出一堆 lat/lon 点中的哪些点落在海洋的某个区域内。但我发现的是,如果我使用 'within' 或等效的 'contains' 的 sjoin - 我最终会得到这组奇怪的点,这些点都受感兴趣的区域,但经度在整个范围内。
代码如下:
pmnm # this is the region of the ocean I'm interested in
geopoints # this is the set of all points
# sjoin to find geopoints that are "within" pmnm
pmnm_points = geopandas.sjoin(geopoints, pmnm, op='within', how='inner')
但是它给了我太多的点 - 我感兴趣的区域是红色的,所有应该在它“内部”的点都是蓝色的:
如果我使用 'intersects' 连接,即:
pmnm_points = geopandas.sjoin(geopoints, pmnm, op='intersects', how='inner')
然后我只得到以下 723 个实际应该在的位置:
现在是真正奇怪的部分。如果我采用更大的一组点(似乎都受区域纬度的限制,但不是实际轮廓)并且基本上 手动 检查它们是否 contained/within, 我只得到了我认为无论如何应该出现的723分:
num_contained = 0
for i in range(pmnm_points.shape[0]):
if pmnm.contains(pmnm_points.iloc[i]['geometry']).iloc[0]:
num_contained += 1
print(num_contained)
# prints 723 -- the correct number! what the heck!
所以我的问题是:为什么这些不在“区域内”的点仍然在 sjoin 操作中被拾取?我做错了什么?
好吧,看起来这实际上可能是 pygeos 中的一个问题。我卸载了 pygeos,常规的 geopandas 能够 运行 正确连接。
我试图通过使用 geopandas 连接来找出一堆 lat/lon 点中的哪些点落在海洋的某个区域内。但我发现的是,如果我使用 'within' 或等效的 'contains' 的 sjoin - 我最终会得到这组奇怪的点,这些点都受感兴趣的区域,但经度在整个范围内。
代码如下:
pmnm # this is the region of the ocean I'm interested in
geopoints # this is the set of all points
# sjoin to find geopoints that are "within" pmnm
pmnm_points = geopandas.sjoin(geopoints, pmnm, op='within', how='inner')
但是它给了我太多的点 - 我感兴趣的区域是红色的,所有应该在它“内部”的点都是蓝色的:
如果我使用 'intersects' 连接,即:
pmnm_points = geopandas.sjoin(geopoints, pmnm, op='intersects', how='inner')
然后我只得到以下 723 个实际应该在的位置:
现在是真正奇怪的部分。如果我采用更大的一组点(似乎都受区域纬度的限制,但不是实际轮廓)并且基本上 手动 检查它们是否 contained/within, 我只得到了我认为无论如何应该出现的723分:
num_contained = 0
for i in range(pmnm_points.shape[0]):
if pmnm.contains(pmnm_points.iloc[i]['geometry']).iloc[0]:
num_contained += 1
print(num_contained)
# prints 723 -- the correct number! what the heck!
所以我的问题是:为什么这些不在“区域内”的点仍然在 sjoin 操作中被拾取?我做错了什么?
好吧,看起来这实际上可能是 pygeos 中的一个问题。我卸载了 pygeos,常规的 geopandas 能够 运行 正确连接。