]> granicus.if.org Git - postgis/commitdiff
Have ST_Tile() generate out-of-db tile bands if input raster's band is
authorBborie Park <bkpark at ucdavis.edu>
Wed, 24 Oct 2012 19:22:46 +0000 (19:22 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Wed, 24 Oct 2012 19:22:46 +0000 (19:22 +0000)
out-of-db.

git-svn-id: http://svn.osgeo.org/postgis/trunk@10546 b70326c6-7e19-0410-871a-916f4a2858ee

doc/reference_raster.xml
raster/rt_pg/rt_pg.c

index 1f3c3b882d2f94773cb86f3440ca51fa1691611c..2782bc670d3412f30f9bc52c472f4914cdb1566d 100644 (file)
@@ -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.
                                </para>
 
+                               <note>
+                                       <para>
+                                               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.
+                                       </para>
+                               </note>
+
                                <para>Availability: 2.1.0</para>
                        </refsection>
 
index ced9e67ad05e0f096b367fc5dcef51d78621b58d..1f28133eac79041ab6d8cb4efd3cd1bf7665d12f 100644 (file)
@@ -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);