From: Pierre Racine Date: Thu, 1 Dec 2011 01:07:58 +0000 (+0000) Subject: Return the last band when the provided band number does not exist. X-Git-Tag: 2.0.0alpha1~596 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=029834ee697036fe0fe7427a2df627ed39cf7287;p=postgis Return the last band when the provided band number does not exist. git-svn-id: http://svn.osgeo.org/postgis/trunk@8269 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/scripts/plpgsql/st_pixelaspolygons.sql b/raster/scripts/plpgsql/st_pixelaspolygons.sql index 7d6aa0007..0b02f2e0e 100644 --- a/raster/scripts/plpgsql/st_pixelaspolygons.sql +++ b/raster/scripts/plpgsql/st_pixelaspolygons.sql @@ -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;