]> granicus.if.org Git - postgis/commitdiff
Return the last band when the provided band number does not exist.
authorPierre Racine <Pierre.Racine@sbf.ulaval.ca>
Thu, 1 Dec 2011 01:07:58 +0000 (01:07 +0000)
committerPierre Racine <Pierre.Racine@sbf.ulaval.ca>
Thu, 1 Dec 2011 01:07:58 +0000 (01:07 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8269 b70326c6-7e19-0410-871a-916f4a2858ee

raster/scripts/plpgsql/st_pixelaspolygons.sql

index 7d6aa0007dc31f9e191585773836b9f19499ad80..0b02f2e0e8ccede167a8c992c85e110051415e63 100644 (file)
@@ -1,4 +1,4 @@
-----------------------------------------------------------------------
+----------------------------------------------------------------------
 --
 -- $Id$
 --
@@ -27,13 +27,17 @@ CREATE OR REPLACE FUNCTION ST_PixelAsPolygons(rast raster, band integer)
         h integer;
         x integer;
         y integer;
+        numband int;
         result geomvalxy;
     BEGIN
-        SELECT st_width(rast), st_height(rast)
-        INTO w, h;
+        SELECT ST_Width(rast), ST_Height(rast), ST_NumBands(rast)
+        INTO w, h, numband;
+        IF band < numband THEN
+            numband := band;
+        END IF;
         FOR x IN 1..w LOOP
              FOR y IN 1..h LOOP
-                 SELECT ST_PixelAsPolygon(rast, band, x, y), ST_Value(rast, band, x, y), x, y INTO result;
+                 SELECT ST_PixelAsPolygon(rast, numband, x, y), ST_Value(rast, numband, x, y), x, y INTO result;
             RETURN NEXT result;
          END LOOP;
         END LOOP;