From d6845686e0a13c3947ed7344466adf65fa6fd36d Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Sun, 15 Jan 2012 20:52:08 +0000 Subject: [PATCH] Wrap DEBUG output in ifdef POSTGIS_TOPOLOGY_DEBUG (#1469) git-svn-id: http://svn.osgeo.org/postgis/trunk@8822 b70326c6-7e19-0410-871a-916f4a2858ee --- topology/Makefile.in | 2 +- topology/sql/{gml.sql => gml.sql.in.c} | 0 ...CopyTopology.sql => CopyTopology.sql.in.c} | 0 ...ManageHelper.sql => ManageHelper.sql.in.c} | 0 ...gySummary.sql => TopologySummary.sql.in.c} | 0 .../{polygonize.sql => polygonize.sql.in.c} | 0 .../sql/{populate.sql => populate.sql.in.c} | 62 +++++++ .../{predicates.sql => predicates.sql.in.c} | 0 ...GetRingEdges.sql => GetRingEdges.sql.in.c} | 0 ...dgebypoint.sql => getedgebypoint.sql.in.c} | 0 ...acebypoint.sql => getfacebypoint.sql.in.c} | 0 ...odebypoint.sql => getnodebypoint.sql.in.c} | 0 topology/sql/{sqlmm.sql => sqlmm.sql.in.c} | 160 ++++++++++++++++++ ...ement_agg.sql => topoelement_agg.sql.in.c} | 0 .../{totopogeom.sql => totopogeom.sql.in.c} | 0 .../topogeometry/{type.sql => type.sql.in.c} | 0 topology/topology.sql.in.c | 30 ++-- 17 files changed, 238 insertions(+), 16 deletions(-) rename topology/sql/{gml.sql => gml.sql.in.c} (100%) rename topology/sql/manage/{CopyTopology.sql => CopyTopology.sql.in.c} (100%) rename topology/sql/manage/{ManageHelper.sql => ManageHelper.sql.in.c} (100%) rename topology/sql/manage/{TopologySummary.sql => TopologySummary.sql.in.c} (100%) rename topology/sql/{polygonize.sql => polygonize.sql.in.c} (100%) rename topology/sql/{populate.sql => populate.sql.in.c} (95%) rename topology/sql/{predicates.sql => predicates.sql.in.c} (100%) rename topology/sql/query/{GetRingEdges.sql => GetRingEdges.sql.in.c} (100%) rename topology/sql/query/{getedgebypoint.sql => getedgebypoint.sql.in.c} (100%) rename topology/sql/query/{getfacebypoint.sql => getfacebypoint.sql.in.c} (100%) rename topology/sql/query/{getnodebypoint.sql => getnodebypoint.sql.in.c} (100%) rename topology/sql/{sqlmm.sql => sqlmm.sql.in.c} (97%) rename topology/sql/topoelement/{topoelement_agg.sql => topoelement_agg.sql.in.c} (100%) rename topology/sql/topogeometry/{totopogeom.sql => totopogeom.sql.in.c} (100%) rename topology/sql/topogeometry/{type.sql => type.sql.in.c} (100%) diff --git a/topology/Makefile.in b/topology/Makefile.in index 9845269d8..cabe44bd9 100644 --- a/topology/Makefile.in +++ b/topology/Makefile.in @@ -69,7 +69,7 @@ topology_upgrade.sql: topology.sql topology_upgrade_20_minor.sql: topology_drop_before.sql topology_upgrade.sql topology_drop_after.sql cat $^ > $@ -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 sql/predicates.sql +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/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 uninstall_topology.sql: topology.sql ../utils/create_undef.pl $(PERL) ../utils/create_undef.pl $< $(POSTGIS_PGSQL_VERSION) > $@ diff --git a/topology/sql/gml.sql b/topology/sql/gml.sql.in.c similarity index 100% rename from topology/sql/gml.sql rename to topology/sql/gml.sql.in.c diff --git a/topology/sql/manage/CopyTopology.sql b/topology/sql/manage/CopyTopology.sql.in.c similarity index 100% rename from topology/sql/manage/CopyTopology.sql rename to topology/sql/manage/CopyTopology.sql.in.c diff --git a/topology/sql/manage/ManageHelper.sql b/topology/sql/manage/ManageHelper.sql.in.c similarity index 100% rename from topology/sql/manage/ManageHelper.sql rename to topology/sql/manage/ManageHelper.sql.in.c diff --git a/topology/sql/manage/TopologySummary.sql b/topology/sql/manage/TopologySummary.sql.in.c similarity index 100% rename from topology/sql/manage/TopologySummary.sql rename to topology/sql/manage/TopologySummary.sql.in.c diff --git a/topology/sql/polygonize.sql b/topology/sql/polygonize.sql.in.c similarity index 100% rename from topology/sql/polygonize.sql rename to topology/sql/polygonize.sql.in.c diff --git a/topology/sql/populate.sql b/topology/sql/populate.sql.in.c similarity index 95% rename from topology/sql/populate.sql rename to topology/sql/populate.sql.in.c index a4930165e..dbb1c0d72 100644 --- a/topology/sql/populate.sql +++ b/topology/sql/populate.sql.in.c @@ -96,7 +96,9 @@ BEGIN IF setContainingFace THEN containing_face := topology.GetFaceByPoint(atopology, apoint, 0); +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'containing face: %', containing_face; +#endif ELSE containing_face := NULL; END IF; @@ -245,7 +247,9 @@ BEGIN -- Reuse an EQUAL edge (be it closed or not) IF ST_RelateMatch(rec.im, '1FFF*FFF2') THEN +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Edge already known as %', rec.edge_id; +#endif RETURN rec.edge_id; END IF; @@ -471,8 +475,10 @@ BEGIN right_side = ST_Line_Locate_Point(bounds, p1) < ST_Line_Locate_Point(bounds, p2); +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Edge % (left:%, right:%) - ring : % - right_side : %', rec.edge_id, rec.left_face, rec.right_face, rrec.path, right_side; +#endif IF right_side THEN right_edges := array_append(right_edges, rec.edge_id); @@ -499,8 +505,12 @@ BEGIN RAISE EXCEPTION 'Found no edges on the polygon boundary'; END IF; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Left edges: %', left_edges; +#endif +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Right edges: %', right_edges; +#endif -- -- Check that all edges found, taken togheter, @@ -521,10 +531,14 @@ BEGIN IF faceid IS NOT NULL AND faceid != 0 THEN IF NOT force_new THEN +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Face already known as %, not forcing a new face', faceid; +#endif RETURN faceid; ELSE +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Face already known as %, forcing a new face', faceid; +#endif END IF; END IF; @@ -656,13 +670,17 @@ BEGIN || tolerance || ') ORDER BY ST_Distance(' || quote_literal(apoint::text) || '::geometry, a.geom) LIMIT 1;'; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG '%', sql; +#endif EXECUTE sql INTO id; IF id IS NOT NULL THEN RETURN id; END IF; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'No existing node within tolerance distance'; +#endif -- 2. Check if any existing edge falls within tolerance -- and if so split it by a point projected on it @@ -673,14 +691,20 @@ BEGIN || tolerance || ') ORDER BY ST_Distance(' || quote_literal(apoint::text) || '::geometry, a.geom) LIMIT 1;'; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG '%', sql; +#endif EXECUTE sql INTO rec; IF rec IS NOT NULL THEN -- project point to line, split edge by point prj := ST_ClosestPoint(rec.geom, apoint); +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Splitting edge % with closest point %', rec.edge_id, ST_AsText(prj); +#endif IF NOT ST_Contains(rec.geom, prj) THEN +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG ' Snapping edge to contain closest point'; +#endif -- Snap the edge geometry to the projected point -- The tolerance is an arbitrary number. -- How much would be enough to ensure any projected point is within @@ -690,7 +714,9 @@ BEGIN END IF; id := topology.ST_ModEdgeSplit(atopology, rec.edge_id, prj); ELSE +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'No existing edge within tolerance distance'; +#endif id := topology.ST_AddIsoNode(atopology, NULL, apoint); END IF; @@ -728,7 +754,9 @@ BEGIN -- 1. Self-node noded := ST_UnaryUnion(aline); +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Self-noded: %', ST_AsText(noded); +#endif -- 2. Node to edges and nodes falling within tolerance distance sql := 'WITH nearby AS ( SELECT geom FROM ' @@ -740,15 +768,23 @@ BEGIN || '.edge WHERE ST_DWithin(geom,' || quote_literal(aline::text) || '::geometry,' || tolerance || ') ) SELECT st_collect(geom) FROM nearby;'; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG '%', sql; +#endif EXECUTE sql INTO set1; IF set1 IS NOT NULL THEN snapped := ST_Snap(noded, set1, tolerance); +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Snapped: %', ST_AsText(snapped); +#endif noded := ST_Difference(snapped, set1); +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Difference: %', ST_AsText(noded); +#endif set2 := ST_Intersection(snapped, set1); +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Intersection: %', ST_AsText(set2); +#endif noded := ST_Union(noded, set2); -- TODO: linemerge ? END IF; @@ -758,40 +794,58 @@ BEGIN -- TODO: skip point elements ? +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Adding edge %', ST_AsText(rec.geom); +#endif start_node := topology.TopoGeo_AddPoint(atopology, ST_StartPoint(rec.geom), tolerance); +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG ' Start Node: %', start_node; +#endif end_node := topology.TopoGeo_AddPoint(atopology, ST_EndPoint(rec.geom), tolerance); +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG ' End Node: %', end_node; +#endif -- Added endpoints may have drifted due to tolerance, so -- we need to re-snap the edge to the new nodes before adding it sql := 'SELECT ST_Collect(geom) FROM ' || quote_ident(atopology) || '.node WHERE node_id IN (' || start_node || ',' || end_node || ')'; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG '%', sql; +#endif EXECUTE sql INTO STRICT set2; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Endnodes: %', ST_AsText(set2); +#endif snapped := ST_Snap(rec.geom, set2, tolerance); +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Snapped edge: %', ST_AsText(snapped); +#endif -- Check if the so-snapped edge _now_ exists sql := 'SELECT edge_id FROM ' || quote_ident(atopology) || '.edge_data WHERE ST_Equals(geom, ' || quote_literal(snapped::text) || '::geometry)'; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG '%', sql; +#endif EXECUTE sql INTO id; IF id IS NULL THEN id := topology.ST_AddEdgeModFace(atopology, start_node, end_node, snapped); +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'New edge id: %', id; +#endif ELSE +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Old edge id: %', id; +#endif END IF; RETURN NEXT id; @@ -828,12 +882,16 @@ BEGIN -- 1. Extract boundary boundary := ST_Boundary(apoly); +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Boundary: %', ST_AsText(boundary); +#endif -- 2. Add boundaries as edges FOR rec IN SELECT (ST_Dump(boundary)).geom LOOP edges := array_cat(edges, array_agg(x)) FROM ( select topology.TopoGeo_addLinestring(atopology, rec.geom, tolerance) as x ) as foo; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'New edges: %', edges; +#endif END LOOP; -- 3. Find faces covered by input polygon @@ -842,12 +900,16 @@ BEGIN || '.face f WHERE f.mbr && ' || quote_literal(apoly::text) || '::geometry'; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG '%', sql; +#endif FOR rec IN EXECUTE sql LOOP -- check for actual containment fgeom := ST_PointOnSurface(ST_GetFaceGeometry(atopology, rec.face_id)); IF NOT ST_Covers(apoly, fgeom) THEN +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Face % not covered by input polygon', rec.face_id; +#endif CONTINUE; END IF; RETURN NEXT rec.face_id; diff --git a/topology/sql/predicates.sql b/topology/sql/predicates.sql.in.c similarity index 100% rename from topology/sql/predicates.sql rename to topology/sql/predicates.sql.in.c diff --git a/topology/sql/query/GetRingEdges.sql b/topology/sql/query/GetRingEdges.sql.in.c similarity index 100% rename from topology/sql/query/GetRingEdges.sql rename to topology/sql/query/GetRingEdges.sql.in.c diff --git a/topology/sql/query/getedgebypoint.sql b/topology/sql/query/getedgebypoint.sql.in.c similarity index 100% rename from topology/sql/query/getedgebypoint.sql rename to topology/sql/query/getedgebypoint.sql.in.c diff --git a/topology/sql/query/getfacebypoint.sql b/topology/sql/query/getfacebypoint.sql.in.c similarity index 100% rename from topology/sql/query/getfacebypoint.sql rename to topology/sql/query/getfacebypoint.sql.in.c diff --git a/topology/sql/query/getnodebypoint.sql b/topology/sql/query/getnodebypoint.sql.in.c similarity index 100% rename from topology/sql/query/getnodebypoint.sql rename to topology/sql/query/getnodebypoint.sql.in.c diff --git a/topology/sql/sqlmm.sql b/topology/sql/sqlmm.sql.in.c similarity index 97% rename from topology/sql/sqlmm.sql rename to topology/sql/sqlmm.sql.in.c index 25a123b55..e9fc62935 100644 --- a/topology/sql/sqlmm.sql +++ b/topology/sql/sqlmm.sql.in.c @@ -104,8 +104,10 @@ BEGIN FOR rec IN EXECUTE sql LOOP +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'rn:%, n:%, edg:%, cnt:%, min:%, reord:%', rec.rn, n, rec.edge_id, rec.cnt, rec.min, rec.reord; +#endif retrec.sequence = n; retrec.edge = rec.edge_id; @@ -281,7 +283,9 @@ BEGIN rec.geom = ST_LineMerge(ST_Collect(e1rec.geom, e2rec.geom)); IF caseno = 1 THEN -- e1.end = e2.start IF NOT ST_Equals(ST_StartPoint(rec.geom), ST_StartPoint(e1rec.geom)) THEN +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'caseno=1: LineMerge did not maintain startpoint'; +#endif rec.geom = ST_Reverse(rec.geom); END IF; rec.end_node = e2rec.end_node; @@ -289,7 +293,9 @@ BEGIN e2sign = 1; ELSIF caseno = 2 THEN -- e1.end = e2.end IF NOT ST_Equals(ST_StartPoint(rec.geom), ST_StartPoint(e1rec.geom)) THEN +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'caseno=2: LineMerge did not maintain startpoint'; +#endif rec.geom = ST_Reverse(rec.geom); END IF; rec.end_node = e2rec.start_node; @@ -297,7 +303,9 @@ BEGIN e2sign = -1; ELSIF caseno = 3 THEN -- e1.start = e2.start IF NOT ST_Equals(ST_EndPoint(rec.geom), ST_EndPoint(e1rec.geom)) THEN +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'caseno=4: LineMerge did not maintain endpoint'; +#endif rec.geom = ST_Reverse(rec.geom); END IF; rec.start_node = e2rec.end_node; @@ -305,7 +313,9 @@ BEGIN e2sign = -1; ELSIF caseno = 4 THEN -- e1.start = e2.end IF NOT ST_Equals(ST_EndPoint(rec.geom), ST_EndPoint(e1rec.geom)) THEN +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'caseno=4: LineMerge did not maintain endpoint'; +#endif rec.geom = ST_Reverse(rec.geom); END IF; rec.start_node = e2rec.start_node; @@ -392,7 +402,9 @@ BEGIN || ' AND l.layer_id = r.layer_id AND abs(r.element_id) = ' || e1id ; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'SQL: %', sql; +#endif EXECUTE sql; @@ -559,7 +571,9 @@ BEGIN rec.geom = ST_LineMerge(ST_Collect(e1rec.geom, e2rec.geom)); IF caseno = 1 THEN -- e1.end = e2.start IF NOT ST_Equals(ST_StartPoint(rec.geom), ST_StartPoint(e1rec.geom)) THEN +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'caseno=1: LineMerge did not maintain startpoint'; +#endif rec.geom = ST_Reverse(rec.geom); END IF; rec.end_node = e2rec.end_node; @@ -567,7 +581,9 @@ BEGIN e2sign = 1; ELSIF caseno = 2 THEN -- e1.end = e2.end IF NOT ST_Equals(ST_StartPoint(rec.geom), ST_StartPoint(e1rec.geom)) THEN +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'caseno=2: LineMerge did not maintain startpoint'; +#endif rec.geom = ST_Reverse(rec.geom); END IF; rec.end_node = e2rec.start_node; @@ -575,7 +591,9 @@ BEGIN e2sign = -1; ELSIF caseno = 3 THEN -- e1.start = e2.start IF NOT ST_Equals(ST_EndPoint(rec.geom), ST_EndPoint(e1rec.geom)) THEN +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'caseno=4: LineMerge did not maintain endpoint'; +#endif rec.geom = ST_Reverse(rec.geom); END IF; rec.start_node = e2rec.end_node; @@ -583,7 +601,9 @@ BEGIN e2sign = -1; ELSIF caseno = 4 THEN -- e1.start = e2.end IF NOT ST_Equals(ST_EndPoint(rec.geom), ST_EndPoint(e1rec.geom)) THEN +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'caseno=4: LineMerge did not maintain endpoint'; +#endif rec.geom = ST_Reverse(rec.geom); END IF; rec.start_node = e2rec.start_node; @@ -728,7 +748,9 @@ BEGIN || 'WHERE l.level = 0 AND l.feature_type = 2 ' || ' AND l.topology_id = ' || topoid || ' AND abs(r.element_id) = ' || e1id ; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Checking TopoGeometry definitions: %', sql; +#endif FOR rec IN EXECUTE sql LOOP RAISE EXCEPTION 'TopoGeom % in layer % (%.%.%) cannot be represented dropping edge %', rec.topogeo_id, rec.layer_id, @@ -753,7 +775,9 @@ BEGIN || abs(elink) || ' WHERE next_left_edge < 0 AND abs(next_left_edge) = ' || e1id; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'next_left_edge update: %', sql; +#endif EXECUTE sql; -- If the edge being removed links to self, @@ -771,7 +795,9 @@ BEGIN || abs(elink) || ' WHERE next_left_edge > 0 AND abs(next_left_edge) = ' || e1id; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'next_left_edge update: %', sql; +#endif EXECUTE sql; -- } @@ -787,7 +813,9 @@ BEGIN || abs(elink) || ' WHERE next_right_edge < 0 AND abs(next_right_edge) = ' || e1id; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'next_right_edge update: %', sql; +#endif EXECUTE sql; -- If the edge being removed links to self, @@ -805,7 +833,9 @@ BEGIN || abs(elink) || ' WHERE next_right_edge > 0 AND abs(next_right_edge) = ' || e1id; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'next_right_edge update: %', sql; +#endif EXECUTE sql; -- } @@ -847,7 +877,9 @@ BEGIN || 'group by r.topogeo_id, r.layer_id, l.schema_name, l.table_name, ' || ' l.feature_column ) t WHERE NOT t.elems @> ' || quote_literal(fidary); +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'SQL: %', sql; +#endif FOR rec IN EXECUTE sql LOOP RAISE EXCEPTION 'TopoGeom % in layer % (%.%.%) cannot be represented healing faces % and %', rec.topogeo_id, rec.layer_id, @@ -891,7 +923,9 @@ BEGIN || '.face WHERE face_id IN (' || e1rec.left_face || ',' || e1rec.right_face || ')'; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'SQL: %', sql; +#endif EXECUTE sql; END IF; -- } @@ -902,7 +936,9 @@ BEGIN || ' WHERE left_face IN (' || e1rec.left_face || ',' || e1rec.right_face || ')'; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'left_face update: %', sql; +#endif EXECUTE sql; -- Update right_face for all edges still referencing old faces @@ -911,7 +947,9 @@ BEGIN || ' WHERE right_face IN (' || e1rec.left_face || ',' || e1rec.right_face || ')'; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'right_face update: %', sql; +#endif EXECUTE sql; -- Update containing_face for all nodes still referencing old faces @@ -920,7 +958,9 @@ BEGIN || ' WHERE containing_face IN (' || e1rec.left_face || ',' || e1rec.right_face || ')'; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Isolated nodes update: %', sql; +#endif EXECUTE sql; -- NOT IN THE SPECS: @@ -933,7 +973,9 @@ BEGIN || ' AND l.topology_id = ' || topoid || ' AND l.layer_id = r.layer_id AND abs(r.element_id) = ' || e1rec.left_face; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'SQL: %', sql; +#endif EXECUTE sql; sql := 'UPDATE ' || quote_ident(toponame) || '.relation r ' @@ -942,7 +984,9 @@ BEGIN || ' AND l.topology_id = ' || topoid || ' AND l.layer_id = r.layer_id AND r.element_id = ' || e1rec.right_face; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'SQL: %', sql; +#endif EXECUTE sql; END IF; -- } two faces healed... @@ -950,7 +994,9 @@ BEGIN -- Delete the edge sql := 'DELETE FROM ' || quote_ident(toponame) || '.edge_data WHERE edge_id = ' || e1id; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Edge deletion: %', sql; +#endif EXECUTE sql; -- Check if any of the edge nodes remains isolated, @@ -962,7 +1008,9 @@ BEGIN || e1rec.end_node || ') AND NOT EXISTS (SELECT edge_id FROM ' || quote_ident(toponame) || '.edge_data WHERE start_node = n.node_id OR end_node = n.node_id)'; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Checking for nodes left isolated: %', sql; +#endif EXECUTE sql; IF e1rec.right_face != e1rec.left_face THEN -- { @@ -971,7 +1019,9 @@ BEGIN IF e1rec.left_face != 0 THEN sql := 'DELETE FROM ' || quote_ident(toponame) || '.face WHERE face_id = ' || e1rec.left_face; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Left face deletion: %', sql; +#endif EXECUTE sql; END IF; @@ -980,7 +1030,9 @@ BEGIN THEN sql := 'DELETE FROM ' || quote_ident(toponame) || '.face WHERE face_id = ' || e1rec.right_face; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Right face deletion: %', sql; +#endif EXECUTE sql; END IF; @@ -1065,7 +1117,9 @@ BEGIN || 'WHERE l.level = 0 AND l.feature_type = 2 ' || ' AND l.topology_id = ' || topoid || ' AND abs(r.element_id) = ' || e1id ; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Checking TopoGeometry definitions: %', sql; +#endif FOR rec IN EXECUTE sql LOOP RAISE EXCEPTION 'TopoGeom % in layer % (%.%.%) cannot be represented dropping edge %', rec.topogeo_id, rec.layer_id, @@ -1090,7 +1144,9 @@ BEGIN || abs(elink) || ' WHERE next_left_edge < 0 AND abs(next_left_edge) = ' || e1id; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'next_left_edge update: %', sql; +#endif EXECUTE sql; -- If the edge being removed links to self, @@ -1108,7 +1164,9 @@ BEGIN || abs(elink) || ' WHERE next_left_edge > 0 AND abs(next_left_edge) = ' || e1id; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'next_left_edge update: %', sql; +#endif EXECUTE sql; -- } @@ -1124,7 +1182,9 @@ BEGIN || abs(elink) || ' WHERE next_right_edge < 0 AND abs(next_right_edge) = ' || e1id; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'next_right_edge update: %', sql; +#endif EXECUTE sql; -- If the edge being removed links to self, @@ -1142,7 +1202,9 @@ BEGIN || abs(elink) || ' WHERE next_right_edge > 0 AND abs(next_right_edge) = ' || e1id; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'next_right_edge update: %', sql; +#endif EXECUTE sql; -- } @@ -1183,7 +1245,9 @@ BEGIN || 'group by r.topogeo_id, r.layer_id, l.schema_name, l.table_name, ' || ' l.feature_column ) t WHERE NOT t.elems @> ' || quote_literal(fidary); +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'SQL: %', sql; +#endif FOR rec IN EXECUTE sql LOOP RAISE EXCEPTION 'TopoGeom % in layer % (%.%.%) cannot be represented healing faces % and %', rec.topogeo_id, rec.layer_id, @@ -1217,7 +1281,9 @@ BEGIN || '.face WHERE face_id IN (' || e1rec.left_face || ',' || e1rec.right_face || ') ) WHERE face_id = ' || floodfaceid ; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'SQL: %', sql; +#endif EXECUTE sql; END IF; -- } @@ -1228,7 +1294,9 @@ BEGIN || ' WHERE left_face IN (' || e1rec.left_face || ',' || e1rec.right_face || ')'; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'left_face update: %', sql; +#endif EXECUTE sql; -- Update right_face for all edges still referencing old faces @@ -1237,7 +1305,9 @@ BEGIN || ' WHERE right_face IN (' || e1rec.left_face || ',' || e1rec.right_face || ')'; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'right_face update: %', sql; +#endif EXECUTE sql; -- Update containing_face for all nodes still referencing old faces @@ -1246,7 +1316,9 @@ BEGIN || ' WHERE containing_face IN (' || e1rec.left_face || ',' || e1rec.right_face || ')'; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Isolated nodes update: %', sql; +#endif EXECUTE sql; -- NOT IN THE SPECS: @@ -1261,7 +1333,9 @@ BEGIN || e1rec.left_face || ',' || e1rec.right_face || ') AND abs(r.element_id) != ' || floodfaceid; -- could be optimized.. +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'SQL: %', sql; +#endif EXECUTE sql; END IF; -- } two faces healed... @@ -1269,7 +1343,9 @@ BEGIN -- Delete the edge sql := 'DELETE FROM ' || quote_ident(toponame) || '.edge_data WHERE edge_id = ' || e1id; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Edge deletion: %', sql; +#endif EXECUTE sql; -- Check if any of the edge nodes remains isolated, @@ -1281,7 +1357,9 @@ BEGIN || e1rec.end_node || ') AND NOT EXISTS (SELECT edge_id FROM ' || quote_ident(toponame) || '.edge_data WHERE start_node = n.node_id OR end_node = n.node_id)'; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Checking for nodes left isolated: %', sql; +#endif EXECUTE sql; IF e1rec.right_face != e1rec.left_face THEN -- { @@ -1291,7 +1369,9 @@ BEGIN THEN sql := 'DELETE FROM ' || quote_ident(toponame) || '.face WHERE face_id = ' || e1rec.left_face; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Left face deletion: %', sql; +#endif EXECUTE sql; END IF; @@ -1300,7 +1380,9 @@ BEGIN THEN sql := 'DELETE FROM ' || quote_ident(toponame) || '.face WHERE face_id = ' || e1rec.right_face; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Right face deletion: %', sql; +#endif EXECUTE sql; END IF; @@ -2672,8 +2754,10 @@ BEGIN || ')' LOOP IF rec.containing_face IS NOT NULL THEN +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'containing_face for node %:%', rec.node_id, rec.containing_face; +#endif IF newedge.left_face IS NULL THEN newedge.left_face := rec.containing_face; newedge.right_face := rec.containing_face; @@ -2778,7 +2862,9 @@ BEGIN -- Find links on start node -- { +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'My start-segment azimuth: %', span.myaz; +#endif sql := 'SELECT edge_id, -1 AS end_node, start_node, left_face, right_face, ' @@ -2824,8 +2910,10 @@ BEGIN rec.edge_id; END IF; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Edge % - az % (%) - fl:% fr:%', rec.edge_id, az, az - span.myaz, rec.left_face, rec.right_face; +#endif az = az - span.myaz; IF az < 0 THEN @@ -2866,7 +2954,9 @@ BEGIN END LOOP; -- incident edges } +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'span ROW_COUNT: %', i; +#endif IF newedge.isclosed THEN IF i < 2 THEN span.was_isolated = true; END IF; ELSE @@ -2882,18 +2972,26 @@ BEGIN newedge.prev_left_edge := -span.nextCCW; END IF; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'edge:%', newedge.edge_id; +#endif +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG ' left:%, next:%, prev:%', newedge.left_face, newedge.next_left_edge, newedge.prev_left_edge; +#endif +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG ' right:%, next:%, prev:%', newedge.right_face, newedge.next_right_edge, newedge.prev_right_edge; +#endif -- } start_node analysis -- Find links on end_node { +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'My end-segment azimuth: %', epan.myaz; +#endif sql := 'SELECT edge_id, -1 as end_node, start_node, left_face, right_face, ' @@ -2935,7 +3033,9 @@ BEGIN END IF; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Edge % - az % (%)', rec.edge_id, az, az - epan.myaz; +#endif az := az - epan.myaz; IF az < 0 THEN @@ -2976,7 +3076,9 @@ BEGIN END LOOP; -- incident edges } +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'epan ROW_COUNT: %', i; +#endif IF newedge.isclosed THEN IF i < 2 THEN epan.was_isolated = true; END IF; ELSE @@ -2994,11 +3096,17 @@ BEGIN -- } end_node analysis +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'edge:%', newedge.edge_id; +#endif +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG ' left:%, next:%, prev:%', newedge.left_face, newedge.next_left_edge, newedge.prev_left_edge; +#endif +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG ' right:%, next:%, prev:%', newedge.right_face, newedge.next_right_edge, newedge.prev_right_edge; +#endif ---------------------------------------------------------------------- -- @@ -3156,12 +3264,16 @@ BEGIN FROM paths p INNER JOIN faces f ON (p.path = f.path) ORDER BY p.right_side DESC LOOP -- { +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Adding % face', rec.side; +#endif SELECT topology.AddFace(atopology, rec.geom, true) INTO newface; newfaces := array_append(newfaces, newface); END LOOP; --} +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Added faces: %', newfaces; +#endif IF array_upper(newfaces, 1) > 2 THEN -- Sanity check.. @@ -3184,7 +3296,9 @@ BEGIN --RAISE DEBUG 'SQL: %', sql; FOR rec IN EXECUTE sql LOOP +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'TopoGeometry % in layer % contained the face being split (%) - updating to contain both new faces %', rec.topogeo_id, rec.layer_id, newedge.left_face, newfaces; +#endif -- Add reference to the other face sql := 'INSERT INTO ' || quote_ident(atopology) @@ -3329,8 +3443,10 @@ BEGIN || ')' LOOP IF rec.containing_face IS NOT NULL THEN +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'containing_face for node %:%', rec.node_id, rec.containing_face; +#endif IF newedge.left_face IS NULL THEN newedge.left_face := rec.containing_face; newedge.right_face := rec.containing_face; @@ -3435,7 +3551,9 @@ BEGIN -- Find links on start node -- { +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'My start-segment azimuth: %', span.myaz; +#endif sql := 'SELECT edge_id, -1 AS end_node, start_node, left_face, right_face, ' @@ -3481,8 +3599,10 @@ BEGIN rec.edge_id; END IF; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Edge % - az % (%) - fl:% fr:%', rec.edge_id, az, az - span.myaz, rec.left_face, rec.right_face; +#endif az = az - span.myaz; IF az < 0 THEN @@ -3523,7 +3643,9 @@ BEGIN END LOOP; -- incident edges } +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'span ROW_COUNT: %', i; +#endif IF newedge.isclosed THEN IF i < 2 THEN span.was_isolated = true; END IF; ELSE @@ -3539,18 +3661,26 @@ BEGIN newedge.prev_left_edge := -span.nextCCW; END IF; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'edge:%', newedge.edge_id; +#endif +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG ' left:%, next:%, prev:%', newedge.left_face, newedge.next_left_edge, newedge.prev_left_edge; +#endif +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG ' right:%, next:%, prev:%', newedge.right_face, newedge.next_right_edge, newedge.prev_right_edge; +#endif -- } start_node analysis -- Find links on end_node { +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'My end-segment azimuth: %', epan.myaz; +#endif sql := 'SELECT edge_id, -1 as end_node, start_node, left_face, right_face, ' @@ -3592,7 +3722,9 @@ BEGIN END IF; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Edge % - az % (%)', rec.edge_id, az, az - epan.myaz; +#endif az := az - epan.myaz; IF az < 0 THEN @@ -3633,7 +3765,9 @@ BEGIN END LOOP; -- incident edges } +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'epan ROW_COUNT: %', i; +#endif IF newedge.isclosed THEN IF i < 2 THEN epan.was_isolated = true; END IF; ELSE @@ -3651,11 +3785,17 @@ BEGIN -- } end_node analysis +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'edge:%', newedge.edge_id; +#endif +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG ' left:%, next:%, prev:%', newedge.left_face, newedge.next_left_edge, newedge.prev_left_edge; +#endif +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG ' right:%, next:%, prev:%', newedge.right_face, newedge.next_right_edge, newedge.prev_right_edge; +#endif ---------------------------------------------------------------------- -- @@ -3806,7 +3946,9 @@ BEGIN -- IF newedge.left_face != 0 THEN -- { +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Checking face %', ST_AsText(rec.geom); +#endif -- Skip this if our edge is on the right side IF ST_IsEmpty(ST_GeometryN( @@ -3823,12 +3965,16 @@ BEGIN END IF; -- } +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Adding % face', ST_AsText(rec.geom); +#endif SELECT topology.AddFace(atopology, rec.geom, true) INTO newface; newfaces := array_append(newfaces, newface); END LOOP; --} +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Added face: %', newface; +#endif IF newedge.left_face != 0 THEN -- { @@ -3845,7 +3991,9 @@ BEGIN --RAISE DEBUG 'SQL: %', sql; FOR rec IN EXECUTE sql LOOP +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'TopoGeometry % in layer % contained the face being split (%) - updating to contain also new face %', rec.topogeo_id, rec.layer_id, newedge.left_face, newface; +#endif -- Add reference to the other face sql := 'INSERT INTO ' || quote_ident(atopology) @@ -3976,7 +4124,9 @@ BEGIN END; -- } +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Noding input linework'; +#endif -- -- Node input linework with itself @@ -3990,7 +4140,9 @@ BEGIN WHERE ST_Dimension(geom) = 2 ) as linework INTO STRICT nodededges; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Computed % noded edges', ST_NumGeometries(nodededges); +#endif -- -- Linemerge the resulting edges, to reduce the working set @@ -3999,7 +4151,9 @@ BEGIN -- SELECT ST_LineMerge(nodededges) INTO STRICT nodededges; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Merged edges: %', ST_NumGeometries(nodededges); +#endif -- @@ -4014,7 +4168,9 @@ BEGIN WHERE ST_Dimension(geom) = 1 ) as nodes INTO STRICT points; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Collected % input points', ST_NumGeometries(points); +#endif -- -- Further split edges by points @@ -4029,8 +4185,10 @@ BEGIN END LOOP; SELECT ST_UnaryUnion(nodededges) INTO STRICT nodededges; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Noded edges became % after point-split', ST_NumGeometries(nodededges); +#endif -- -- Collect all nodes (from points and noded linework endpoints) @@ -4049,7 +4207,9 @@ BEGIN SELECT ST_EndPoint(geom) FROM edges ) as endpoints INTO points; +#ifdef POSTGIS_TOPOLOGY_DEBUG RAISE DEBUG 'Total nodes count: %', ST_NumGeometries(points); +#endif -- -- Add all nodes as isolated so that diff --git a/topology/sql/topoelement/topoelement_agg.sql b/topology/sql/topoelement/topoelement_agg.sql.in.c similarity index 100% rename from topology/sql/topoelement/topoelement_agg.sql rename to topology/sql/topoelement/topoelement_agg.sql.in.c diff --git a/topology/sql/topogeometry/totopogeom.sql b/topology/sql/topogeometry/totopogeom.sql.in.c similarity index 100% rename from topology/sql/topogeometry/totopogeom.sql rename to topology/sql/topogeometry/totopogeom.sql.in.c diff --git a/topology/sql/topogeometry/type.sql b/topology/sql/topogeometry/type.sql.in.c similarity index 100% rename from topology/sql/topogeometry/type.sql rename to topology/sql/topogeometry/type.sql.in.c diff --git a/topology/topology.sql.in.c b/topology/topology.sql.in.c index 2fd81aef7..ef8cd57cc 100644 --- a/topology/topology.sql.in.c +++ b/topology/topology.sql.in.c @@ -1879,41 +1879,41 @@ $$ LANGUAGE 'plpgsql' VOLATILE STRICT; --} DropTopology -#include "sql/manage/TopologySummary.sql" -#include "sql/manage/CopyTopology.sql" +#include "sql/manage/TopologySummary.sql.in.c" +#include "sql/manage/CopyTopology.sql.in.c" -- Spatial predicates -#include "sql/predicates.sql" +#include "sql/predicates.sql.in.c" -- Querying -#include "sql/query/getnodebypoint.sql" -#include "sql/query/getedgebypoint.sql" -#include "sql/query/getfacebypoint.sql" +#include "sql/query/getnodebypoint.sql.in.c" +#include "sql/query/getedgebypoint.sql.in.c" +#include "sql/query/getfacebypoint.sql.in.c" -- Populating -#include "sql/populate.sql" -#include "sql/polygonize.sql" +#include "sql/populate.sql.in.c" +#include "sql/polygonize.sql.in.c" -- TopoElement -#include "sql/topoelement/topoelement_agg.sql" +#include "sql/topoelement/topoelement_agg.sql.in.c" -- TopoGeometry -#include "sql/topogeometry/type.sql" -#include "sql/topogeometry/totopogeom.sql" +#include "sql/topogeometry/type.sql.in.c" +#include "sql/topogeometry/totopogeom.sql.in.c" -- GML -#include "sql/gml.sql" +#include "sql/gml.sql.in.c" --=} POSTGIS-SPECIFIC block -- SQL/MM block -#include "sql/sqlmm.sql" +#include "sql/sqlmm.sql.in.c" -- The following file needs getfaceedges_returntype, defined in sqlmm.sql -#include "sql/query/GetRingEdges.sql" +#include "sql/query/GetRingEdges.sql.in.c" --general management -- -#include "sql/manage/ManageHelper.sql" +#include "sql/manage/ManageHelper.sql.in.c" --COMMIT; -- Make sure topology is in database search path -- -- 2.50.1