Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

order bv and hydro areas by zh cover #102

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions backend/gn_module_zh/model/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from ref_geo.models import BibAreasTypes, LAreas
from geonature.utils.env import DB
from sqlalchemy.sql import select
from sqlalchemy.sql import select, func
from pypn_habref_api.models import Habref
from pypnnomenclature.models import TNomenclatures

Expand Down Expand Up @@ -500,8 +500,17 @@ def __get_river_basins(self):
return [
name
for name in DB.session.scalars(
select(TRiverBasin.name).where(
TRiverBasin.id_rb == CorZhRb.id_rb, CorZhRb.id_zh == self.id_zh
select(TRiverBasin.name)
.where(
TRiverBasin.id_rb == CorZhRb.id_rb,
CorZhRb.id_zh == self.id_zh,
TZH.id_zh == self.id_zh,
)
.order_by(
(
func.ST_Area(func.ST_Intersection(TZH.geom, TRiverBasin.geom))
/ func.ST_Area(TZH.geom)
).desc()
)
)
]
Expand All @@ -511,8 +520,17 @@ def __get_hydro_zones(self):
name
for name in DB.session.scalars(
select(THydroArea.name)
.where(THydroArea.id_hydro == CorZhHydro.id_hydro, CorZhHydro.id_zh == self.id_zh)
.distinct()
.where(
THydroArea.id_hydro == CorZhHydro.id_hydro,
CorZhHydro.id_zh == self.id_zh,
TZH.id_zh == self.id_zh,
)
.order_by(
(
func.ST_Area(func.ST_Intersection(TZH.geom, THydroArea.geom))
/ func.ST_Area(TZH.geom)
).desc()
)
)
]

Expand Down
13 changes: 11 additions & 2 deletions backend/gn_module_zh/model/zh_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,17 @@ def bassin_versant(self):
bassin_versant = [
name
for name in DB.session.scalars(
select(TRiverBasin.name).where(
TRiverBasin.id_rb == CorZhRb.id_rb, CorZhRb.id_zh == self.id_zh
select(TRiverBasin.name)
.where(
TRiverBasin.id_rb == CorZhRb.id_rb,
CorZhRb.id_zh == self.id_zh,
TZH.id_zh == self.id_zh,
)
.order_by(
(
func.ST_Area(func.ST_Intersection(TZH.geom, TRiverBasin.geom))
/ func.ST_Area(TZH.geom)
).desc()
)
).all()
]
Expand Down
Loading