From ee40807c5adedf6028fff57fda2f5a4a54a29fa2 Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Wed, 24 Oct 2012 19:22:46 +0000 Subject: [PATCH] Have ST_Tile() generate out-of-db tile bands if input raster's band is out-of-db. git-svn-id: http://svn.osgeo.org/postgis/trunk@10546 b70326c6-7e19-0410-871a-916f4a2858ee --- doc/reference_raster.xml | 6 +++ raster/rt_pg/rt_pg.c | 97 ++++++++++++++++++++++++++-------------- 2 files changed, 70 insertions(+), 33 deletions(-) diff --git a/doc/reference_raster.xml b/doc/reference_raster.xml index 1f3c3b882..2782bc670 100644 --- a/doc/reference_raster.xml +++ b/doc/reference_raster.xml @@ -1615,6 +1615,12 @@ FROM (SELECT rid, ST_MetaData(rast) As md Returns a set of rasters resulting from the split of the input raster based upon the desired dimensions of the output rasters. + + + If a specified band of the input raster is out-of-db, the corresponding band in the output rasters will also be out-of-db. + + + Availability: 2.1.0 diff --git a/raster/rt_pg/rt_pg.c b/raster/rt_pg/rt_pg.c index ced9e67ad..1f28133ea 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -5661,42 +5661,72 @@ Datum RASTER_tile(PG_FUNCTION_ARGS) else nodataval = rt_band_get_min_value(_band); - if (rt_raster_generate_new_band(tile, pixtype, nodataval, hasnodata, nodataval, i) < 0) { - elog(ERROR, "RASTER_tile: Unable to add new band to output tile"); - rt_raster_destroy(tile); - rt_raster_destroy(arg2->raster.raster); - pfree(arg2->nbands); - pfree(arg2); - SRF_RETURN_DONE(funcctx); - } - band = rt_raster_get_band(tile, i); - if (band == NULL) { - 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); - pfree(arg2); - SRF_RETURN_DONE(funcctx); - } + /* inline band */ + if (!rt_band_is_offline(_band)) { + if (rt_raster_generate_new_band(tile, pixtype, nodataval, hasnodata, nodataval, i) < 0) { + elog(ERROR, "RASTER_tile: Unable to add new band to output tile"); + rt_raster_destroy(tile); + rt_raster_destroy(arg2->raster.raster); + pfree(arg2->nbands); + pfree(arg2); + SRF_RETURN_DONE(funcctx); + } + band = rt_raster_get_band(tile, i); + if (band == NULL) { + 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); + pfree(arg2); + SRF_RETURN_DONE(funcctx); + } - /* if isnodata, set flag and continue */ - if (rt_band_get_isnodata_flag(_band)) { - rt_band_set_isnodata_flag(band, 1); - continue; - } + /* if isnodata, set flag and continue */ + if (rt_band_get_isnodata_flag(_band)) { + rt_band_set_isnodata_flag(band, 1); + continue; + } - /* copy data */ - for (j = 0; j < arg2->tile.height; j++) { - k = ry + j; + /* copy data */ + for (j = 0; j < arg2->tile.height; j++) { + k = ry + j; - if (k >= arg2->raster.height) { - POSTGIS_RT_DEBUGF(4, "row %d is beyond extent of source raster. skipping", k); - continue; + if (k >= arg2->raster.height) { + POSTGIS_RT_DEBUGF(4, "row %d is beyond extent of source raster. skipping", k); + continue; + } + + POSTGIS_RT_DEBUGF(4, "getting pixel line %d, %d for %d pixels", rx, k, len); + if (rt_band_get_pixel_line(_band, rx, k, len, &vals, &nvals) != 0) { + 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); + pfree(arg2); + SRF_RETURN_DONE(funcctx); + } + + if (nvals && !rt_band_set_pixel_line(band, 0, j, vals, nvals)) { + 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); + pfree(arg2); + SRF_RETURN_DONE(funcctx); + } } + } + /* offline */ + else { + band = rt_band_new_offline( + arg2->raster.width, arg2->raster.height, + pixtype, + hasnodata, nodataval, + rt_band_get_ext_band_num(_band), rt_band_get_ext_path(_band) + ); - POSTGIS_RT_DEBUGF(4, "getting pixel line %d, %d for %d pixels", rx, k, len); - if (rt_band_get_pixel_line(_band, rx, k, len, &vals, &nvals) != 0) { - elog(ERROR, "RASTER_tile: Unable to get pixel line from source raster"); + if (band == NULL) { + 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); @@ -5704,8 +5734,9 @@ Datum RASTER_tile(PG_FUNCTION_ARGS) SRF_RETURN_DONE(funcctx); } - if (nvals && !rt_band_set_pixel_line(band, 0, j, vals, nvals)) { - elog(ERROR, "RASTER_tile: Unable to set pixel line of output tile"); + if (rt_raster_add_band(tile, band, i) < 0) { + elog(ERROR, "RASTER_tile: Unable to add new offline band to output tile"); + rt_band_destroy(band); rt_raster_destroy(tile); rt_raster_destroy(arg2->raster.raster); pfree(arg2->nbands); -- 2.50.1