From: Darafei Praliaskouski Date: Fri, 28 Jun 2019 09:42:49 +0000 (+0000) Subject: [raster] Skip NODATA tiles in raster2pgsql. X-Git-Tag: 3.0.0alpha3~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6b96e49010918d3faaf0358971b36461ee45305b;p=postgis [raster] Skip NODATA tiles in raster2pgsql. 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 --- diff --git a/NEWS b/NEWS index 9efbec41c..4a02ffc9d 100644 --- 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) diff --git a/raster/loader/raster2pgsql.c b/raster/loader/raster2pgsql.c index 4d57db640..1b1199c89 100644 --- a/raster/loader/raster2pgsql.c +++ b/raster/loader/raster2pgsql.c @@ -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); diff --git a/raster/test/regress/Makefile.in b/raster/test/regress/Makefile.in index 44a006c93..c0b139ef1 100644 --- a/raster/test/regress/Makefile.in +++ b/raster/test/regress/Makefile.in @@ -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) \ diff --git a/raster/test/regress/loader/TiledAuto.opts b/raster/test/regress/loader/TiledAuto.opts index 96fbc855c..88c34c083 100644 --- a/raster/test/regress/loader/TiledAuto.opts +++ b/raster/test/regress/loader/TiledAuto.opts @@ -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 index 000000000..97227db32 --- /dev/null +++ b/raster/test/regress/loader/TiledAutoSkipNoData-post.pl @@ -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 index 000000000..78c6cfae5 --- /dev/null +++ b/raster/test/regress/loader/TiledAutoSkipNoData-pre.pl @@ -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 index 000000000..96fbc855c --- /dev/null +++ b/raster/test/regress/loader/TiledAutoSkipNoData.opts @@ -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 index 000000000..9902f1784 --- /dev/null +++ b/raster/test/regress/loader/TiledAutoSkipNoData.select.expected @@ -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 index 000000000..81d831770 --- /dev/null +++ b/raster/test/regress/loader/TiledAutoSkipNoData.select.sql @@ -0,0 +1 @@ +select count(*) from loadedrast;