I want to check if points layer that I have intersect with polygons layer that I have, as Boolean column in the points dataframe.
I have two GeoPandas dataframes, the first one is many points and looks like this:

>>>ID  geometry
0  12  POINT (5.0279 7.4547)
1  45  POINT (6.6539 12.139)

and the second dataframe is one layer of many different polygons that looks something like this:

>>>name     code   geometry
0  Desert   12     POLYGON ((5.52013 13.8902, 5.5265 13.892,...)
1  Water    24     POLYGON ((5.53756 13.88472, 5.5291 13.8791,...)

I'm trying to check if there is any intersection between the points layer and the regions layer. For that I have determined the crs and then used intersects :

regions=regions.to_crs({'init': 'epsg:4326'})
points=points.set_crs({'init': 'epsg:4326'})

A The script runs with the following warnings:

FutureWarning: '+init=:' syntax is deprecated. ':' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6 return _prepare_from_string(" ".join(pjargs)) /opt/conda/lib/python3.8/site-packages/geopandas/base.py:39: UserWarning: The indices of the two GeoSeries are different.
warn("The indices of the two GeoSeries are different.")

Then when I check the results the only value is False, like all th epoints do not intersect:


*I saw on QGIS that the there are points that intersect and there are points that do not so there is no way this result is true

*I have checked the dtypes - each one of my geodataframes has one column that is geometry and called geometry.

My end goal: to add new column in the points geodataframe that will tell if it intersects the regions or not.

1 Answer 1


Intersects is row-wise operation which aligns both GeoSeries and check is a geometry A in row 0 intersects geometry B in row 0. See the documentation on that: https://geopandas.readthedocs.io/en/stable/docs/reference/api/geopandas.GeoSeries.intersects.html#geopandas.GeoSeries.intersects

For check if there is any intersection, use spatial index.

import numpy as np

inp, res = regions.sindex.query_bulk(points.geometry, predicate='intersects')
points['intersects'] = np.isin(np.arange(0, len(points)), inp)

Regarding the CRS warning, just remove init part and pass it as a string.


query_bulk requires geopandas 0.8. You can check the docs - https://geopandas.readthedocs.io/en/stable/docs/reference/api/geopandas.sindex.SpatialIndex.query_bulk.html#geopandas.sindex.SpatialIndex.query_bulk

  • thank you for your answer, the problem is that even though the geometry columns are type geometry, when I try this I get error "TypeError: Got geometry of type <class 'str'>, geometry must be a shapely geometry."
    – ReutKeller
    Commented Sep 30, 2020 at 8:33
  • 1
    I ffound the problem- I had also to put ".geometry" after the points dataframe in the beackets. thank you for your answer!
    – ReutKeller
    Commented Sep 30, 2020 at 10:37
  • 1
    @hhh The code above will work even without pygeos with geopandas 0.8 Commented Nov 3, 2020 at 16:53
  • 1
    @hhh only optionally - geopandas.readthedocs.io/en/latest/getting_started/… Commented Nov 3, 2020 at 19:14
  • 1
    What does sindex do? Does the code work also without it? Is it just a speedup thing?
    – hhh
    Commented Nov 3, 2020 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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