[postgis-tickets] r17564 - [raster] Skip NODATA tiles in raster2pgsql.

Darafei komzpa at gmail.com
Fri Jun 28 02:42:49 PDT 2019


Author: komzpa
Date: 2019-06-28 02:42:49 -0700 (Fri, 28 Jun 2019)
New Revision: 17564

Added:
   trunk/raster/test/regress/loader/TiledAutoSkipNoData-post.pl
   trunk/raster/test/regress/loader/TiledAutoSkipNoData-pre.pl
   trunk/raster/test/regress/loader/TiledAutoSkipNoData.opts
   trunk/raster/test/regress/loader/TiledAutoSkipNoData.select.expected
   trunk/raster/test/regress/loader/TiledAutoSkipNoData.select.sql
Modified:
   trunk/NEWS
   trunk/raster/loader/raster2pgsql.c
   trunk/raster/test/regress/Makefile.in
   trunk/raster/test/regress/loader/TiledAuto.opts
Log:
[raster] Skip NODATA tiles in raster2pgsql.

Closes #4442
Closes https://github.com/postgis/postgis/pull/427



Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2019-06-27 20:15:29 UTC (rev 17563)
+++ trunk/NEWS	2019-06-28 09:42:49 UTC (rev 17564)
@@ -89,6 +89,8 @@
   - #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)

Modified: trunk/raster/loader/raster2pgsql.c
===================================================================
--- trunk/raster/loader/raster2pgsql.c	2019-06-27 20:15:29 UTC (rev 17563)
+++ trunk/raster/loader/raster2pgsql.c	2019-06-28 09:42:49 UTC (rev 17564)
@@ -1769,6 +1769,7 @@
 				_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 @@
 
 					/* 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 @@
 				_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,14 +1940,16 @@
 				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;
@@ -1949,7 +1956,8 @@
 				}
 
 				/* add hexwkb to tileset */
-				append_stringbuffer(tileset, hex);
+				if (!tile_is_nodata)
+					append_stringbuffer(tileset, hex);
 
 				GDALClose(hdsDst);
 

Modified: trunk/raster/test/regress/Makefile.in
===================================================================
--- trunk/raster/test/regress/Makefile.in	2019-06-27 20:15:29 UTC (rev 17563)
+++ trunk/raster/test/regress/Makefile.in	2019-06-28 09:42:49 UTC (rev 17564)
@@ -155,7 +155,8 @@
 	loader/Tiled10x10 \
 	loader/Tiled10x10Copy \
 	loader/Tiled8x8 \
-	loader/TiledAuto
+	loader/TiledAuto \
+	loader/TiledAutoSkipNoData
 
 TESTS = $(TEST_FIRST) \
 	$(TEST_METADATA) $(TEST_IO) $(TEST_BASIC_FUNC) \

Modified: trunk/raster/test/regress/loader/TiledAuto.opts
===================================================================
--- trunk/raster/test/regress/loader/TiledAuto.opts	2019-06-27 20:15:29 UTC (rev 17563)
+++ trunk/raster/test/regress/loader/TiledAuto.opts	2019-06-28 09:42:49 UTC (rev 17564)
@@ -1 +1 @@
--t auto -C
+-k -t auto -C

Added: trunk/raster/test/regress/loader/TiledAutoSkipNoData-post.pl
===================================================================
--- trunk/raster/test/regress/loader/TiledAutoSkipNoData-post.pl	                        (rev 0)
+++ trunk/raster/test/regress/loader/TiledAutoSkipNoData-post.pl	2019-06-28 09:42:49 UTC (rev 17564)
@@ -0,0 +1 @@
+unlink "loader/TiledAuto.tif";


Property changes on: trunk/raster/test/regress/loader/TiledAutoSkipNoData-post.pl
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: trunk/raster/test/regress/loader/TiledAutoSkipNoData-pre.pl
===================================================================
--- trunk/raster/test/regress/loader/TiledAutoSkipNoData-pre.pl	                        (rev 0)
+++ trunk/raster/test/regress/loader/TiledAutoSkipNoData-pre.pl	2019-06-28 09:42:49 UTC (rev 17564)
@@ -0,0 +1 @@
+link "loader/testraster2.tif", "loader/TiledAutoSkipNoData.tif";


Property changes on: trunk/raster/test/regress/loader/TiledAutoSkipNoData-pre.pl
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: trunk/raster/test/regress/loader/TiledAutoSkipNoData.opts
===================================================================
--- trunk/raster/test/regress/loader/TiledAutoSkipNoData.opts	                        (rev 0)
+++ trunk/raster/test/regress/loader/TiledAutoSkipNoData.opts	2019-06-28 09:42:49 UTC (rev 17564)
@@ -0,0 +1 @@
+-t auto -C

Added: trunk/raster/test/regress/loader/TiledAutoSkipNoData.select.expected
===================================================================
--- trunk/raster/test/regress/loader/TiledAutoSkipNoData.select.expected	                        (rev 0)
+++ trunk/raster/test/regress/loader/TiledAutoSkipNoData.select.expected	2019-06-28 09:42:49 UTC (rev 17564)
@@ -0,0 +1 @@
+28

Added: trunk/raster/test/regress/loader/TiledAutoSkipNoData.select.sql
===================================================================
--- trunk/raster/test/regress/loader/TiledAutoSkipNoData.select.sql	                        (rev 0)
+++ trunk/raster/test/regress/loader/TiledAutoSkipNoData.select.sql	2019-06-28 09:42:49 UTC (rev 17564)
@@ -0,0 +1 @@
+select count(*) from loadedrast;



More information about the postgis-tickets mailing list