I have a GeoDataFrame of polygons (~30) and a GeoDataFrame of Points (~10k)
I\'m looking to create 30 new columns (with appropriate polygon names) in my GeoDataFrame
Not really clear what kind of data structures you actually have. Also, all your expected results are False, so that's kind of hard to check. Assuming GeoSeries and GeoDataFrames, I would do this:
from shapely.geometry import Point, Polygon
import geopandas
polys = geopandas.GeoSeries({
'foo': Polygon([(5, 5), (5, 13), (13, 13), (13, 5)]),
'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'])
pnts = pnts.assign(**{key: pnts.within(geom) for key, geom in polys.items()})
print(pnts)
And that gives me:
geometry bar foo
A POINT (3 3) False False
B POINT (8 8) False True
C POINT (11 11) True True