]> granicus.if.org Git - postgis/commitdiff
Simplify the code looking for face containment in ST_AddIsoNode
authorSandro Santilli <strk@keybit.net>
Fri, 27 Jan 2012 11:05:35 +0000 (11:05 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 27 Jan 2012 11:05:35 +0000 (11:05 +0000)
Fixes bug #1503 for me, altough I didn't handle to produce a
testcase for it.

git-svn-id: http://svn.osgeo.org/postgis/trunk@8941 b70326c6-7e19-0410-871a-916f4a2858ee

topology/sql/sqlmm.sql.in.c

index cb23c56ef018072dd98e3b6cf70499f294b38db1..693c20f65def339bf3315422efb3bed900a54752 100644 (file)
@@ -1538,38 +1538,26 @@ BEGIN
         --
         -- probably there is something so now check the exact test
         --    
-    sql := 'SELECT e.face_id FROM ('
-      || 'SELECT d.face_id,ST_BuildArea(ST_Union(geom)) as geom FROM ('
-      || 'SELECT b.edge_id as edge_id,b.left_face as face_id,b.geom as geom FROM '
-      || quote_ident(atopology) || '.edge_data as b,'
-      || '(SELECT a.face_id FROM '
-      || quote_ident(atopology) || '.face as a '
-      || 'WHERE ST_Intersects(a.mbr,' || quote_literal(apoint::text)||'::geometry)=true'
-      || ') as c '
-      || 'WHERE (b.left_face = c.face_id) '
-      || ' UNION ALL '
-      || 'SELECT b.edge_id as edge_id, b.right_face as face_id, b.geom as geom FROM '
-      || quote_ident(atopology) || '.edge_data as b,'
-      || '(SELECT a.face_id FROM '
-      || quote_ident(atopology) || '.face as a '
-      || 'WHERE ST_Intersects(a.mbr,' || quote_literal(apoint::text)||'::geometry)=true'
-      || ') as c '
-      || 'WHERE (b.right_face = c.face_id) '
-      || ') as d '
-      || 'GROUP BY face_id '
-      || ') as e '
-      || 'WHERE ST_Intersects(e.geom, ' || quote_literal(apoint::text)||'::geometry)=true;';
-
-        --raise notice ' ==> %',sql;
-        BEGIN
-            EXECUTE sql INTO STRICT containingface;
-                EXCEPTION
-                    WHEN NO_DATA_FOUND THEN
-                        containingface = 0;
-                    WHEN TOO_MANY_ROWS THEN
-                        RAISE EXCEPTION 'Two or more faces found';
-        END;
-    END IF;
+    sql := 'SELECT face_id FROM '
+      || quote_ident(atopology) || '.face WHERE face_id > 0 AND mbr && '
+      || quote_literal(apoint::text) || '::geometry AND ST_Contains(topology.ST_GetFaceGeometry('
+      || quote_literal(atopology) || ', face_id), '
+      || quote_literal(apoint::text) || '::geometry)';
+#ifdef POSTGIS_TOPOLOGY_DEBUG
+    RAISE DEBUG ' ==> %',sql;
+#endif
+    BEGIN
+      EXECUTE sql INTO STRICT containingface;
+      EXCEPTION
+        WHEN NO_DATA_FOUND THEN
+#ifdef POSTGIS_TOPOLOGY_DEBUG
+          RAISE DEBUG 'No faces contain point';
+#endif
+          containingface = 0;
+        WHEN TOO_MANY_ROWS THEN
+          RAISE EXCEPTION 'Two or more faces found';
+    END;
+  END IF;
 
   --
   -- Verify that aface contains apoint