0

I would like to select polygons that contain at least a point. I can use QGIS's tool called "Select by location: Select all buildings by location of point".

Is there a python alternative?

So far, I wrote a jupyter notebook and worked with GeoPandas.

I have tried

import geopandas as gpd
import pandas as pd

polygon_layer = gpd.read_file(r'file.shp') 
excel = pd.read_excel('file2.xlsx')

points_layer = gpd.GeoDataFrame(excel, geometry=gpd.points_from_xy(excel.X, excel.Y))

subset = gpd.sjoin(polygon_layer, points_layer, how='inner', predicate='within')

However, the spatial join does not work as it returns an empty geoDataFrame

Edo Grm
  • 13
  • 4

0 Answers0