diff --git a/backend/geonature/core/gn_synthese/routes.py b/backend/geonature/core/gn_synthese/routes.py index 851cd8868d..83dec1de76 100644 --- a/backend/geonature/core/gn_synthese/routes.py +++ b/backend/geonature/core/gn_synthese/routes.py @@ -145,6 +145,7 @@ def build_blurred_precise_geom_queries(filters, where_clauses: list = []): # - priority is used to prevail non blurred geom over blurred geom if the user # can access to the non blurred geom # - orderby needed to match the non blurred and the blurred observations + areas_srid = DB.session.execute(func.Find_SRID("ref_geo", "l_areas", "geom")).scalar() blurred_geom_query = SyntheseQuery( Synthese, select( @@ -166,6 +167,8 @@ def build_blurred_precise_geom_queries(filters, where_clauses: list = []): CorAreaSyntheseAlias, CorAreaSyntheseAlias.id_synthese == Synthese.id_synthese, ), + geom_column=LAreas.geom, + geom_column_srid=areas_srid, ) # Joins here are needed to retrieve the blurred geometry blurred_geom_query.add_join(LAreas, LAreas.id_area, CorAreaSyntheseAlias.id_area) diff --git a/backend/geonature/core/gn_synthese/utils/query_select_sqla.py b/backend/geonature/core/gn_synthese/utils/query_select_sqla.py index ad48d2d2fe..1a248b32af 100644 --- a/backend/geonature/core/gn_synthese/utils/query_select_sqla.py +++ b/backend/geonature/core/gn_synthese/utils/query_select_sqla.py @@ -18,6 +18,8 @@ from werkzeug.exceptions import BadRequest from shapely.geometry import shape from geoalchemy2.shape import from_shape +from pyproj import CRS, Transformer +from shapely.ops import transform from geonature.utils.env import DB from geonature.core.gn_synthese.models import ( @@ -70,6 +72,7 @@ def __init__( with_generic_table=False, query_joins=None, geom_column=None, + geom_column_srid=4326, ): self.query = query @@ -79,6 +82,7 @@ def __init__( self._already_joined_table = [] self.query_joins = query_joins self.geom_column = geom_column if geom_column is not None else model.the_geom_4326 + self.geom_column_srid = geom_column_srid if with_generic_table: model_temp = model.columns @@ -419,7 +423,15 @@ def filter_other_filters(self, user): raise BadRequest("Unsupported geoIntersection type") geo_filters = [] for feature in features: - geom_wkb = from_shape(shape(feature["geometry"]), srid=4326) + geom_4326 = shape(feature["geometry"]) + if self.geom_column_srid != 4326: + projection = Transformer.from_crs( + CRS(4326), CRS(self.geom_column_srid), always_xy=True + ) + geom_correct_srid = transform(projection.transform, geom_4326) + else: + geom_correct_srid = geom_4326 + geom_wkb = from_shape(geom_correct_srid, srid=self.geom_column_srid) # if the geom is a circle if "radius" in feature["properties"]: radius = feature["properties"]["radius"]