Python to detect point in polygons

33 views Asked by At

First I import a shapefile

import geopandas as gpd
shapefile_path = "data/TRI_75_SIG_DI/TRI_PARI_SIG_DI/n_tri_pari_carte_inond_s_075.shp"
gdf = gpd.read_file(shapefile_path)

And it works fine.

enter image description here

Then I can display the polygons :

import folium
m = folium.Map(location=[48.8566, 2.3522], zoom_start=12)
folium.GeoJson(gdf).add_to(m)
m

And it also works

enter image description here

Now, I choose a point, and we can see that it is in the polygons:

import geopandas as gpd
from shapely.geometry import Point

point_coordinates = (2.3546, 48.8517) 
point = Point(point_coordinates)
m = folium.Map(location=[point_coordinates[1], point_coordinates[0]], zoom_start=13)
folium.Marker(
    location=[point_coordinates[1], point_coordinates[0]],
    icon=folium.Icon(color='blue'),
    popup="Point d'intérêt"
).add_to(m)
m

enter image description here

And I used the following code, that does not work because the result is empty, whereas there should be some polygons that contain this point:

gdf.geometry.contains(point)

Could you please help?

0

There are 0 answers