From 1c6d71b4abaafa133d1eb9d4f6373188accb0ee2 Mon Sep 17 00:00:00 2001 From: Thomas Sibley Date: Mon, 16 Dec 2019 15:46:23 -0800 Subject: [PATCH] wip! Not fully baked prototype of automatically setting warehouse.location.hierarchy for imported locations based on geospatial containment. Probably would want to be optional rather than always used. --- lib/id3c/cli/command/location.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/id3c/cli/command/location.py b/lib/id3c/cli/command/location.py index 6b6a34069..abb46035b 100644 --- a/lib/id3c/cli/command/location.py +++ b/lib/id3c/cli/command/location.py @@ -207,7 +207,7 @@ def as_simplified(feature): select scale, identifier, - coalesce(lower(hierarchy)::hstore, '') || hstore(lower(scale), lower(identifier)) as hierarchy, + coalesce(nested_within.hierarchy, '') || coalesce(lower(hierarchy)::hstore, '') || hstore(lower(scale), lower(identifier)) as hierarchy, st_transform(st_setsrid(st_geomfromgeojson(point), location.srid), 4326) as point, st_transform(st_setsrid(st_multi(st_geomfromgeojson(location.polygon)), location.srid), 4326) as polygon, st_transform(st_setsrid(st_multi(st_geomfromgeojson(simplified.polygon)), simplified.srid), 4326) as simplified_polygon, @@ -227,6 +227,12 @@ def as_simplified(feature): , srid integer ) using (identifier) + left join lateral ( + select hstore_agg(hierarchy) + from warehouse.location as containing + where st_within(location.point, containing.polygon)) + as nested_within + on true ), inserted as ( insert into warehouse.location (scale, identifier, hierarchy, point, polygon, simplified_polygon, details)