Skip to content

Commit

Permalink
feat(check): add valid geom check
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Narcisi committed Aug 23, 2023
1 parent c62385b commit 3180196
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
45 changes: 29 additions & 16 deletions backend/gn_module_import/checks/sql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from sqlalchemy.dialects.postgresql import array_agg, aggregate_order_by
from geoalchemy2.functions import (
ST_Transform,
ST_GeomFromWKB,
ST_IsValid,
ST_Centroid,
ST_GeomFromText,
ST_MakePoint,
Expand Down Expand Up @@ -701,6 +701,21 @@ def complete_others_geom_columns(imprt, fields):
)


def check_is_valid_geography(imprt, fields):
if "WKT" in fields:
where_clause = sa.and_(
ImportSyntheseData.src_WKT != None,
ImportSyntheseData.src_WKT != "",
sa.not_(ST_IsValid(ST_GeomFromText(ImportSyntheseData.src_WKT))),
)
report_erroneous_rows(
imprt,
error_type="INVALID_GEOMETRY",
error_column="WKT",
whereclause=where_clause,
)


def check_geography_outside(imprt, fields):
id_area = current_app.config["IMPORT"]["ID_AREA_RESTRICTION"]
where_clause = ()
Expand Down Expand Up @@ -735,24 +750,22 @@ def check_geography_outside(imprt, fields):
)

if "longitude" in fields and "latitude" in fields:
where_clause = sa.or_(
sa.and_(
sa.not_(WKT_present),
lat_long_present,
area.geom.ST_Intersects(
ST_Transform(
ST_SetSRID(
ST_MakePoint(
ImportSyntheseData.src_longitude.cast(sa.Float),
ImportSyntheseData.src_latitude.cast(sa.Float),
),
imprt.srid,
where_clause = sa.and_(
sa.not_(WKT_present),
lat_long_present,
area.geom.ST_Intersects(
ST_Transform(
ST_SetSRID(
ST_MakePoint(
ImportSyntheseData.src_longitude.cast(sa.Float),
ImportSyntheseData.src_latitude.cast(sa.Float),
),
local_srid,
imprt.srid,
),
)
== False,
local_srid,
),
)
== False,
)
report_erroneous_rows(
imprt,
Expand Down
2 changes: 2 additions & 0 deletions backend/gn_module_import/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
check_depths,
check_digital_proof_urls,
check_geography_outside,
check_is_valid_geography,
)

from geonature.core.notifications.utils import dispatch_notifications
Expand Down Expand Up @@ -104,6 +105,7 @@ def do_import_checks(self, import_id):
check_digital_proof_urls,
check_mandatory_fields,
check_geography_outside,
check_is_valid_geography,
]
with start_sentry_child(op="check.sql", description="run all checks"):
for i, check in enumerate(sql_checks):
Expand Down
1 change: 1 addition & 0 deletions backend/gn_module_import/tests/files/geom_file.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ date_min;cd_nom;nom_cite;observateurs;WKT;latitude;longitude;codecommune;codedep
2017-01-01;67111;Ablette;Toto;;44.85;6.5;;;;Valide (X/Y)
2017-01-01;67111;Ablette;Toto;POINT(6.5 44.85);44.85;6.5;;;;MULTIPLE_ATTACHMENT_TYPE_CODE
2017-01-01;67111;Ablette;Toto;;;;;;;NO-GEOM
2017-01-01;67111;Ablette;Toto;POLYGON((0 0, 1 1, 1 2, 1 1, 0 0));;;;;;INVALID_GEOMETRY
3 changes: 2 additions & 1 deletion backend/gn_module_import/tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,9 +929,10 @@ def test_import_geometry_file(self, area_restriction, prepared_import):
"Champs géométriques",
frozenset([10, 13]),
),
("GEOMETRY_OUTSIDE", "WKT", frozenset([8, 11])),
("GEOMETRY_OUTSIDE", "WKT", frozenset([8, 11, 15])),
("GEOMETRY_OUTSIDE", "longitude", frozenset([9, 12])),
("NO-GEOM", "Champs géométriques", frozenset([14])),
("INVALID_GEOMETRY", "WKT", frozenset([15])),
},
)

