Skip to content

Commit

Permalink
fix: srid is no more hardcoded on zh creation
Browse files Browse the repository at this point in the history
  • Loading branch information
20cents committed Aug 30, 2024
1 parent 0bc9052 commit da45b72
Show file tree
Hide file tree
Showing 2 changed files with 9 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,16 @@ 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 +191,7 @@ 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
5 changes: 4 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,11 @@ 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 da45b72

Please sign in to comment.