]> granicus.if.org Git - postgis/commitdiff
Ticket #855: topology.TopologySummary(<name>)
authorSandro Santilli <strk@keybit.net>
Wed, 9 Mar 2011 10:19:15 +0000 (10:19 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 9 Mar 2011 10:19:15 +0000 (10:19 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@6886 b70326c6-7e19-0410-871a-916f4a2858ee

topology/Makefile.in
topology/sql/manage/TopologySummary.sql [new file with mode: 0644]
topology/topology.sql.in.c

index 5193f52706807cba70df1766ee6ef545b1e7cb2f..a0ec01b47c86620791b06df76059edd283e7e7f8 100644 (file)
@@ -42,7 +42,7 @@ endif
 $(SQL_OBJS): %.in: %.in.c
        $(CPP) -traditional-cpp $< | grep -v '^#' > $@
 
-topology.sql.in: sql/sqlmm.sql sql/populate.sql sql/gml.sql sql/query/getnodebypoint.sql sql/query/getedgebypoint.sql
+topology.sql.in: sql/sqlmm.sql sql/populate.sql sql/gml.sql sql/query/getnodebypoint.sql sql/query/getedgebypoint.sql sql/manage/TopologySummary.sql
 
 check: topology.sql
        $(MAKE) -C test $@
diff --git a/topology/sql/manage/TopologySummary.sql b/topology/sql/manage/TopologySummary.sql
new file mode 100644 (file)
index 0000000..9c5f4c2
--- /dev/null
@@ -0,0 +1,101 @@
+-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+-- 
+-- PostGIS - Spatial Types for PostgreSQL
+-- http://postgis.refractions.net
+--
+-- Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
+--
+-- This is free software; you can redistribute and/or modify it under
+-- the terms of the GNU General Public Licence. See the COPYING file.
+--
+-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+--{
+--  TopologySummary(name)
+--
+-- Print an overview about a topology
+--
+CREATE OR REPLACE FUNCTION topology.TopologySummary(atopology varchar)
+RETURNS text
+AS
+$$
+DECLARE
+  rec RECORD;
+  rec2 RECORD;
+  topology_id integer;
+  n int4;
+  ret text;
+BEGIN
+
+  SELECT * FROM topology.topology WHERE name = atopology INTO STRICT rec;
+  -- TODO: catch <no_rows> to give a nice error message
+  topology_id := rec.id;
+
+  ret := 'Topology ' || quote_ident(atopology) 
+      || ' (' || rec.id || '), ';
+  ret := ret || 'SRID ' || rec.srid || ', '
+             || 'precision: ' || rec.precision || E'\n';
+
+  EXECUTE 'SELECT count(node_id) FROM ' || quote_ident(atopology)
+    || '.node ' INTO STRICT n;
+  ret = ret || n || ' nodes, ';
+
+  EXECUTE 'SELECT count(edge_id) FROM ' || quote_ident(atopology)
+    || '.edge_data ' INTO STRICT n;
+  ret = ret || n || ' edges, ';
+
+  EXECUTE 'SELECT count(face_id) FROM ' || quote_ident(atopology)
+    || '.face ' INTO STRICT n;
+  ret = ret || n || ' faces, ';
+
+  EXECUTE 'SELECT count(*) FROM (SELECT DISTINCT layer_id,topogeo_id FROM '
+    || quote_ident(atopology) || '.relation ) foo ' INTO STRICT n;
+  ret = ret || n || ' topogeoms in ';
+
+  EXECUTE 'SELECT count(*) FROM (SELECT DISTINCT layer_id FROM '
+    || quote_ident(atopology) || '.relation ) foo ' INTO STRICT n;
+  ret = ret || n || ' layers' || E'\n';
+
+  -- TODO: print informations about layers
+  FOR rec IN SELECT * FROM topology.layer l
+    WHERE l.topology_id = topology_id
+    ORDER by layer_id
+  LOOP
+    ret = ret || 'Layer ' || rec.layer_id || ', type ';
+    CASE
+      WHEN rec.feature_type = 1 THEN
+        ret = ret || 'Puntal';
+      WHEN rec.feature_type = 2 THEN
+        ret = ret || 'Lineal';
+      WHEN rec.feature_type = 3 THEN
+        ret = ret || 'Polygonal';
+      ELSE 
+        ret = ret || '???';
+    END CASE;
+
+    EXECUTE 'SELECT count(*) FROM ( SELECT DISTINCT topogeo_id FROM '
+      || quote_ident(atopology)
+      || '.relation r WHERE r.layer_id = ' || rec.layer_id
+      || ' ) foo ' INTO STRICT n;
+
+    ret = ret || ' (' || rec.feature_type || E'), '
+              || n || ' topogeoms' || E'\n';
+
+    IF rec.level > 0 THEN
+      ret = ret || ' Hierarchy level ' || rec.level 
+                || ', child layer ' || rec.child_id || E'\n';
+    END IF;
+
+    ret = ret || ' Deploy: '
+              || quote_ident(rec.schema_name) || '.'
+              || quote_ident(rec.table_name) || '.'
+              || quote_ident(rec.feature_column)
+              || E'\n';
+  END LOOP;
+
+  RETURN ret;
+END
+$$
+LANGUAGE 'plpgsql' VOLATILE STRICT;
+
+--} TopologySummary
index 7ff49c6ae5302bb3ba871874cdcaf4d87188550c..518e346a9ddb27f049f1c3f601aa2612b9a1b037 100644 (file)
@@ -1907,6 +1907,8 @@ END
 LANGUAGE 'plpgsql' VOLATILE STRICT;
 --} DropTopology
 
+#include "sql/manage/TopologySummary.sql"
+
 --={ ----------------------------------------------------------------
 --  POSTGIS-SPECIFIC topology predicates
 --