1

I have a GeoJSON file with different geometries(polygons). I'd like to find if my polygon intersects with any of the file's geometry. I am not going to paste the file here as it is a long one, but can be found here: https://flightplan.romatsa.ro/init/static/zone_restrictionate_uav.json

Here is what I have done, but it returns false when it should return true:

import geopandas
from shapely.geometry import Polygon

df = geopandas.read_file("geometries.json") 
lat_point_list = [46.384215727080694, 46.42583525049556, 46.40743997749065]
lon_point_list = [24.66499565544466, 24.699163210220682, 24.706980760567422]

polygon_geom = Polygon(zip(lat_point_list, lon_point_list))
df1 = geopandas.GeoSeries({'geometry': polygon_geom}).set_crs(4326)

for geo in df["geometry"]:
    ctr = geopandas.GeoSeries({'geometry': geo}).set_crs(4326)
    if ctr.intersects(df1)[0]:
        print(ctr)

What am I doing wrong?

2
  • 1
    Heyo Alin. Good question. It's easier for people to answer if you have a code example without a file that needs to be read since people don't have your file.
    – Davma
    Jul 1, 2022 at 7:30
  • 1
    Thank you Davma for pointing out, I attached a link to the question Jul 1, 2022 at 7:41

1 Answer 1

3

Shapely use (x,y) in the geometries and not (y,x), therefore:

polygon_geom = Polygon(zip(lon_point_list,lat_point_list))
df1 = gpd.GeoDataFrame({'geometry':[polygon_geom]})
for geo in df["geometry"]:
    if geo.intersects(df1.geometry[0]):
        print(geo)
POLYGON ((24.14861107 46.46777725, 24.63750076 46.5633316, 24.69666672 46.41916656, 24.20750046 46.32361221, 24.14861107 46.46777725))
0

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.