From: Bborie Park Date: Tue, 31 Jul 2012 23:44:16 +0000 (+0000) Subject: Added regression tests and docs for two of the ST_SetValues variants X-Git-Tag: 2.1.0beta2~724 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7eef12ba617ded502b726767e5d80fe4629123b9;p=postgis Added regression tests and docs for two of the ST_SetValues variants git-svn-id: http://svn.osgeo.org/postgis/trunk@10148 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index 2794db525..ed2ecb78a 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,8 @@ PostGIS 2.1.0 (ST_Contains, ST_ContainsProperly, ST_Covers, ST_CoveredBy, ST_Disjoint, ST_Overlaps, ST_Touches, ST_Within, ST_DWithin, ST_DFullyWithin) (Bborie Park / UC Davis) + - Added array variants of ST_SetValues() to set many pixel values of a band + in one call (Bborie Park / UC Davis) - #1643, Tiger Geocoder - Tiger 2011 loader (Regina Obe / Paragon Corporation) Funded by Hunter Systems Group - GEOMETRYCOLLECTION support for ST_MakeValid (Sandro Santilli / Vizzuality) diff --git a/doc/reference_raster.xml b/doc/reference_raster.xml index 47dee238e..540a39019 100644 --- a/doc/reference_raster.xml +++ b/doc/reference_raster.xml @@ -4004,6 +4004,345 @@ GROUP BY (foo.geomval).val; + + + ST_SetValues + Returns modified raster resulting from setting the values of a given band. + + + + + + raster ST_SetValues + raster rast + integer nband + integer columnx + integer rowy + double precision[][] newvalueset + boolean[][] noset=NULL + boolean keepnodata=FALSE + + + + raster ST_SetValues + raster rast + integer nband + integer columnx + integer rowy + integer width + integer height + double precision newvalue + boolean keepnodata=FALSE + + + + + + + Description + + Returns modified raster resulting from setting specified pixels to new value(s) for the designated band. + + + + For variant 1, the specific pixels to be set are determined by the columnx, rowy pixel coordinates and the dimensions of the newvalueset array. noset can be used to prevent pixels with values present in newvalueset from being set (due to PostgreSQL not permitting ragged/jagged arrays). If keepnodata is TRUE, those pixels whose values are NODATA will not be set with the corresponding value in newvalueset. See example Variant 1. + + + + For variant 2, the specific pixels to be set are determined by the columnx, rowy pixel coordinates, width and height. If keepnodata is TRUE, those pixels whose values are NODATA will not be set with the corresponding value in newvalueset. See example Variant 2. + + + + + + Examples: Variant 1 + + +/* +The ST_SetValues() does the following... + ++ - + - + - + + - + - + - + +| 1 | 1 | 1 | | 1 | 1 | 1 | ++ - + - + - + + - + - + - + +| 1 | 1 | 1 | => | 1 | 9 | 9 | ++ - + - + - + + - + - + - + +| 1 | 1 | 1 | | 1 | 9 | 9 | ++ - + - + - + + - + - + - + +*/ +SELECT + (poly).x, + (poly).y, + (poly).val +FROM ( +SELECT + ST_PixelAsPolygons( + ST_SetValues( + ST_AddBand( + ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0), + 1, '8BUI', 1, 0 + ), + 1, 2, 2, ARRAY[[9, 9], [9, 9]]::double precision[][] + ) + ) AS poly +) foo +ORDER BY 1, 2; + + x | y | val +---+---+----- + 1 | 1 | 1 + 1 | 2 | 1 + 1 | 3 | 1 + 2 | 1 | 1 + 2 | 2 | 9 + 2 | 3 | 9 + 3 | 1 | 1 + 3 | 2 | 9 + 3 | 3 | 9 + + + +/* +The ST_SetValues() does the following... + ++ - + - + - + + - + - + - + +| 1 | 1 | 1 | | 9 | 9 | 9 | ++ - + - + - + + - + - + - + +| 1 | 1 | 1 | => | 9 | | 9 | ++ - + - + - + + - + - + - + +| 1 | 1 | 1 | | 9 | 9 | 9 | ++ - + - + - + + - + - + - + +*/ +SELECT + (poly).x, + (poly).y, + (poly).val +FROM ( +SELECT + ST_PixelAsPolygons( + ST_SetValues( + ST_AddBand( + ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0), + 1, '8BUI', 1, 0 + ), + 1, 1, 1, ARRAY[[9, 9, 9], [9, NULL, 9], [9, 9, 9]]::double precision[][] + ) + ) AS poly +) foo +ORDER BY 1, 2; + + x | y | val +---+---+----- + 1 | 1 | 9 + 1 | 2 | 9 + 1 | 3 | 9 + 2 | 1 | 9 + 2 | 2 | + 2 | 3 | 9 + 3 | 1 | 9 + 3 | 2 | 9 + 3 | 3 | 9 + + + +/* +The ST_SetValues() does the following... + ++ - + - + - + + - + - + - + +| 1 | 1 | 1 | | 9 | 9 | 9 | ++ - + - + - + + - + - + - + +| 1 | 1 | 1 | => | 1 | | 9 | ++ - + - + - + + - + - + - + +| 1 | 1 | 1 | | 9 | 9 | 9 | ++ - + - + - + + - + - + - + +*/ +SELECT + (poly).x, + (poly).y, + (poly).val +FROM ( +SELECT + ST_PixelAsPolygons( + ST_SetValues( + ST_AddBand( + ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0), + 1, '8BUI', 1, 0 + ), + 1, 1, 1, + ARRAY[[9, 9, 9], [9, NULL, 9], [9, 9, 9]]::double precision[][], + ARRAY[[false], [true]]::boolean[][] + ) + ) AS poly +) foo +ORDER BY 1, 2; + + x | y | val +---+---+----- + 1 | 1 | 9 + 1 | 2 | 1 + 1 | 3 | 9 + 2 | 1 | 9 + 2 | 2 | + 2 | 3 | 9 + 3 | 1 | 9 + 3 | 2 | 9 + 3 | 3 | 9 + + + +/* +The ST_SetValues() does the following... + ++ - + - + - + + - + - + - + +| | 1 | 1 | | | 9 | 9 | ++ - + - + - + + - + - + - + +| 1 | 1 | 1 | => | 1 | | 9 | ++ - + - + - + + - + - + - + +| 1 | 1 | 1 | | 9 | 9 | 9 | ++ - + - + - + + - + - + - + +*/ +SELECT + (poly).x, + (poly).y, + (poly).val +FROM ( +SELECT + ST_PixelAsPolygons( + ST_SetValues( + ST_SetValue( + ST_AddBand( + ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0), + 1, '8BUI', 1, 0 + ), + 1, 1, 1, NULL + ), + 1, 1, 1, + ARRAY[[9, 9, 9], [9, NULL, 9], [9, 9, 9]]::double precision[][], + ARRAY[[false], [true]]::boolean[][], + TRUE + ) + ) AS poly +) foo +ORDER BY 1, 2; + + x | y | val +---+---+----- + 1 | 1 | + 1 | 2 | 1 + 1 | 3 | 9 + 2 | 1 | 9 + 2 | 2 | + 2 | 3 | 9 + 3 | 1 | 9 + 3 | 2 | 9 + 3 | 3 | 9 + + + + + + Examples: Variant 2 + + +/* +The ST_SetValues() does the following... + ++ - + - + - + + - + - + - + +| 1 | 1 | 1 | | 1 | 1 | 1 | ++ - + - + - + + - + - + - + +| 1 | 1 | 1 | => | 1 | 9 | 9 | ++ - + - + - + + - + - + - + +| 1 | 1 | 1 | | 1 | 9 | 9 | ++ - + - + - + + - + - + - + +*/ +SELECT + (poly).x, + (poly).y, + (poly).val +FROM ( +SELECT + ST_PixelAsPolygons( + ST_SetValues( + ST_AddBand( + ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0), + 1, '8BUI', 1, 0 + ), + 1, 2, 2, 2, 2, 9 + ) + ) AS poly +) foo +ORDER BY 1, 2; + + x | y | val +---+---+----- + 1 | 1 | 1 + 1 | 2 | 1 + 1 | 3 | 1 + 2 | 1 | 1 + 2 | 2 | 9 + 2 | 3 | 9 + 3 | 1 | 1 + 3 | 2 | 9 + 3 | 3 | 9 + + + +/* +The ST_SetValues() does the following... + ++ - + - + - + + - + - + - + +| 1 | 1 | 1 | | 1 | 1 | 1 | ++ - + - + - + + - + - + - + +| 1 | | 1 | => | 1 | | 9 | ++ - + - + - + + - + - + - + +| 1 | 1 | 1 | | 1 | 9 | 9 | ++ - + - + - + + - + - + - + +*/ +SELECT + (poly).x, + (poly).y, + (poly).val +FROM ( +SELECT + ST_PixelAsPolygons( + ST_SetValues( + ST_SetValue( + ST_AddBand( + ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0), + 1, '8BUI', 1, 0 + ), + 1, 2, 2, NULL + ), + 1, 2, 2, 2, 2, 9, TRUE + ) + ) AS poly +) foo +ORDER BY 1, 2; + + x | y | val +---+---+----- + 1 | 1 | 1 + 1 | 2 | 1 + 1 | 3 | 1 + 2 | 1 | 1 + 2 | 2 | + 2 | 3 | 9 + 3 | 1 | 1 + 3 | 2 | 9 + 3 | 3 | 9 + + + + + + See Also + + , + , + + + + + ST_PixelOfValue diff --git a/raster/rt_pg/rtpostgis.sql.in.c b/raster/rt_pg/rtpostgis.sql.in.c index bef1cf47a..1e9d3fb3f 100644 --- a/raster/rt_pg/rtpostgis.sql.in.c +++ b/raster/rt_pg/rtpostgis.sql.in.c @@ -2917,8 +2917,7 @@ CREATE OR REPLACE FUNCTION st_setvalue(rast raster, pt geometry, newvalue float8 -- ST_SetValues (set one or more pixels to a one or more values) ----------------------------------------------------------------------- CREATE OR REPLACE FUNCTION st_setvalues( - rast raster, - nband integer, + rast raster, nband integer, x integer, y integer, newvalueset double precision[][], noset boolean[][] DEFAULT NULL, @@ -2930,8 +2929,7 @@ CREATE OR REPLACE FUNCTION st_setvalues( -- cannot be STRICT as newvalue can be NULL CREATE OR REPLACE FUNCTION st_setvalues( - rast raster, - nband integer, + rast raster, nband integer, x integer, y integer, width integer, height integer, newvalue double precision, diff --git a/raster/test/regress/Makefile.in b/raster/test/regress/Makefile.in index 631941872..083fe7ee5 100644 --- a/raster/test/regress/Makefile.in +++ b/raster/test/regress/Makefile.in @@ -43,11 +43,7 @@ TEST_FUNC = \ rt_bytea \ box3d \ rt_addband \ - rt_band \ - rt_asgdalraster \ - rt_astiff \ - rt_asjpeg \ - rt_aspng + rt_band TEST_PROPS = \ rt_dimensions \ @@ -66,6 +62,7 @@ TEST_PROPS = \ TEST_BANDPROPS = \ rt_band_properties \ rt_set_band_properties \ + rt_setvalues_array \ rt_summarystats \ rt_count \ rt_histogram \ @@ -84,6 +81,10 @@ TEST_BANDPROPS = \ TEST_UTILITY = \ rt_utility \ + rt_asgdalraster \ + rt_astiff \ + rt_asjpeg \ + rt_aspng \ rt_mapalgebraexpr \ rt_mapalgebrafct \ rt_mapalgebraexpr_2raster \ @@ -135,9 +136,9 @@ TEST_LOADER = \ loader/Tiled10x10 \ loader/Tiled10x10Copy -TESTS = $(TEST_FIRST) $(TEST_METADATA) $(TEST_IO) $(TEST_FUNC) \ - $(TEST_PROPS) $(TEST_BANDPROPS) \ - $(TEST_UTILITY) $(TEST_GIST) $(TEST_SREL) \ +TESTS = $(TEST_FIRST) $(TEST_METADATA) $(TEST_IO) $(TEST_BASIC_FUNC) \ + $(TEST_PROPS) $(TEST_GIST) $(TEST_BANDPROPS) \ + $(TEST_UTILITY) $(TEST_SREL) \ $(TEST_BUGS) \ $(TEST_LOADER) diff --git a/raster/test/regress/rt_setvalues_array.sql b/raster/test/regress/rt_setvalues_array.sql new file mode 100644 index 000000000..f81d1fba3 --- /dev/null +++ b/raster/test/regress/rt_setvalues_array.sql @@ -0,0 +1,199 @@ +SET client_min_messages TO warning; + +DROP TABLE IF EXISTS raster_setvalues_rast; +DROP TABLE IF EXISTS raster_setvalues_out; +CREATE TABLE raster_setvalues_rast ( + rid integer, + rast raster +); +CREATE TABLE raster_setvalues_out ( + rid integer, + rast raster +); +CREATE OR REPLACE FUNCTION make_test_raster(rid integer, width integer DEFAULT 2, height integer DEFAULT 2, ul_x double precision DEFAULT 0, ul_y double precision DEFAULT 0, skew_x double precision DEFAULT 0, skew_y double precision DEFAULT 0) + RETURNS void + AS $$ + DECLARE + x int; + y int; + rast raster; + BEGIN + rast := ST_MakeEmptyRaster(width, height, ul_x, ul_y, 1, 1, skew_x, skew_y, 0); + rast := ST_AddBand(rast, 1, '8BUI', 1, 0); + + INSERT INTO raster_setvalues_rast VALUES (rid, rast); + + RETURN; + END; + $$ LANGUAGE 'plpgsql'; +SELECT make_test_raster(0, 5, 3); +DROP FUNCTION make_test_raster(integer, integer, integer, double precision, double precision, double precision, double precision); + +INSERT INTO raster_setvalues_out VALUES ( + 1, ( + SELECT ST_SetValues( + rast, 1, 1, 1, + ARRAY[10]::double precision[] + ) + FROM raster_setvalues_rast +)); + +INSERT INTO raster_setvalues_out VALUES ( + 2, ( + SELECT ST_SetValues( + rast, 1, 2, 1, + ARRAY[10]::double precision[] + ) + FROM raster_setvalues_rast +)); + +INSERT INTO raster_setvalues_out VALUES ( + 3, ( + SELECT ST_SetValues( + rast, 1, 3, 1, + ARRAY[10]::double precision[] + ) + FROM raster_setvalues_rast +)); + +INSERT INTO raster_setvalues_out VALUES ( + 4, ( + SELECT ST_SetValues( + rast, 1, 1, 1, + ARRAY[10, 10]::double precision[] + ) + FROM raster_setvalues_rast +)); + +INSERT INTO raster_setvalues_out VALUES ( + 5, ( + SELECT ST_SetValues( + rast, 1, 2, 2, + ARRAY[10, 10]::double precision[] + ) + FROM raster_setvalues_rast +)); + +INSERT INTO raster_setvalues_out VALUES ( + 6, ( + SELECT ST_SetValues( + rast, 1, 3, 3, + ARRAY[10, 10, 10]::double precision[] + ) + FROM raster_setvalues_rast +)); + +INSERT INTO raster_setvalues_out VALUES ( + 7, ( + SELECT ST_SetValues( + rast, 1, 4, 3, + ARRAY[10, 10, 10]::double precision[] + ) + FROM raster_setvalues_rast +)); + +INSERT INTO raster_setvalues_out VALUES ( + 8, ( + SELECT ST_SetValues( + rast, 1, 2, 1, + ARRAY[[5, 5, 5, 5], [6, 6, 6, 6]]::double precision[] + ) + FROM raster_setvalues_rast +)); + +INSERT INTO raster_setvalues_out VALUES ( + 9, ( + SELECT ST_SetValues( + rast, 1, 2, 1, + ARRAY[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, NULL]]::double precision[] + ) + FROM raster_setvalues_rast +)); + +INSERT INTO raster_setvalues_out VALUES ( + 10, ( + SELECT ST_SetValues( + rast, 1, 2, 1, + ARRAY[[5, 5, 5, 5, 10], [6, 6, 6, 6, 10], [7, 7, 7, NULL, 10]]::double precision[] + ) + FROM raster_setvalues_rast +)); + +INSERT INTO raster_setvalues_out VALUES ( + 11, ( + SELECT ST_SetValues( + rast, 1, 1, 1, + ARRAY[10, 10, 10]::double precision[], + ARRAY[false, true]::boolean[] + ) + FROM raster_setvalues_rast +)); + +INSERT INTO raster_setvalues_out VALUES ( + 12, ( + SELECT ST_SetValues( + rast, 1, 1, 1, + ARRAY[NULL, 10, 0]::double precision[], + ARRAY[false, NULL, false]::boolean[] + ) + FROM raster_setvalues_rast +)); + +INSERT INTO raster_setvalues_out VALUES ( + 13, ( + SELECT ST_SetValues( + rast, 1, 1, 1, + ARRAY[NULL, 10, 0]::double precision[], + ARRAY[false, NULL, true]::boolean[] + ) + FROM raster_setvalues_rast +)); + +INSERT INTO raster_setvalues_out VALUES ( + 21, ( + SELECT ST_SetValues( + rast, 1, + 1, 1, + 5, 3, + 100 + ) + FROM raster_setvalues_rast +)); + +INSERT INTO raster_setvalues_out VALUES ( + 22, ( + SELECT ST_SetValues( + rast, 1, + 1, 1, + 5, 3, + NULL + ) + FROM raster_setvalues_rast +)); + +INSERT INTO raster_setvalues_out VALUES ( + 23, ( + SELECT ST_SetValues( + rast, 1, + 1, 1, + 5, 3, + 0 + ) + FROM raster_setvalues_rast +)); + +SELECT + rid, + (poly).x, + (poly).y, + (poly).val +FROM ( + SELECT + rid, + ST_PixelAsPolygons(rast) AS poly + FROM raster_setvalues_out +) AS foo +ORDER BY 1, 2, 3; + +DROP TABLE IF EXISTS raster_setvalues_rast; +DROP TABLE IF EXISTS raster_setvalues_out; diff --git a/raster/test/regress/rt_setvalues_array_expected b/raster/test/regress/rt_setvalues_array_expected new file mode 100644 index 000000000..51aa70055 --- /dev/null +++ b/raster/test/regress/rt_setvalues_array_expected @@ -0,0 +1,240 @@ +1|1|1|10 +1|1|2|1 +1|1|3|1 +1|2|1|1 +1|2|2|1 +1|2|3|1 +1|3|1|1 +1|3|2|1 +1|3|3|1 +1|4|1|1 +1|4|2|1 +1|4|3|1 +1|5|1|1 +1|5|2|1 +1|5|3|1 +2|1|1|1 +2|1|2|1 +2|1|3|1 +2|2|1|10 +2|2|2|1 +2|2|3|1 +2|3|1|1 +2|3|2|1 +2|3|3|1 +2|4|1|1 +2|4|2|1 +2|4|3|1 +2|5|1|1 +2|5|2|1 +2|5|3|1 +3|1|1|1 +3|1|2|1 +3|1|3|1 +3|2|1|1 +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10|5|2|6 +10|5|3| +11|1|1|10 +11|1|2|1 +11|1|3|1 +11|2|1|1 +11|2|2|1 +11|2|3|1 +11|3|1|10 +11|3|2|1 +11|3|3|1 +11|4|1|1 +11|4|2|1 +11|4|3|1 +11|5|1|1 +11|5|2|1 +11|5|3|1 +12|1|1| +12|1|2|1 +12|1|3|1 +12|2|1|10 +12|2|2|1 +12|2|3|1 +12|3|1| +12|3|2|1 +12|3|3|1 +12|4|1|1 +12|4|2|1 +12|4|3|1 +12|5|1|1 +12|5|2|1 +12|5|3|1 +13|1|1| +13|1|2|1 +13|1|3|1 +13|2|1|10 +13|2|2|1 +13|2|3|1 +13|3|1|1 +13|3|2|1 +13|3|3|1 +13|4|1|1 +13|4|2|1 +13|4|3|1 +13|5|1|1 +13|5|2|1 +13|5|3|1 +21|1|1|100 +21|1|2|100 +21|1|3|100 +21|2|1|100 +21|2|2|100 +21|2|3|100 +21|3|1|100 +21|3|2|100 +21|3|3|100 +21|4|1|100 +21|4|2|100 +21|4|3|100 +21|5|1|100 +21|5|2|100 +21|5|3|100 +22|1|1| +22|1|2| +22|1|3| +22|2|1| +22|2|2| +22|2|3| +22|3|1| +22|3|2| +22|3|3| +22|4|1| +22|4|2| +22|4|3| +22|5|1| +22|5|2| +22|5|3| +23|1|1| +23|1|2| +23|1|3| +23|2|1| +23|2|2| +23|2|3| +23|3|1| +23|3|2| +23|3|3| +23|4|1| +23|4|2| +23|4|3| +23|5|1| +23|5|2| +23|5|3|