]> granicus.if.org Git - postgis/commitdiff
Fixed behavior of ST_DumpValues(raster, ...) when passed an empty raster. Ticket...
authorBborie Park <bkpark at ucdavis.edu>
Thu, 3 Oct 2013 03:18:49 +0000 (03:18 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Thu, 3 Oct 2013 03:18:49 +0000 (03:18 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@11996 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
raster/rt_pg/rtpg_pixel.c

diff --git a/NEWS b/NEWS
index 7384b698a78c72f10ae4909dd08c06dd92315e8f..79780f1750e0e8258031f61e46be87dc919b614b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -27,6 +27,7 @@ PostGIS 2.2.0
   - #2384, Fixed variable datatype in ST_Neighborhood
   - #2454, Fix behavior of ST_PixelAsXXX functions regarding
            exclude_nodata_value parameter
+  - #2493, Fix behavior of ST_DumpValues when passed an empty raster
 
 PostGIS 2.1.0
 2013/MM/DD
index 3c21940c0e21f37f9312a9bfb361362bd30f13ef..8c6700a891ad01e83f18f09a9704171751fef16c 100644 (file)
@@ -257,6 +257,7 @@ Datum RASTER_dumpValues(PG_FUNCTION_ARGS)
                }
 
                /* check that raster is not empty */
+               /*
                if (rt_raster_is_empty(raster)) {
                        elog(NOTICE, "Raster provided is empty");
                        rt_raster_destroy(raster);
@@ -264,6 +265,7 @@ Datum RASTER_dumpValues(PG_FUNCTION_ARGS)
                        MemoryContextSwitchTo(oldcontext);
                        SRF_RETURN_DONE(funcctx);
                }
+               */
 
                /* raster has bands */
                numbands = rt_raster_get_num_bands(raster); 
@@ -402,6 +404,10 @@ Datum RASTER_dumpValues(PG_FUNCTION_ARGS)
 
                /* get each band and dump data */
                for (z = 0; z < arg1->numbands; z++) {
+                       /* shortcut if raster is empty */
+                       if (rt_raster_is_empty(raster))
+                               break;
+
                        band = rt_raster_get_band(raster, arg1->nbands[z]);
                        if (!band) {
                                int nband = arg1->nbands[z] + 1;
@@ -509,6 +515,7 @@ Datum RASTER_dumpValues(PG_FUNCTION_ARGS)
                HeapTuple tuple;
                Datum result;
                ArrayType *mdValues = NULL;
+               int ndim = 2;
                int dim[2] = {arg2->rows, arg2->columns};
                int lbound[2] = {1, 1};
 
@@ -522,10 +529,14 @@ Datum RASTER_dumpValues(PG_FUNCTION_ARGS)
                /* info about the type of item in the multi-dimensional array (float8). */
                get_typlenbyvalalign(FLOAT8OID, &typlen, &typbyval, &typalign);
 
+               /* if values is NULL, return empty array */
+               if (arg2->values[call_cntr] == NULL)
+                       ndim = 0;
+
                /* assemble 3-dimension array of values */
                mdValues = construct_md_array(
                        arg2->values[call_cntr], arg2->nodata[call_cntr],
-                       2, dim, lbound,
+                       ndim, dim, lbound,
                        FLOAT8OID,
                        typlen, typbyval, typalign
                );