Expand Down
2 changes: 1 addition & 1 deletion dependencies/GeoNature
Submodule GeoNature updated 59 files
+3 −4 .github/workflows/lint.yml
+1 −1 VERSION
+1 −1 backend/dependencies/TaxHub
+1 −1 backend/dependencies/UsersHub-authentification-module
+1 −1 backend/dependencies/Utils-Flask-SQLAlchemy
+2 −2 backend/geonature/core/gn_commons/admin.py
+18 −6 backend/geonature/core/gn_commons/routes.py
+3 −1 backend/geonature/core/gn_meta/routes.py
+51 −33 backend/geonature/core/gn_permissions/admin.py
+3 −1 backend/geonature/core/gn_permissions/routes.py
+10 −0 backend/geonature/core/gn_permissions/templates/role_or_group_detail.html
+32 −3 backend/geonature/core/gn_permissions/tools.py
+54 −23 backend/geonature/core/gn_synthese/routes.py
+23 −5 backend/geonature/core/gn_synthese/utils/query_select_sqla.py
+16 −6 backend/geonature/core/users/register_post_actions.py
+7 −2 backend/geonature/core/users/routes.py
+21 −0 backend/geonature/core/users/templates/account_created.html
+4 −0 backend/geonature/core/users/templates/email_admin_validate_account.html
+22 −1 backend/geonature/migrations/versions/95acee9f0452_add_comment_notification.py
+1 −0 backend/geonature/migrations/versions/f051b88a57fd_permissions_available.py
+209 −13 backend/geonature/tests/fixtures.py
+3 −3 backend/geonature/tests/test_gn_commons.py
+1 −0 backend/geonature/tests/test_gn_meta.py
+69 −3 backend/geonature/tests/test_permissions.py
+11 −0 backend/geonature/tests/test_pr_occtax.py
+1 −1 backend/geonature/tests/test_sensitivity.py
+533 −11 backend/geonature/tests/test_synthese.py
+7 −6 backend/geonature/utils/config_schema.py
+1 −0 backend/requirements-common.in
+3 −3 backend/requirements-dependencies.in
+16 −17 backend/requirements-dev.txt
+27 −26 backend/requirements.txt
+1 −1 backend/static/css/metadata_pdf.css
+5 −2 contrib/occtax/backend/occtax/blueprint.py
+42 −0 contrib/occtax/backend/occtax/commands.py
+1 −0 contrib/occtax/backend/occtax/conf_schema_toml.py
+1 −2 contrib/occtax/backend/occtax/models.py
+1 −0 contrib/occtax/frontend/app/occtax-form/map/occtax-map.service.ts
+1 −1 contrib/occtax/frontend/app/occtax-form/occurrence/occurrence.component.ts
+3 −0 contrib/occtax/occtax_config.toml.example
+87 −9 docs/CHANGELOG.md
+33 −33 docs/admin-manual.rst
+8 −6 docs/installation.rst
+134 −8 docs/user-manual.rst
+7 −9 frontend/package-lock.json
+1 −1 frontend/package.json
+11 −9 frontend/src/app/GN2CommonModule/form/synthese-form/synthese-form.component.html
+9 −0 frontend/src/app/GN2CommonModule/map/map.component.ts
+7 −3 frontend/src/app/GN2CommonModule/map/marker/marker.component.ts
+7 −4 frontend/src/app/metadataModule/af/af-card.component.html
+8 −4 frontend/src/app/metadataModule/af/af-card.component.ts
+54 −32 frontend/src/app/metadataModule/metadata.component.html
+4 −0 frontend/src/app/metadataModule/metadata.component.ts
+3 −0 frontend/src/app/modules/login/sign-up/sign-up.component.html
+20 −8 frontend/src/app/modules/login/sign-up/sign-up.component.ts
+20 −37 frontend/src/app/syntheseModule/synthese-results/synthese-carte/synthese-carte.component.ts
+3 −1 frontend/src/app/syntheseModule/synthese.component.ts
+3 −3 install/install_all/install_all.ini
+3 −3 install/install_all/install_all.sh

0 comments on commit 3180196

Please sign in to comment.