Skip to content

Commit

Permalink
test(fixture): Guarantee point is inside surface
Browse files Browse the repository at this point in the history
See: https://postgis.net/docs/ST_PointOnSurface.html
"The result of ST_PointOnSurface is guaranteed to lie within polygons,
whereas the point computed by ST_Centroid may be outside."

May append for departments? Regions?
  • Loading branch information
Maxime Vergez authored and jacquesfize committed Jan 26, 2024
1 parent 0f4fa7b commit 79c0449
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions backend/geonature/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,51 @@ def synthese_sensitive_data(app, users, datasets, source):
SensitivityRule.cd_nom == sensitive_protected_cd_nom,
SensitivityRule.areas.any(LAreas.id_area == sensitive_protected_id_area),
).first()
assert sensitivity_rule is None, "Le référentiel de sensibilité ne convient pas aux tests"
sensitive_protected_area = LAreas.query.filter(
LAreas.id_area == sensitive_protected_id_area
).first()
# Get one point inside the area : the centroid (assuming the area is convex)
sensitive_protected_point = db.session.query(
func.ST_PointOnSurface(func.ST_Transform(sensitive_protected_area.geom, 4326))
).first()[0]
# Add a criteria to the sensitivity rule if needed
id_nomenclature_bio_status = None
id_type_nomenclature_bio_status = (
BibNomenclaturesTypes.query.filter(BibNomenclaturesTypes.mnemonique == "STATUT_BIO")
.one()
.id_type
)
id_nomenclature_behaviour = None
id_type_nomenclature_behaviour = (
BibNomenclaturesTypes.query.filter(BibNomenclaturesTypes.mnemonique == "OCC_COMPORTEMENT")
.one()
.id_type
)
# Get one criteria for the sensitivity rule if needed
list_criterias_for_sensitivity_rule = sensitivity_rule.criterias
if list_criterias_for_sensitivity_rule:
one_criteria_for_sensitive_rule = list_criterias_for_sensitivity_rule[0]
id_type_criteria_for_sensitive_rule = one_criteria_for_sensitive_rule.id_type
if id_type_criteria_for_sensitive_rule == id_type_nomenclature_bio_status:
id_nomenclature_bio_status = one_criteria_for_sensitive_rule.id_nomenclature
elif id_type_criteria_for_sensitive_rule == id_type_nomenclature_behaviour:
id_nomenclature_behaviour = one_criteria_for_sensitive_rule.id_nomenclature

# Retrieve a cd_nom and point that fit a protection status but no sensitivity rule
protected_not_sensitive_cd_nom, protected_not_sensitive_id_area = (
db.session.query(cte_taxa_area_with_status.c.cd_nom, cte_taxa_area_with_status.c.id_area)
.filter(
cte_taxa_area_with_status.c.cd_nom.notin_([cte_taxa_area_with_sensitivity.c.cd_nom])
)
.first()
)
protected_not_sensitive_area = LAreas.query.filter(
LAreas.id_area == protected_not_sensitive_id_area
).first()
# Get one point inside the area : the centroid (assuming the area is convex)
protected_not_sensitive_point = db.session.query(
func.ST_PointOnSurface(func.ST_Transform(protected_not_sensitive_area.geom, 4326))
).first()[0]

with db.session.begin_nested():
for name, cd_nom, point, ds, comment_description in [
Expand Down Expand Up @@ -591,7 +635,8 @@ def synthese_sensitive_data(app, users, datasets, source):

assert synthese_to_assert.id_nomenclature_sensitivity != id_nomenclature_not_sensitive, (
f"cd_nom: {synthese_to_assert.cd_nom}, id_nomenclature_bio_status: {synthese_to_assert.id_nomenclature_bio_status}, "
f"id_nomenclature_behaviour: {synthese_to_assert}.id_nomenclature_behaviour, "
f"id_nomenclature_behaviour: {synthese_to_assert.id_nomenclature_behaviour}, "
f"id_nomenclature_sensitivity: {synthese_to_assert.id_nomenclature_sensitivity}, "
f"geojson: {synthese_to_assert.the_geom_4326_geojson}"
)

Expand Down

0 comments on commit 79c0449

Please sign in to comment.