From bcf0caf894fae740c5f3ba655a31bfd778b091be Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Tue, 6 Mar 2012 16:16:34 +0000 Subject: [PATCH] Snap new lines over existing nodes (#1654) Also add Salvatore to the list of testing heroes :) git-svn-id: http://svn.osgeo.org/postgis/trunk@9409 b70326c6-7e19-0410-871a-916f4a2858ee --- NEWS | 1 + topology/sql/populate.sql.in.c | 38 +++++++++++++------ .../test/regress/topogeo_addlinestring.sql | 13 +++++++ .../regress/topogeo_addlinestring_expected | 8 ++++ 4 files changed, 49 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index ecfadb3fd..e0b76da9a 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,7 @@ PostGIS 2.0.0beta1 Andrea Peri - Lots of testing on topology, checking for correctness Andreas Forø Tollefsen - raster testing Chris English - topology stress testing loader functions + Salvatore Larosa - Lots of topology testing Brian Hamlin - Benchmarking (also experimental experimental branches before they are folded into core) diff --git a/topology/sql/populate.sql.in.c b/topology/sql/populate.sql.in.c index a036b0f71..4cdfb8b8f 100644 --- a/topology/sql/populate.sql.in.c +++ b/topology/sql/populate.sql.in.c @@ -838,7 +838,7 @@ BEGIN snapped := ST_Snap(noded, iedges, tol); #ifdef POSTGIS_TOPOLOGY_DEBUG - RAISE DEBUG 'Snapped: %', ST_AsText(snapped); + RAISE DEBUG 'Snapped to edges: %', ST_AsText(snapped); #endif noded := ST_Difference(snapped, iedges); @@ -864,28 +864,44 @@ BEGIN END IF; -- 2.1. Node with existing nodes within tol + -- TODO: check if we should be only considering _isolated_ nodes! sql := 'WITH nearby AS ( SELECT n.geom FROM ' || quote_ident(atopology) || '.node n WHERE ST_DWithin(n.geom, ' || quote_literal(noded::text) || '::geometry, ' - || tol || ') ) SELECT (st_dump(st_unaryunion(st_collect(geom)))).geom FROM nearby;'; + || tol || ') ) SELECT st_collect(geom) FROM nearby;'; #ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG '%', sql; #endif - FOR rec IN EXECUTE sql - LOOP - -- Use the node to split edges - SELECT ST_Collect(geom) - FROM ST_Dump(ST_Split(noded, rec.geom)) - INTO STRICT noded; + EXECUTE sql INTO inodes; + + IF inodes IS NOT NULL THEN -- { #ifdef POSTGIS_TOPOLOGY_DEBUG - RAISE DEBUG 'Split by %: %', ST_AsText(rec.geom), ST_AsText(noded); + RAISE DEBUG 'Intersecting nodes: %', ST_AsText(inodes); #endif - END LOOP; + + -- TODO: consider snapping once against all elements + --- (rather than once with edges and once with nodes) + noded := ST_Snap(noded, inodes, tol); +#ifdef POSTGIS_TOPOLOGY_DEBUG + RAISE DEBUG 'Snapped to nodes: %', ST_AsText(noded); +#endif + + FOR rec IN SELECT (ST_Dump(inodes)).* + LOOP + -- Use the node to split edges + SELECT ST_Collect(geom) + FROM ST_Dump(ST_Split(noded, rec.geom)) + INTO STRICT noded; +#ifdef POSTGIS_TOPOLOGY_DEBUG + RAISE DEBUG 'Split by %: %', ST_AsText(rec.geom), ST_AsText(noded); +#endif + END LOOP; #ifdef POSTGIS_TOPOLOGY_DEBUG - RAISE DEBUG 'Split: %', ST_AsText(noded); + RAISE DEBUG 'Split: %', ST_AsText(noded); #endif + END IF; -- } -- 3. For each (now-noded) segment, insert an edge FOR rec IN SELECT (ST_Dump(noded)).geom LOOP diff --git a/topology/test/regress/topogeo_addlinestring.sql b/topology/test/regress/topogeo_addlinestring.sql index ebdfd9cc7..cad4f1794 100644 --- a/topology/test/regress/topogeo_addlinestring.sql +++ b/topology/test/regress/topogeo_addlinestring.sql @@ -189,6 +189,19 @@ SELECT '#1650.3', TopoGeo_addLineString('city_data', , 2) ORDER BY 2; SELECT check_changes(); +-- Test snapping of line over a node( http://trac.osgeo.org/postgis/ticket/??? ) + +DELETE FROM city_data.edge_data; DELETE FROM city_data.node; +DELETE FROM city_data.face where face_id > 0; + +SELECT '#1654.1', 'N', ST_AddIsoNode('city_data', 0, 'POINT(0 0)'); +SELECT check_changes(); +SELECT '#1654.2', TopoGeo_addLineString('city_data', + 'LINESTRING(-10 1, 10 1)' +, 2); +SELECT check_changes(); + + -- Cleanups DROP FUNCTION check_changes(); SELECT DropTopology('city_data'); diff --git a/topology/test/regress/topogeo_addlinestring_expected b/topology/test/regress/topogeo_addlinestring_expected index 4d21f9b2d..1dae3b809 100644 --- a/topology/test/regress/topogeo_addlinestring_expected +++ b/topology/test/regress/topogeo_addlinestring_expected @@ -149,4 +149,12 @@ N|65|0|POINT(0 0) #1650.3|66 N|66||POINT(10 0) E|66|sn65|en66 +#1654.1|N|67 +N|67|0|POINT(0 0) +#1654.2|67 +#1654.2|68 +N|68||POINT(-10 1) +N|69||POINT(10 1) +E|67|sn68|en67 +E|68|sn67|en69 Topology 'city_data' dropped -- 2.40.0