0

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'])


Tristan Tran
  • 1,351
  • 1
  • 10
  • 36

1 Answers1

0

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()},
    }
)
geometry foo bar foo_filled bar_filled
A POINT (3 3) False False False False
B POINT (8 8) False False True False
C POINT (11 11) False True True True
Rob Raymond
  • 29,118
  • 3
  • 14
  • 30