From: Sandro Santilli Date: Tue, 19 Apr 2011 16:58:42 +0000 (+0000) Subject: Add topology.polygonize() function, see ticket #916 X-Git-Tag: 2.0.0alpha1~1756 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c1091e7e820288d24069bb3e888ffd281dc455b6;p=postgis Add topology.polygonize() function, see ticket #916 git-svn-id: http://svn.osgeo.org/postgis/trunk@7047 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/topology/Makefile.in b/topology/Makefile.in index d6d036696..72d6e6368 100644 --- a/topology/Makefile.in +++ b/topology/Makefile.in @@ -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 sql/query/getfacebypoint.sql sql/manage/TopologySummary.sql sql/manage/CopyTopology.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/manage/TopologySummary.sql sql/manage/CopyTopology.sql check: topology.sql $(MAKE) -C test $@ diff --git a/topology/sql/polygonize.sql b/topology/sql/polygonize.sql new file mode 100644 index 000000000..4d04bcdb4 --- /dev/null +++ b/topology/sql/polygonize.sql @@ -0,0 +1,51 @@ +-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +-- +-- PostGIS - Spatial Types for PostgreSQL +-- http://postgis.refractions.net +-- +-- Copyright (C) 2011 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. +-- +-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +-- +-- Functions used to polygonize topology edges +-- +-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +--{ +-- +-- int Polygonize(toponame) +-- +-- TODO: allow restricting polygonization to a bounding box +-- +-- }{ +CREATE OR REPLACE FUNCTION topology.polygonize(toponame varchar) + RETURNS text +AS +$$ +DECLARE + sql text; + rec RECORD; + faces int; +BEGIN + + sql := 'SELECT (st_dump(st_polygonize(geom))).geom from ' + || quote_ident(toponame) || '.edge_data'; + + faces = 0; + FOR rec in EXECUTE sql LOOP + BEGIN + PERFORM topology.AddFace(toponame, rec.geom); + faces = faces + 1; + EXCEPTION + WHEN OTHERS THEN + RAISE WARNING 'Error registering face % (%)', rec.geom, SQLERRM; + END; + END LOOP; + RETURN faces || ' faces registered'; +END +$$ +LANGUAGE 'plpgsql'; +--} Polygonize(toponame) diff --git a/topology/topology.sql.in.c b/topology/topology.sql.in.c index 58caa4c38..4ff811224 100644 --- a/topology/topology.sql.in.c +++ b/topology/topology.sql.in.c @@ -2436,8 +2436,9 @@ LANGUAGE 'plpgsql' VOLATILE STRICT; #include "sql/query/getedgebypoint.sql" #include "sql/query/getfacebypoint.sql" --- Editing +-- Populating #include "sql/populate.sql" +#include "sql/polygonize.sql" -- TopoElement #include "sql/topoelement/topoelement_agg.sql"