Skip to content

Commit

Permalink
blurred_geom_query: filter on blurred geom
Browse files Browse the repository at this point in the history
Thus, use blurred geom (area geom) srid instead of 4326,
waiting for PnX-SI/RefGeo#6
  • Loading branch information
bouttier committed Sep 7, 2023
1 parent 44cdc69 commit c7d3cd4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions backend/geonature/core/gn_synthese/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion backend/geonature/core/gn_synthese/utils/query_select_sqla.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -70,6 +72,7 @@ def __init__(
with_generic_table=False,
query_joins=None,
geom_column=None,
geom_column_srid=4326,
):
self.query = query

Expand All @@ -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
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit c7d3cd4

Please sign in to comment.