获取GeoPandas中几何之间的相交计数 [英] Getting counts of intersections between geometries in GeoPandas
问题描述
是否可以使用GeoPandas对象获取两个几何之间的相交计数?也就是说,我要计算一个GeoDataFrame中与另一个GeoDataFrame中的每个多边形相交的多边形或线串的数量.在浏览GeoPandas文档时,我没有看到一种简便的方法,但是想在使用低级工具之前先进行检查.
Is it possible to get counts of intersections between two geometries using GeoPandas objects? That is, I want to count up the number of polygons or line strings in one GeoDataFrame that intersect with each polygon in another GeoDataFrame. I did not see an easy way of doing this while browsing the GeoPandas docs, but wanted to check before moving on to lower-level tools.
推荐答案
您要进行空间连接:geopandas.tools.sjoin()
.
You want a spatial join: geopandas.tools.sjoin()
.
在此Jupyter笔记本中有一个示例 — 空间连接部分.这会将一组点(midpoints
)计入一组多边形(bins
)中.两种几何形状均定义GeoDataFrame
.
There's an example in this Jupyter Notebook — look at the section called Spatial join. This is counting a set of points (midpoints
) into a set of polygons (bins
). Both geometries define a GeoDataFrame
.
在撰写本文时,tools.sjoin()
不在当前版本的geopandas
中.我无法在其任何分支机构中构建geopandas.tools
,但无论如何我都已对其进行了修复-打开PR .
At the time of writing, tools.sjoin()
is not in the current release of geopandas
. I couldn't get geopandas.tools
to build in any of their branches, but I fixed it — for me anyway — in my fork. My fix is an open PR.
这篇关于获取GeoPandas中几何之间的相交计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!