From 0caa3c0b895e81e2af7624f0018e258ff8f01844 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Thu, 6 Dec 2012 23:02:23 +0000 Subject: [PATCH] Add topology.clearTopoGeom(TopoGeometry) function git-svn-id: http://svn.osgeo.org/postgis/trunk@10808 b70326c6-7e19-0410-871a-916f4a2858ee --- NEWS | 1 + topology/Makefile.in | 2 +- .../sql/topogeometry/cleartopogeom.sql.in.c | 52 +++++++++++++++++++ topology/test/regress/cleartopogeom.sql | 36 +++++++++++++ topology/test/regress/cleartopogeom_expected | 17 ++++++ topology/topology.sql.in.c | 1 + 6 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 topology/sql/topogeometry/cleartopogeom.sql.in.c create mode 100644 topology/test/regress/cleartopogeom.sql create mode 100644 topology/test/regress/cleartopogeom_expected diff --git a/NEWS b/NEWS index bb7a9954a..bd203fab4 100644 --- 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) diff --git a/topology/Makefile.in b/topology/Makefile.in index 06d8e2940..8f6cde5d2 100644 --- a/topology/Makefile.in +++ b/topology/Makefile.in @@ -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 index 000000000..e80dd4cde --- /dev/null +++ b/topology/sql/topogeometry/cleartopogeom.sql.in.c @@ -0,0 +1,52 @@ +-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +-- +-- PostGIS - Spatial Types for PostgreSQL +-- http://postgis.refractions.net +-- +-- Copyright (C) 2012 Sandro Santilli +-- +-- 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 index 000000000..e3697dbe5 --- /dev/null +++ b/topology/test/regress/cleartopogeom.sql @@ -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 index 000000000..decc772f4 --- /dev/null +++ b/topology/test/regress/cleartopogeom_expected @@ -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 diff --git a/topology/topology.sql.in.c b/topology/topology.sql.in.c index 09a88c078..5e5c16ff3 100644 --- a/topology/topology.sql.in.c +++ b/topology/topology.sql.in.c @@ -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 -- 2.50.1