-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #917 from opengisch/QF-3986-empty-str-geom
Handle deltas with WKT geometry as empty string instead of null
- Loading branch information
Showing
4 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
docker-app/qfieldcloud/core/migrations/0075_auto_20240323_1419.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.25 on 2024-03-23 13:19 | ||
|
||
import migrate_sql.operations | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("core", "0074_auto_20240314_1805"), | ||
] | ||
|
||
operations = [ | ||
migrate_sql.operations.AlterSQL( | ||
name="core_delta_geom_trigger_func", | ||
sql="\n CREATE OR REPLACE FUNCTION core_delta_geom_trigger_func()\n RETURNS trigger\n AS\n $$\n DECLARE\n delta_srid int;\n old_geom_wkt text;\n new_geom_wkt text;\n BEGIN\n SELECT CASE\n WHEN jsonb_extract_path_text(NEW.content, 'localLayerCrs') ~ '^EPSG:\\d{1,10}$'\n THEN\n REGEXP_REPLACE(jsonb_extract_path_text(NEW.content, 'localLayerCrs'), '\\D*', '', 'g')::int\n ELSE\n NULL\n END INTO delta_srid;\n\n old_geom_wkt := NULLIF( TRIM( jsonb_extract_path_text(NEW.content, 'old', 'geometry') ), '');\n new_geom_wkt := NULLIF( TRIM( jsonb_extract_path_text(NEW.content, 'new', 'geometry') ), '');\n\n IF delta_srid IS NOT NULL\n AND EXISTS(\n SELECT *\n FROM spatial_ref_sys\n WHERE auth_name = 'EPSG'\n AND auth_srid = delta_srid\n )\n THEN\n NEW.old_geom := ST_Transform( ST_SetSRID( ST_Force2D( ST_GeomFromText( REPLACE( old_geom_wkt, 'nan', '0' ) ) ), delta_srid ), 4326 );\n NEW.new_geom := ST_Transform( ST_SetSRID( ST_Force2D( ST_GeomFromText( REPLACE( new_geom_wkt, 'nan', '0' ) ) ), delta_srid ), 4326 );\n ELSE\n NEW.old_geom := NULL;\n NEW.new_geom := NULL;\n END IF;\n\n IF ST_GeometryType(NEW.old_geom) IN ('ST_CircularString', 'ST_CompoundCurve', 'ST_CurvePolygon', 'ST_MultiCurve', 'ST_MultiSurface')\n THEN\n NEW.old_geom := ST_CurveToLine(NEW.old_geom);\n END IF;\n\n IF ST_GeometryType(NEW.new_geom) IN ('ST_CircularString', 'ST_CompoundCurve', 'ST_CurvePolygon', 'ST_MultiCurve', 'ST_MultiSurface')\n THEN\n NEW.new_geom := ST_CurveToLine(NEW.new_geom);\n END IF;\n\n RETURN NEW;\n END;\n $$\n LANGUAGE PLPGSQL\n ", | ||
reverse_sql="\n CREATE OR REPLACE FUNCTION core_delta_geom_trigger_func()\n RETURNS trigger\n AS\n $$\n DECLARE\n srid int;\n BEGIN\n SELECT CASE\n WHEN jsonb_extract_path_text(NEW.content, 'localLayerCrs') ~ '^EPSG:\\d{1,10}$'\n THEN\n REGEXP_REPLACE(jsonb_extract_path_text(NEW.content, 'localLayerCrs'), '\\D*', '', 'g')::int\n ELSE\n NULL\n END INTO srid;\n NEW.old_geom := ST_Transform( ST_SetSRID( ST_Force2D( ST_GeomFromText( REPLACE( jsonb_extract_path_text(NEW.content, 'old', 'geometry'), 'nan', '0' ) ) ), srid ), 4326 );\n NEW.new_geom := ST_Transform( ST_SetSRID( ST_Force2D( ST_GeomFromText( REPLACE( jsonb_extract_path_text(NEW.content, 'new', 'geometry'), 'nan', '0' ) ) ), srid ), 4326 );\n\n IF ST_GeometryType(NEW.old_geom) IN ('ST_CircularString', 'ST_CompoundCurve', 'ST_CurvePolygon', 'ST_MultiCurve', 'ST_MultiSurface')\n THEN\n NEW.old_geom := ST_CurveToLine(NEW.old_geom);\n END IF;\n\n IF ST_GeometryType(NEW.new_geom) IN ('ST_CircularString', 'ST_CompoundCurve', 'ST_CurvePolygon', 'ST_MultiCurve', 'ST_MultiSurface')\n THEN\n NEW.new_geom := ST_CurveToLine(NEW.new_geom);\n END IF;\n\n RETURN NEW;\n END;\n $$\n LANGUAGE PLPGSQL\n ", | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
docker-app/qfieldcloud/core/tests/testdata/delta/deltas/nonspatial_geom_empty_str.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"deltas": [ | ||
{ | ||
"uuid": "1270b97d-6a28-49cc-83f3-b827ec574fee", | ||
"clientId": "cd517e24-a520-4021-8850-e5af70e3a612", | ||
"exportId": "f70c7286-fcec-4dbe-85b5-63d4735dac47", | ||
"localPk": "1", | ||
"sourcePk": "1", | ||
"localLayerId": "nonspatial_5b9be5d0_6faa_4c14_825d_7889615c842c", | ||
"sourceLayerId": "nonspatial_5b9be5d0_6faa_4c14_825d_7889615c842c", | ||
"method": "patch", | ||
"new": { | ||
"geometry": "", | ||
"attributes": { | ||
"col1": "foo" | ||
} | ||
}, | ||
"old": { | ||
"geometry": null, | ||
"attributes": { | ||
"col1": "bar" | ||
} | ||
} | ||
} | ||
], | ||
"files": [], | ||
"id": "2c98410f-e1b2-45e6-9026-97898bfee730", | ||
"project": "e02d02cc-af1b-414c-a14c-e2ed5dfee52f", | ||
"version": "1.0" | ||
} |