From: Bborie Park Date: Thu, 3 Oct 2013 03:18:49 +0000 (+0000) Subject: Fixed behavior of ST_DumpValues(raster, ...) when passed an empty raster. Ticket... X-Git-Tag: 2.2.0rc1~1351 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=584b28065df75b4ea0c16e9ac80827711c536f6b;p=postgis Fixed behavior of ST_DumpValues(raster, ...) when passed an empty raster. Ticket #2493 git-svn-id: http://svn.osgeo.org/postgis/trunk@11996 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index 7384b698a..79780f175 100644 --- 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 diff --git a/raster/rt_pg/rtpg_pixel.c b/raster/rt_pg/rtpg_pixel.c index 3c21940c0..8c6700a89 100644 --- a/raster/rt_pg/rtpg_pixel.c +++ b/raster/rt_pg/rtpg_pixel.c @@ -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 );