两只大熊猫的交集 地理系列给出警告"The indices of the two GeoSeries are different."和很少的匹配



我使用geoandas来查找点和多边形之间的交点。当我使用以下命令时:

intersection_mb = buffers_df.intersection(rest_VIC)

我得到这个输出和一个警告,基本上说没有交集:

0         None
112780    None
112781    None
112782    None
112784    None
... 
201314    None
201323    None
201403    None
201404    None
201444    None
Length: 3960, dtype: geometry

警告消息:

C:UsersNameAnaconda3libsite-packagesgeopandasbase.py:31: UserWarning: The indices of the two GeoSeries are different.
warn("The indices of the two GeoSeries are different.")

我寻找了任何建议,发现我可以通过为要执行交集的两个geoseries设置crs来解决,但它不起作用。

rest_VIC = rest_VIC.set_crs(epsg=4326, allow_override=True)
buffers_df = buffers_df.set_crs(epsg=4326, allow_override=True)
任何建议都会有帮助的。谢谢。

geopandas.GeoSeries.intersection是一个元素的操作。从交叉文档:

操作以1对1的行方式进行

有一个可选的align参数,它决定序列是否应该在基于索引对齐后首先进行比较(如果为True,默认值),或者是否应该基于位置逐行执行相交操作。

所以你得到的警告,以及产生的nan,是因为你正在对索引不匹配的数据执行元素比较。当试图合并索引未对齐的dataframe的列时,在pandas中也会出现同样的问题。

如果你试图找到从点到多边形的映射横跨两个数据框的所有行组合,你正在寻找一个空间连接,这可以用geopandas.sjoin完成:

intersection_mb = geopandas.sjoin(
buffers_df,
rest_VIC,
how='outer',
predicate='intersects',
)

有关更多信息,请参阅geoandas合并数据指南。

相关内容

最新更新