]> granicus.if.org Git - postgis/commitdiff
Stub toTopoGeom function and testcase (#1017)
authorSandro Santilli <strk@keybit.net>
Sun, 25 Dec 2011 10:56:12 +0000 (10:56 +0000)
committerSandro Santilli <strk@keybit.net>
Sun, 25 Dec 2011 10:56:12 +0000 (10:56 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8576 b70326c6-7e19-0410-871a-916f4a2858ee

topology/Makefile.in
topology/sql/topogeometry/totopogeom.sql [new file with mode: 0644]
topology/test/Makefile
topology/test/regress/totopogeom.sql [new file with mode: 0644]
topology/test/regress/totopogeom_expected [new file with mode: 0644]
topology/topology.sql.in.c

index e0d377b1374d8c4cef611a50fe5c2a879d5d4610..f694126dc86224a5033a577dd6ead6eb4a8a8661 100644 (file)
@@ -66,7 +66,7 @@ topology_upgrade_20_minor.sql:  topology.sql
                 -e '/^\(CREATE\|ALTER\) \(CAST\|TYPE\|TABLE\|SCHEMA\|DOMAIN\|TRIGGER\)/,/\;/d' \
                 $< > $@
 
-topology.sql.in: sql/sqlmm.sql sql/populate.sql sql/polygonize.sql sql/gml.sql sql/query/getnodebypoint.sql sql/query/getedgebypoint.sql sql/query/getfacebypoint.sql sql/query/GetRingEdges.sql sql/manage/TopologySummary.sql sql/manage/CopyTopology.sql sql/manage/ManageHelper.sql sql/topoelement/topoelement_agg.sql sql/topogeometry/type.sql
+topology.sql.in: sql/sqlmm.sql sql/populate.sql sql/polygonize.sql sql/gml.sql sql/query/getnodebypoint.sql sql/query/getedgebypoint.sql sql/query/getfacebypoint.sql sql/query/GetRingEdges.sql sql/manage/TopologySummary.sql sql/manage/CopyTopology.sql sql/manage/ManageHelper.sql sql/topoelement/topoelement_agg.sql sql/topogeometry/type.sql sql/topogeometry/totopogeom.sql
 
 uninstall_topology.sql: topology.sql ../utils/create_undef.pl 
        $(PERL) ../utils/create_undef.pl $< $(POSTGIS_PGSQL_VERSION) > $@
diff --git a/topology/sql/topogeometry/totopogeom.sql b/topology/sql/topogeometry/totopogeom.sql
new file mode 100644 (file)
index 0000000..6d9408b
--- /dev/null
@@ -0,0 +1,70 @@
+-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+-- 
+-- PostGIS - Spatial Types for PostgreSQL
+-- http://postgis.refractions.net
+--
+-- Copyright (C) 2012 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.
+--
+-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+-- {
+--  Convert a simple geometry to a topologically-defined one
+--
+--  See http://trac.osgeo.org/postgis/ticket/1017
+--
+-- }{
+CREATE OR REPLACE FUNCTION topology.toTopoGeom(geom Geometry, toponame varchar, layer_id int, tolerance float8 DEFAULT 0)
+  RETURNS topology.TopoGeometry
+AS
+$$
+DECLARE
+  layer_info RECORD;
+  topology_info RECORD;
+BEGIN
+
+  -- Get topology information
+  BEGIN
+    SELECT * FROM topology.topology
+      INTO STRICT topology_info WHERE name = toponame;
+  EXCEPTION
+    WHEN NO_DATA_FOUND THEN
+      RAISE EXCEPTION 'No topology with name "%" in topology.topology',
+        toponame;
+  END;
+
+  -- Get layer information
+  BEGIN
+    SELECT * FROM topology.layer l
+      INTO STRICT layer_info
+      WHERE l.layer_id = layer_id
+      AND l.topology_id = topology_info.id;
+  EXCEPTION
+    WHEN NO_DATA_FOUND THEN
+      RAISE EXCEPTION 'No layer with id "%" in topology "%"',
+        layer_id, toponame;
+  END;
+
+  -- Can't convert to a hierarchical topogeometry
+  IF layer_info.level > 0 THEN
+      RAISE EXCEPTION 'Layer "%" of topology "%" is hierarchical, cannot convert to it',
+        layer_id, toponame;
+  END IF;
+
+  -- 
+  -- TODO: Check type compatibility 
+  --  A point can go in puntal or collection layer
+  --  A line can go in lineal or collection layer
+  --  An area can go in areal or collection layer
+  --  A collection can only go collection layer
+  --  What to do with EMPTies ?
+  -- 
+
+  RAISE EXCEPTION 'toTopoGeometry not implemented yet';
+
+END
+$$
+LANGUAGE 'plpgsql' STABLE STRICT;
+-- }
index 062fbaf3935df5ed09d701b07ca12ca3cf4c2975..111bd22512ab21f1705dcfc262d0d902a9420ff5 100644 (file)
@@ -44,6 +44,7 @@ TESTS = regress/legacy_validate.sql regress/legacy_predicate.sql \
        regress/topoelementarray_agg.sql \
        regress/topogeometry_type.sql \
        regress/topo2.5d.sql \
+       regress/totopogeom.sql \
        regress/droptopology.sql \
        regress/copytopology.sql \
        regress/createtopogeom.sql \
diff --git a/topology/test/regress/totopogeom.sql b/topology/test/regress/totopogeom.sql
new file mode 100644 (file)
index 0000000..7afcda8
--- /dev/null
@@ -0,0 +1,30 @@
+\set VERBOSITY terse
+set client_min_messages to ERROR;
+
+select 'create', createtopology('tt') > 0;
+
+-- Invalid calls
+select totopogeom('POINT(0 0)'::geometry, 'unexistent', 1);
+select totopogeom('POINT(0 0)'::geometry, 'tt', 1);
+select totopogeom(null, 'tt', 1);
+select totopogeom('POINT(0 0)'::geometry, '', 1);
+select totopogeom('POINT(0 0)'::geometry, null, 1);
+select totopogeom('POINT(0 0)'::geometry, 'tt', null);
+
+-- Create simple puntual layer ( will be layer 2 )
+CREATE TABLE tt.f_puntal(id serial);
+SELECT 'simple_puntual_layer', AddTopoGeometryColumn('tt', 'tt', 'f_puntal','g','POINT');
+
+-- Create a hierarchical layer (will be layer 2)
+CREATE TABLE tt.f_hier(id serial);
+SELECT 'hierarchical_layer', AddTopoGeometryColumn('tt', 'tt', 'f_hier','g','COLLECTION', 1);
+
+-- A couple more invalid calls
+select totopogeom('POINT(0 0)'::geometry, 'tt', 3); -- non existent layer
+select totopogeom('POINT(0 0)'::geometry, 'tt', 2); -- invalid (hierarchical) layer
+-- TODO: add more invalid calls due to type mismatch
+
+
+DROP TABLE tt.f_hier;
+DROP TABLE tt.f_puntal;
+select droptopology('tt');
diff --git a/topology/test/regress/totopogeom_expected b/topology/test/regress/totopogeom_expected
new file mode 100644 (file)
index 0000000..caff7f5
--- /dev/null
@@ -0,0 +1,9 @@
+create|t
+ERROR:  No topology with name "unexistent" in topology.topology
+ERROR:  No layer with id "1" in topology "tt"
+ERROR:  No topology with name "" in topology.topology
+simple_puntual_layer|1
+hierarchical_layer|2
+ERROR:  No layer with id "3" in topology "tt"
+ERROR:  Layer "2" of topology "tt" is hierarchical, cannot convert to it
+Topology 'tt' dropped
index 542575fa4924b055958fe644a0e47c6bb4f0cbed..9f1052b27a8e5cf12eeac72a8b8000eaa985a1ab 100644 (file)
@@ -2451,6 +2451,7 @@ LANGUAGE 'plpgsql' VOLATILE STRICT;
 
 --  TopoGeometry
 #include "sql/topogeometry/type.sql"
+#include "sql/topogeometry/totopogeom.sql"
 
 --  GML
 #include "sql/gml.sql"