确定地geopandas点是否在带有孔的通用多边形中

发布于 2025-01-29 16:50:39 字数 741 浏览 1 评论 0原文

此线程在这里提供了一个解决方案,说明如何确定geopandas> point在实体polygon中。

对于用孔确定Polygon的通用解决方案,即MultipolyGon

例如,使用foo下面:

from shapely.geometry import Point, Polygon
import geopandas

polys = geopandas.GeoSeries({
    'foo': Polygon([(5, 5), (5, 13), (13, 13), (13, 5)],
                        [[(7, 7), (7, 11), (11, 11), (11, 7)]]),
    'bar': Polygon([(10, 10), (10, 15), (15, 15), (15, 10)]),
})

_pnts = [Point(3, 3), Point(8, 8), Point(11, 11)]
pnts = geopandas.GeoDataFrame(geometry=_pnts, index=['A', 'B', 'C'])


This thread here gave a solution of how to determine if a geopandas POINT is in a solid POLYGON.

What would be a generic solution to determine this for a POLYGON with holes, i.e. MULTIPOLYGON.

For e.g., using foo below:

from shapely.geometry import Point, Polygon
import geopandas

polys = geopandas.GeoSeries({
    'foo': Polygon([(5, 5), (5, 13), (13, 13), (13, 5)],
                        [[(7, 7), (7, 11), (11, 11), (11, 7)]]),
    'bar': Polygon([(10, 10), (10, 15), (15, 15), (15, 10)]),
})

_pnts = [Point(3, 3), Point(8, 8), Point(11, 11)]
pnts = geopandas.GeoDataFrame(geometry=_pnts, index=['A', 'B', 'C'])


如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嗼ふ静 2025-02-05 16:50:39

严格来说,您提供的样品是多边形。几何包含一个孔。

测试非常简单,只需使用 convex_hull 即可。下面的代码进行了这两个测试。

pnts.assign(
    **{
        **{key: pnts.within(geom) for key, geom in polys.items()},
        **{key+"_filled": pnts.within(geom.convex_hull) for key, geom in polys.items()},
    }
)
几何foobarfoo_foodbar_fild
a点(3 3)falseFalseFalsetrue
B点(8 8)falsefalsefalsefalse
fpoint(11 11)false true true truefalsetrue true truetruetrue

Strictly the sample you have provided are polygons. Geometry contains a hole.

It's pretty straight forward to test, just use convex_hull. Code below does both tests.

pnts.assign(
    **{
        **{key: pnts.within(geom) for key, geom in polys.items()},
        **{key+"_filled": pnts.within(geom.convex_hull) for key, geom in polys.items()},
    }
)
geometryfoobarfoo_filledbar_filled
APOINT (3 3)FalseFalseFalseFalse
BPOINT (8 8)FalseFalseTrueFalse
CPOINT (11 11)FalseTrueTrueTrue
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文