1

I have two GeoDataframes : one has polygons, the other points.

df_points

x   y   z   geometry
0   1844035.96  5172079.80  172.74  POINT (1844035.960 5172079.800)
1   1844036.48  5172079.77  172.78  POINT (1844036.480 5172079.770)
2   1844036.94  5172079.74  172.93  POINT (1844036.940 5172079.740)
3   1844037.39  5172079.71  173.12  POINT (1844037.390 5172079.710)
4   1844037.88  5172079.68  173.18  POINT (1844037.880 5172079.680)
... ... ... ... ...
df_poly

    commune name    type    created updated geometry
0   69001   None    01  2003-12-12  2018-04-23  POLYGON ((1810135.020 5183850.517, 1810133.653...
1   69001   None    01  2003-12-12  2018-04-23  POLYGON ((1810337.438 5183826.746, 1810328.829...
2   69001   None    01  2003-12-31  2018-04-23  POLYGON ((1810620.774 5183915.964, 1810632.762...
3   69001   None    01  2003-12-12  2018-04-23  POLYGON ((1809572.945 5184941.853, 1809580.233...
4   69001   None    01  2003-12-12  2018-04-23  POLYGON ((1809564.855 5184931.139, 1809558.822...
... ... ... ... ...

Both are in CRS EPSG:3946.

To get the points contained in each polygon, I do

gpd.sjoin(df_points, df_poly, op = 'within')

Initially, the above function returned an empty dataframe, but that's because I had an issue in my polygon dataset that resulted in no mapping. Consequently, my problem is solved.

0

1 Answer 1

5

You need to specify the how parameter which is "inner" by default (see docu here). "inner" keeps only the left geometries once the condition ("within") is True for both datasets which is not the case (the polygons are not within the points).

Example code (returning point geometries within polygons):

gpd.sjoin(df_points, df_poly, how = 'left', op = 'within')

Not the answer you're looking for? Browse other questions tagged or ask your own question.