Skip to content

Commit

Permalink
fix: attempt at simplifying
Browse files Browse the repository at this point in the history
  • Loading branch information
edelclaux committed Jul 18, 2024
1 parent 148024a commit cfad0d9
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions backend/gn_module_zh/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ def set_geom(geometry_geojson, id_zh=None):
).all()

is_intersected = False
polygon = geometry
polygon_geom = geometry
for zh in q_zh:
if zh.id_zh != id_zh:
if DB.session.scalar(select(func.ST_Intersects(polygon, zh.geom))):
if DB.session.scalar(select(func.ST_Intersects(polygon_geom, zh.geom))):
if DB.session.scalar(
select(func.ST_GeometryType(func.ST_Intersection(zh.geom, polygon, 0.1)))
select(func.ST_GeometryType(func.ST_Intersection(zh.geom, polygon_geom)))
) not in ["ST_LineString", "ST_MultiLineString"]:
is_intersected = True
if DB.session.scalar(
select(
func.ST_Contains(
zh.geom,
polygon,
polygon_geom,
)
)
):
Expand All @@ -60,17 +60,17 @@ def set_geom(geometry_geojson, id_zh=None):
if DB.session.scalar(
select(
func.ST_Contains(
polygon,
polygon_geom,
zh.geom,
)
)
):
raise BadRequest("La ZH englobe complètement une ZH existante")
# TODO: not detected if contained entirely in 2 or more ZH polygons

polygon = DB.session.scalar(select(func.ST_Difference(polygon, zh.geom)))
polygon_geom = DB.session.scalar(select(func.ST_Difference(polygon_geom, zh.geom)))

return {"polygon": polygon, "is_intersected": is_intersected}
return {"polygon": polygon_geom, "is_intersected": is_intersected}


def set_area(geom):
Expand Down

0 comments on commit cfad0d9

Please sign in to comment.