]> granicus.if.org Git - postgis/commitdiff
Have ST_GetFaceGeometry check face existance, regress-test
authorSandro Santilli <strk@keybit.net>
Thu, 23 Feb 2012 12:54:48 +0000 (12:54 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 23 Feb 2012 12:54:48 +0000 (12:54 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9276 b70326c6-7e19-0410-871a-916f4a2858ee

topology/sql/sqlmm.sql.in.c
topology/test/regress/st_getfacegeometry.sql
topology/test/regress/st_getfacegeometry_expected

index 38a2a16f31d29566a9244e16ecdd2a71d59a6597..704c5b9bc5ab810989f70d63d7f86f88e36683f9 100644 (file)
@@ -1408,6 +1408,7 @@ CREATE OR REPLACE FUNCTION topology.ST_GetFaceGeometry(toponame varchar, aface i
 $$
 DECLARE
   rec RECORD;
+  sql TEXT;
 BEGIN
 
   --
@@ -1426,30 +1427,38 @@ BEGIN
       'SQL/MM Spatial exception - universal face has no geometry';
   END IF;
 
-  --
-  -- Construct face 
-  -- 
   BEGIN
-    FOR rec IN EXECUTE 'SELECT ST_BuildArea(ST_Collect(geom)) FROM '
+
+    -- No such face
+    sql := 'SELECT NOT EXISTS (SELECT * from ' || quote_ident(toponame)
+      || '.face WHERE face_id = ' || aface
+      || ') as none';
+    EXECUTE sql INTO rec;
+    IF rec.none THEN
+      RAISE EXCEPTION 'SQL/MM Spatial exception - non-existent face.';
+    END IF;
+
+    --
+    -- Construct face 
+    -- 
+    sql :=
+      'SELECT ST_BuildArea(ST_Collect(geom)) as geom FROM '
       || quote_ident(toponame)
-      || '.edge_data WHERE left_face = ' || aface || 
-      ' OR right_face = ' || aface 
+      || '.edge_data WHERE left_face = ' || aface
+      || ' OR right_face = ' || aface;
+    FOR rec IN EXECUTE sql
     LOOP
-      RETURN rec.st_buildarea;
+      RETURN rec.geom;
     END LOOP;
+
   EXCEPTION
     WHEN INVALID_SCHEMA_NAME THEN
       RAISE EXCEPTION 'SQL/MM Spatial exception - invalid topology name';
     WHEN UNDEFINED_TABLE THEN
-      RAISE EXCEPTION 'corrupted topology "%" (missing edge_data table)',
-        toponame;
+      RAISE EXCEPTION 'corrupted topology "%"', toponame;
   END;
 
-
-  --
-  -- No face found
-  -- 
-  RAISE EXCEPTION 'SQL/MM Spatial exception - non-existent face.';
+  RETURN NULL;
 END
 $$
 LANGUAGE 'plpgsql' STABLE;
index edac609424d3c0a3bcb5c938cc6002ec0377417e..2bb2c13977c3de2cba1acd3fddb706d8e747cc7c 100644 (file)
@@ -41,4 +41,7 @@ SELECT topology.st_getfacegeometry('tt', null);
 SELECT topology.st_getfacegeometry('NonExistent', 1);
 SELECT topology.st_getfacegeometry('', 1);
 
+-- Non-existent face
+SELECT topology.st_getfacegeometry('tt', 666);
+
 SELECT topology.DropTopology('tt');
index 7bd616c77fa1d0b9a217f24cf50d5a58ec987745..7516763996ca4141af5299ba58aef313400a5238 100644 (file)
@@ -6,4 +6,5 @@ ERROR:  SQL/MM Spatial exception - null argument
 ERROR:  SQL/MM Spatial exception - null argument
 ERROR:  SQL/MM Spatial exception - invalid topology name
 ERROR:  SQL/MM Spatial exception - invalid topology name
+ERROR:  SQL/MM Spatial exception - non-existent face.
 Topology 'tt' dropped