]> granicus.if.org Git - postgis/commitdiff
[raster] Skip NODATA tiles in raster2pgsql.
authorDarafei Praliaskouski <me@komzpa.net>
Fri, 28 Jun 2019 09:42:49 +0000 (09:42 +0000)
committerDarafei Praliaskouski <me@komzpa.net>
Fri, 28 Jun 2019 09:42:49 +0000 (09:42 +0000)
Closes #4442
Closes https://github.com/postgis/postgis/pull/427

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

NEWS
raster/loader/raster2pgsql.c
raster/test/regress/Makefile.in
raster/test/regress/loader/TiledAuto.opts
raster/test/regress/loader/TiledAutoSkipNoData-post.pl [new file with mode: 0755]
raster/test/regress/loader/TiledAutoSkipNoData-pre.pl [new file with mode: 0755]
raster/test/regress/loader/TiledAutoSkipNoData.opts [new file with mode: 0644]
raster/test/regress/loader/TiledAutoSkipNoData.select.expected [new file with mode: 0644]
raster/test/regress/loader/TiledAutoSkipNoData.select.sql [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 9efbec41c8a7b0b0fc677d1a06791eea01f76d72..4a02ffc9d744d64c922bd4d7acff7bdc255e21c0 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -89,6 +89,8 @@ PostGIS 3.0.0
   - #4356, ST_Accum removed. Use array_agg instead. (Darafei Praliaskouski)
   - #4414, Include version number in address_standardizer lib (Raúl Marín)
   - #4334, Fix upgrade issues related to renamed function parameters (Raúl Marín)
+  - #4442, raster2pgsql now skips NODATA tiles. Use -k option if you still want
+           them in database for some reason. (Darafei Praliaskouski)
 
 * New Features *
   - #2902, postgis_geos_noop (Sandro Santilli)
index 4d57db6407418d8669e8f8b6d509e1f1853628b6..1b1199c89663633ef6d2b447bf360bd378995d8c 100644 (file)
@@ -1769,6 +1769,7 @@ convert_raster(int idx, RTLOADERCFG *config, RASTERINFO *info, STRINGBUFFER *til
                                _tile_size[1] = info->tile_size[1];
 
                        for (xtile = 0; xtile < ntiles[0]; xtile++) {
+                               int tile_is_nodata = !config->skip_nodataval_check;
 
                                /* edge x tile */
                                if (!config->pad_tile && ntiles[0] > 1 && (xtile + 1) == ntiles[0])
@@ -1819,20 +1820,23 @@ convert_raster(int idx, RTLOADERCFG *config, RASTERINFO *info, STRINGBUFFER *til
 
                                        /* inspect each band of raster where band is NODATA */
                                        if (!config->skip_nodataval_check)
-                                               rt_band_check_is_nodata(band);
+                                               tile_is_nodata = tile_is_nodata && rt_band_check_is_nodata(band);
                                }
 
                                /* convert rt_raster to hexwkb */
-                               hex = rt_raster_to_hexwkb(rast, FALSE, &hexlen);
+                               if (!tile_is_nodata)
+                                       hex = rt_raster_to_hexwkb(rast, FALSE, &hexlen);
                                raster_destroy(rast);
 
-                               if (hex == NULL) {
+                               if (!hex && !tile_is_nodata)
+                               {
                                        rterror(_("convert_raster: Could not convert PostGIS raster to hex WKB"));
                                        return 0;
                                }
 
                                /* add hexwkb to tileset */
-                               append_stringbuffer(tileset, hex);
+                               if (!tile_is_nodata)
+                                       append_stringbuffer(tileset, hex);
 
                                /* flush if tileset gets too big */
                                if (tileset->length > 10) {
@@ -1866,6 +1870,7 @@ convert_raster(int idx, RTLOADERCFG *config, RASTERINFO *info, STRINGBUFFER *til
                                _tile_size[1] = info->tile_size[1];
 
                        for (xtile = 0; xtile < ntiles[0]; xtile++) {
+                               int tile_is_nodata = !config->skip_nodataval_check;
                                /*
                                char fn[100];
                                sprintf(fn, "/tmp/tile%d.vrt", (ytile * ntiles[0]) + xtile);
@@ -1935,21 +1940,24 @@ convert_raster(int idx, RTLOADERCFG *config, RASTERINFO *info, STRINGBUFFER *til
                                for (i = 0; i < numbands; i++) {
                                        band = rt_raster_get_band(rast, i);
                                        if (band != NULL && !config->skip_nodataval_check)
-                                               rt_band_check_is_nodata(band);
+                                               tile_is_nodata = tile_is_nodata && rt_band_check_is_nodata(band);
                                }
 
                                /* convert rt_raster to hexwkb */
-                               hex = rt_raster_to_hexwkb(rast, FALSE, &hexlen);
+                               if (!tile_is_nodata)
+                                       hex = rt_raster_to_hexwkb(rast, FALSE, &hexlen);
                                raster_destroy(rast);
 
-                               if (hex == NULL) {
+                               if (!hex && !tile_is_nodata)
+                               {
                                        rterror(_("convert_raster: Could not convert PostGIS raster to hex WKB"));
                                        GDALClose(hdsDst);
                                        return 0;
                                }
 
                                /* add hexwkb to tileset */
-                               append_stringbuffer(tileset, hex);
+                               if (!tile_is_nodata)
+                                       append_stringbuffer(tileset, hex);
 
                                GDALClose(hdsDst);
 
index 44a006c932f80d38f271356838fb3b7a3600f00f..c0b139ef14b244f5b00a01f420f6189e4087f11c 100644 (file)
@@ -155,7 +155,8 @@ TEST_LOADER = \
        loader/Tiled10x10 \
        loader/Tiled10x10Copy \
        loader/Tiled8x8 \
-       loader/TiledAuto
+       loader/TiledAuto \
+       loader/TiledAutoSkipNoData
 
 TESTS = $(TEST_FIRST) \
        $(TEST_METADATA) $(TEST_IO) $(TEST_BASIC_FUNC) \
index 96fbc855ce364840914cca66b1ea9a7f57b142f2..88c34c0830495991f20737a4f9bdfff034b5646e 100644 (file)
@@ -1 +1 @@
--t auto -C
+-k -t auto -C
diff --git a/raster/test/regress/loader/TiledAutoSkipNoData-post.pl b/raster/test/regress/loader/TiledAutoSkipNoData-post.pl
new file mode 100755 (executable)
index 0000000..97227db
--- /dev/null
@@ -0,0 +1 @@
+unlink "loader/TiledAuto.tif";
diff --git a/raster/test/regress/loader/TiledAutoSkipNoData-pre.pl b/raster/test/regress/loader/TiledAutoSkipNoData-pre.pl
new file mode 100755 (executable)
index 0000000..78c6cfa
--- /dev/null
@@ -0,0 +1 @@
+link "loader/testraster2.tif", "loader/TiledAutoSkipNoData.tif";
diff --git a/raster/test/regress/loader/TiledAutoSkipNoData.opts b/raster/test/regress/loader/TiledAutoSkipNoData.opts
new file mode 100644 (file)
index 0000000..96fbc85
--- /dev/null
@@ -0,0 +1 @@
+-t auto -C
diff --git a/raster/test/regress/loader/TiledAutoSkipNoData.select.expected b/raster/test/regress/loader/TiledAutoSkipNoData.select.expected
new file mode 100644 (file)
index 0000000..9902f17
--- /dev/null
@@ -0,0 +1 @@
+28
diff --git a/raster/test/regress/loader/TiledAutoSkipNoData.select.sql b/raster/test/regress/loader/TiledAutoSkipNoData.select.sql
new file mode 100644 (file)
index 0000000..81d8317
--- /dev/null
@@ -0,0 +1 @@
+select count(*) from loadedrast;