Skip to content

Commit

Permalink
Merge pull request #85 from naturalsolutions/fix/zh-creation-form-1
Browse files Browse the repository at this point in the history
Fix/zh creation form 1
  • Loading branch information
andriacap authored Aug 30, 2024
2 parents c8dd966 + 9d1713c commit 63736d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions backend/gn_module_zh/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,14 @@ def post_cor_lim_list(uuid_lim, criteria):

def post_cor_zh_area(polygon, id_zh, id_type):
# try:
local_srid = DB.session.execute(func.Find_SRID("ref_geo", "l_areas", "geom")).scalar()
elements = [
getattr(element, "id_area")
for element in DB.session.scalars(
select(LAreas)
.where(
LAreas.geom.ST_Intersects(
func.ST_Transform(func.ST_SetSRID(func.ST_AsText(polygon), 4326), 2154)
func.ST_Transform(func.ST_SetSRID(func.ST_AsText(polygon), 4326), local_srid)
)
)
.where(LAreas.id_type == id_type)
Expand All @@ -188,7 +189,9 @@ def post_cor_zh_area(polygon, id_zh, id_type):
if id_type == CorZhArea.get_id_type("Communes"):
municipality_geom = getattr(DB.session.get(LAreas, element), "geom")
polygon_2154 = DB.session.scalar(
select(func.ST_Transform(func.ST_SetSRID(func.ST_AsText(polygon), 4326), 2154))
select(
func.ST_Transform(func.ST_SetSRID(func.ST_AsText(polygon), 4326), local_srid)
)
)
intersect_area = DB.session.scalar(
select(func.ST_Area(func.ST_Intersection(municipality_geom, polygon_2154)))
Expand Down
3 changes: 2 additions & 1 deletion backend/gn_module_zh/model/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ def get_departments(self):
try:
departments = CorZhArea.get_departments(self.id_zh)
area = 0
local_srid = DB.session.execute(func.Find_SRID("ref_geo", "l_areas", "geom")).scalar()
my_geom = DB.session.execute(
select(func.ST_Transform(func.ST_SetSRID(TZH.geom, 4326), 2154)).where(
select(func.ST_Transform(func.ST_SetSRID(TZH.geom, 4326), local_srid)).where(
TZH.id_zh == self.id_zh
)
).scalar_one()
Expand Down

0 comments on commit 63736d2

Please sign in to comment.