]> granicus.if.org Git - postgis/commitdiff
Add topology.clearTopoGeom(TopoGeometry) function
authorSandro Santilli <strk@keybit.net>
Thu, 6 Dec 2012 23:02:23 +0000 (23:02 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 6 Dec 2012 23:02:23 +0000 (23:02 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@10808 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
topology/Makefile.in
topology/sql/topogeometry/cleartopogeom.sql.in.c [new file with mode: 0644]
topology/test/regress/cleartopogeom.sql [new file with mode: 0644]
topology/test/regress/cleartopogeom_expected [new file with mode: 0644]
topology/topology.sql.in.c

diff --git a/NEWS b/NEWS
index bb7a9954aede06f4e781cd874e2296db0ccbb616..bd203fab4c08b81678dc18bfdf305454c2c50203 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,7 @@ PostGIS 2.1.0
 
 * New Features *
 
+  - topology.clearTopoGeom (Sandro Santilli / Vizzuality)
   - ST_Segmentize(geography) (Paul Ramsey / OpenGeo)
   - ST_DelaunayTriangles (Sandro Santilli / Vizzuality)
   - ST_NearestValue, ST_Neighborhood (Bborie Park / UC Davis)
index 06d8e29405aee75d8f813ab552d06a332df4a3e3..8f6cde5d21dbea8d7a2732abd0c2c647b5fa6178 100644 (file)
@@ -90,7 +90,7 @@ topology_upgrade.sql:  topology.sql
 topology_upgrade_$(PGIS_MAJ_MIN)_minor.sql:  topology_drop_before.sql topology_upgrade.sql topology_drop_after.sql
        cat $^ > $@
 
-topology.sql.in: sql/sqlmm.sql.in.c sql/populate.sql.in.c sql/polygonize.sql.in.c sql/gml.sql.in.c sql/query/getnodebypoint.sql.in.c sql/query/getedgebypoint.sql.in.c sql/query/getfacebypoint.sql.in.c sql/query/GetRingEdges.sql.in.c sql/query/GetNodeEdges.sql.in.c sql/manage/TopologySummary.sql.in.c sql/manage/CopyTopology.sql.in.c sql/manage/ManageHelper.sql.in.c sql/topoelement/topoelement_agg.sql.in.c sql/topogeometry/type.sql.in.c sql/topogeometry/totopogeom.sql.in.c sql/predicates.sql.in.c ../postgis/sqldefines.h ../postgis_svn_revision.h
+topology.sql.in: sql/sqlmm.sql.in.c sql/populate.sql.in.c sql/polygonize.sql.in.c sql/gml.sql.in.c sql/query/getnodebypoint.sql.in.c sql/query/getedgebypoint.sql.in.c sql/query/getfacebypoint.sql.in.c sql/query/GetRingEdges.sql.in.c sql/query/GetNodeEdges.sql.in.c sql/manage/TopologySummary.sql.in.c sql/manage/CopyTopology.sql.in.c sql/manage/ManageHelper.sql.in.c sql/topoelement/topoelement_agg.sql.in.c sql/topogeometry/type.sql.in.c sql/topogeometry/totopogeom.sql.in.c sql/topogeometry/cleartopogeom.sql.in.c sql/predicates.sql.in.c ../postgis/sqldefines.h ../postgis_svn_revision.h
 
 uninstall_topology.sql: topology.sql ../utils/create_undef.pl 
        $(PERL) ../utils/create_undef.pl $< $(POSTGIS_PGSQL_VERSION) > $@
diff --git a/topology/sql/topogeometry/cleartopogeom.sql.in.c b/topology/sql/topogeometry/cleartopogeom.sql.in.c
new file mode 100644 (file)
index 0000000..e80dd4c
--- /dev/null
@@ -0,0 +1,52 @@
+-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+-- 
+-- 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.
+--
+-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+-- {
+--  Clear the contents of a TopoGeometry 
+--
+-- }{
+CREATE OR REPLACE FUNCTION topology.clearTopoGeom(tg topology.TopoGeometry)
+  RETURNS topology.TopoGeometry
+AS
+$$
+DECLARE
+  topology_info RECORD;
+  sql TEXT;
+BEGIN
+
+  -- Get topology information
+  SELECT id, name FROM topology.topology
+    INTO topology_info
+    WHERE id = topology_id(tg);
+  IF NOT FOUND THEN
+      RAISE EXCEPTION 'No topology with id "%" in topology.topology', topology_id(tg);
+  END IF;
+
+  -- Clear the TopoGeometry contents
+  sql := 'DELETE FROM ' || quote_ident(topology_info.name)
+        || '.relation WHERE layer_id = '
+        || layer_id(tg)
+        || ' AND topogeo_id = '
+        || id(tg);
+#ifdef POSTGIS_TOPOLOGY_DEBUG
+    RAISE DEBUG '%', sql;
+#endif
+  EXECUTE sql;
+
+
+  RETURN tg;
+
+END
+$$
+LANGUAGE 'plpgsql' VOLATILE STRICT;
+-- }
+
diff --git a/topology/test/regress/cleartopogeom.sql b/topology/test/regress/cleartopogeom.sql
new file mode 100644 (file)
index 0000000..e3697db
--- /dev/null
@@ -0,0 +1,36 @@
+\set VERBOSITY terse
+set client_min_messages to ERROR;
+
+\i load_topology.sql
+\i load_features.sql
+
+SELECT 'relation before', count(distinct topogeo_id)
+ FROM city_data.relation
+ WHERE layer_id = 1;
+
+SELECT 'feature before',
+    feature_name,
+    ST_IsEmpty(feature)
+  FROM features.land_parcels
+  WHERE feature_name = 'P1'
+  ORDER BY feature_name;
+
+SELECT 'feature during',
+    feature_name,
+    ST_IsEmpty(clearTopoGeom(feature))
+  FROM features.land_parcels
+  WHERE feature_name = 'P1'
+  ORDER BY feature_name;
+
+SELECT 'feature after',
+    feature_name,
+    ST_IsEmpty(feature)
+  FROM features.land_parcels
+  WHERE feature_name = 'P1'
+  ORDER BY feature_name;
+
+SELECT 'relation after', count(distinct topogeo_id)
+ FROM city_data.relation
+ WHERE layer_id = 1;
+
+select droptopology('city_data');
diff --git a/topology/test/regress/cleartopogeom_expected b/topology/test/regress/cleartopogeom_expected
new file mode 100644 (file)
index 0000000..decc772
--- /dev/null
@@ -0,0 +1,17 @@
+BEGIN
+t
+9
+22
+26
+COMMIT
+BEGIN
+1
+2
+3
+COMMIT
+relation before|5
+feature before|P1|f
+feature during|P1|t
+feature after|P1|t
+relation after|4
+Topology 'city_data' dropped
index 09a88c07823fecaa4254158cd11f58d8f2f41252..5e5c16ff3f62f39d75c158567ce991958771989c 100644 (file)
@@ -1983,6 +1983,7 @@ LANGUAGE 'plpgsql' VOLATILE STRICT;
 
 --  TopoGeometry
 #include "sql/topogeometry/type.sql.in.c"
+#include "sql/topogeometry/cleartopogeom.sql.in.c"
 #include "sql/topogeometry/totopogeom.sql.in.c"
 
 --  GML