From 8601e43af62961ec10ba87715e9d91f80b844a22 Mon Sep 17 00:00:00 2001 From: spwoodcock Date: Mon, 26 Feb 2024 10:56:47 +0000 Subject: [PATCH] fix: put feature id on top level of task geojson for odk collect --- src/backend/app/db/postgis_utils.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/backend/app/db/postgis_utils.py b/src/backend/app/db/postgis_utils.py index 6f1a2a40e9..0d4a014fdd 100644 --- a/src/backend/app/db/postgis_utils.py +++ b/src/backend/app/db/postgis_utils.py @@ -257,25 +257,23 @@ async def split_geojson_by_task_areas( -- Create a temporary table to store the parsed GeoJSON features CREATE TEMP TABLE temp_features ( - id SERIAL PRIMARY KEY, + id INTEGER, geometry GEOMETRY, properties JSONB ); -- Insert parsed geometries and properties into the temporary table - INSERT INTO temp_features (geometry, properties) + INSERT INTO temp_features (id, geometry, properties) SELECT + tasks.id, ST_SetSRID(ST_GeomFromGeoJSON(feature->>'geometry'), 4326) AS geometry, jsonb_set( jsonb_set( jsonb_set( - jsonb_set( - feature->'properties', - '{task_id}', to_jsonb(tasks.id), true - ), - '{project_id}', to_jsonb(tasks.project_id), true + feature->'properties', + '{task_id}', to_jsonb(tasks.id), true ), - '{id}', to_jsonb(tasks.id), true + '{project_id}', to_jsonb(tasks.project_id), true ), '{title}', to_jsonb(CONCAT( 'project_', @@ -305,6 +303,7 @@ async def split_geojson_by_task_areas( jsonb_build_object( 'type', 'Feature', 'geometry', ST_AsGeoJSON(temp_features.geometry)::jsonb, + 'id', temp_features.id, 'properties', temp_features.properties ) AS feature FROM (