Added support for no-band rasters to ST_Tile(raster)

git-svn-id: http://svn.osgeo.org/postgis/trunk@10838 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
Bborie Park 2012-12-14 20:27:21 +00:00
parent b336b4b201
commit ed72bde7d3

View file

@ -5444,6 +5444,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
/* raster has bands */
numbands = rt_raster_get_num_bands(arg1->raster.raster);
/*
if (!numbands) {
elog(NOTICE, "Raster provided has no bands");
rt_raster_destroy(arg1->raster.raster);
@ -5452,6 +5453,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
*/
/* width (1) */
if (PG_ARGISNULL(1)) {
@ -5492,7 +5494,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
}
/* nband, array (3) */
if (!PG_ARGISNULL(3)) {
if (numbands && !PG_ARGISNULL(3)) {
array = PG_GETARG_ARRAYTYPE_P(3);
etype = ARR_ELEMTYPE(array);
get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
@ -5567,6 +5569,8 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
}
else {
arg1->numbands = numbands;
if (numbands) {
arg1->nbands = palloc(sizeof(int) * arg1->numbands);
if (arg1->nbands == NULL) {
@ -5583,6 +5587,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
POSTGIS_RT_DEBUGF(4, "arg1->nbands[%d] = %d", arg1->nbands[i], i);
}
}
}
/* pad (4) and padnodata (5) */
if (!PG_ARGISNULL(4)) {
@ -5706,7 +5711,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
elog(ERROR, "RASTER_tile: Unable to compute the coordinates of the upper-left corner of the output tile");
rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster);
pfree(arg2->nbands);
if (arg2->numbands) pfree(arg2->nbands);
pfree(arg2);
SRF_RETURN_DONE(funcctx);
}
@ -5728,7 +5733,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
elog(ERROR, "RASTER_tile: Unable to get band %d from source raster", arg2->nbands[i] + 1);
rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster);
pfree(arg2->nbands);
if (arg2->numbands) pfree(arg2->nbands);
pfree(arg2);
SRF_RETURN_DONE(funcctx);
}
@ -5759,7 +5764,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
elog(ERROR, "RASTER_tile: Unable to get newly added band from output tile");
rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster);
pfree(arg2->nbands);
if (arg2->numbands) pfree(arg2->nbands);
pfree(arg2);
SRF_RETURN_DONE(funcctx);
}
@ -5784,7 +5789,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
elog(ERROR, "RASTER_tile: Unable to get pixel line from source raster");
rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster);
pfree(arg2->nbands);
if (arg2->numbands) pfree(arg2->nbands);
pfree(arg2);
SRF_RETURN_DONE(funcctx);
}
@ -5793,7 +5798,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
elog(ERROR, "RASTER_tile: Unable to set pixel line of output tile");
rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster);
pfree(arg2->nbands);
if (arg2->numbands) pfree(arg2->nbands);
pfree(arg2);
SRF_RETURN_DONE(funcctx);
}
@ -5815,7 +5820,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
elog(ERROR, "RASTER_tile: Unable to create new offline band for output tile");
rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster);
pfree(arg2->nbands);
if (arg2->numbands) pfree(arg2->nbands);
pfree(arg2);
SRF_RETURN_DONE(funcctx);
}
@ -5825,7 +5830,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
rt_band_destroy(band);
rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster);
pfree(arg2->nbands);
if (arg2->numbands) pfree(arg2->nbands);
pfree(arg2);
SRF_RETURN_DONE(funcctx);
}
@ -5836,7 +5841,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
rt_raster_destroy(tile);
if (!pgtile) {
rt_raster_destroy(arg2->raster.raster);
pfree(arg2->nbands);
if (arg2->numbands) pfree(arg2->nbands);
pfree(arg2);
SRF_RETURN_DONE(funcctx);
}
@ -5847,7 +5852,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
/* do when there is no more left */
else {
rt_raster_destroy(arg2->raster.raster);
pfree(arg2->nbands);
if (arg2->numbands) pfree(arg2->nbands);
pfree(arg2);
SRF_RETURN_DONE(funcctx);
}