Geopandas equivalent to select by location
If poly
is a GeoDataFrame with a single geometry, extract this:
polygon = poly.geometry[0]
The, you can use the within
method to check which of the points is within the polygon:
points.within(polygon)
this returns a boolean True/False values, which can be used to filter to original dataframe:
subset = points[points.within(polygon)]
In case the polygon layer contains many polygon features, the solution can be extended, like so:
poly = gpd.read_file('C:/Users/srcha/Desktop/folder/poly.shp')
points = gpd.read_file('c:/Users/srcha/Desktop/folder/points.shp')
poly['dummy'] = 'dummy' # add dummy column to dissolve all geometries into one
geom = poly.dissolve(by='dummy').geometry[0] # take the single union geometry
subset = points[points.within(geom)]
I'm not fond of the dummy-trick, but I have no other idea how to do this using geopandas.