且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Python中使用Geopandas测试Point是否在Polygon/Multipolygon中?

更新时间:2023-01-02 10:11:41

包含当前在GeoPandas中以一对一的方式(而不是一对多的)工作.为此,请使用 sjoin .

contains in GeoPandas currently work on a pairwise basis 1-to-1, not 1-to-many. For this purpose, use sjoin.

points_within = gp.sjoin(gdf, US, op='within')

这将仅返回 US 中的那些点.另外,您可以过滤包含点的多边形.

That will return only those points within the US. Alternatively, you can filter polygons which contain points.

polygons_contains = gp.sjoin(US, gdf, op='contains')