I have two shapefiles (https://drive.google.com/drive/folders/1pbvKvhIIvhqHfcMe9g6qtsjbZ6SzZrqt?usp=sharing) - one point layer, and one polygon layer. The point layer represents customers and their location, while the polygon layers represents two boundaries. The objective is to get a table in the following format:
| customer | location 1 | location 2 |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 0 | 1 |
| 3 | 1 | 1 |
| 5 | 1 | 0 |
| 6 | 1 | 0 |
| 9 | 0 | 0 |
| 10 | 0 | 0 |
The way I've thought of doing this is to iterate through the polygons and do a sjoin with the points, then encode the categories as such:
import geopandas as gpd
points = gpd.read_file('point.shp')
polygons = gpd.read_file('polygon.shp')
for index,row in polygons.iterrows():
points = gpd.sjoin(points, row, how='left', op='intersects')
points = pd.get_dummies(points, columns=['name'])
I get this error message:
ValueError: 'right_df' should be GeoDataFrame, got <class 'pandas.core.series.Series'>
Appreciate any advice, thanks in advance!