]> granicus.if.org Git - postgis/commitdiff
Add topology.populate_topology_layer function
authorSandro Santilli <strk@keybit.net>
Wed, 25 Nov 2015 23:22:15 +0000 (23:22 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 25 Nov 2015 23:22:15 +0000 (23:22 +0000)
Useful for passing data around.

git-svn-id: http://svn.osgeo.org/postgis/trunk@14432 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
topology/topology.sql.in

diff --git a/NEWS b/NEWS
index 9324d6047323d0a81351852796c7e5b7d2bbc811..b9ca646720ef83bc1cb7268a64a64d824fb2cf47 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,7 +5,8 @@ PostGIS 2.3.0
  * Deprecated signatures *
  * New Features *
 
-  - TopoGeom_addElement, TopoGeom_remElement (Sando Santilli)
+  - TopoGeom_addElement, TopoGeom_remElement (Sandro Santilli)
+  - populate_topology_layer (Sandro Santilli)
 
 PostGIS 2.2.0
 2015/10/07
index 92af06f34e2962c4d6576e50988604f3dc186880..07026692466a9d4a86c60a891cdda974b50ed174 100644 (file)
@@ -812,6 +812,53 @@ LANGUAGE 'plpgsql' VOLATILE;
 --
 --} DropTopoGeometryColumn
 
+-- {
+--
+-- populate_topology_layer
+--
+-- Register missing layers into topology.topology, looking at
+-- their constraints.
+--
+-- The function doesn't attempt to determine if a layer is
+-- hierarchical or primitive, but always assumes primitive.
+--
+-- }{
+DROP FUNCTION IF EXISTS topology.populate_topology_layer();
+CREATE OR REPLACE FUNCTION topology.populate_topology_layer()
+       RETURNS TABLE(schema_name text, table_name text, feature_column text)
+AS
+$$
+  INSERT INTO topology.layer
+  WITH checks AS (
+  SELECT
+    n.nspname sch, r.relname tab,
+    replace(c.conname, 'check_topogeom_', '') col,
+    --c.consrc src,
+    regexp_matches(c.consrc,
+      '\.topology_id = (\d+).*\.layer_id = (\d+).*\.type = (\d+)') inf
+  FROM pg_constraint c, pg_class r, pg_namespace n
+  WHERE c.conname LIKE 'check_topogeom_%'
+    AND r.oid = c.conrelid
+    AND n.oid = r.relnamespace
+  ), newrows AS (
+    SELECT inf[1]::int as topology_id,
+           inf[2]::int as layer_id,
+          sch, tab, col, inf[3]::int as feature_type --, src
+    FROM checks c
+    WHERE NOT EXISTS (
+      SELECT * FROM topology.layer l
+      WHERE l.schema_name = c.sch
+        AND l.table_name = c.tab
+        AND l.feature_column = c.col
+    )
+  )
+  SELECT topology_id, layer_id, sch,
+         tab, col, feature_type,
+         0, NULL
+  FROM newrows RETURNING schema_name,table_name,feature_column;
+$$
+LANGUAGE 'sql' VOLATILE;
+
 
 --{
 -- CreateTopoGeom(topology_name, topogeom_type, layer_id, elements)