From 091246ef835bc25e244b57b829c72e5ed9494271 Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Tue, 22 May 2012 17:06:15 +0000 Subject: [PATCH] Added regression tests for ST_World2RasterCoord and ST_Raster2WorldCoord. Updated existing tests use the same functions git-svn-id: http://svn.osgeo.org/postgis/trunk@9793 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/test/regress/Makefile.in | 4 +- .../test/regress/create_rt_utility_test.sql | 2 - raster/test/regress/rt_raster2worldcoord.sql | 69 ++++++++++++ .../regress/rt_raster2worldcoord_expected | 50 +++++++++ raster/test/regress/rt_utility.sql | 100 +++++++++--------- raster/test/regress/rt_utility_expected | 20 +++- raster/test/regress/rt_world2rastercoord.sql | 69 ++++++++++++ .../regress/rt_world2rastercoord_expected | 50 +++++++++ 8 files changed, 307 insertions(+), 57 deletions(-) create mode 100644 raster/test/regress/rt_raster2worldcoord.sql create mode 100644 raster/test/regress/rt_raster2worldcoord_expected create mode 100644 raster/test/regress/rt_world2rastercoord.sql create mode 100644 raster/test/regress/rt_world2rastercoord_expected diff --git a/raster/test/regress/Makefile.in b/raster/test/regress/Makefile.in index 230eb4448..359f92e62 100644 --- a/raster/test/regress/Makefile.in +++ b/raster/test/regress/Makefile.in @@ -60,7 +60,9 @@ TEST_PROPS = \ rt_isempty \ rt_hasnoband \ drop_rt_empty_raster_test \ - rt_metadata + rt_metadata \ + rt_raster2worldcoord \ + rt_world2rastercoord TEST_BANDPROPS = \ create_rt_band_properties_test \ diff --git a/raster/test/regress/create_rt_utility_test.sql b/raster/test/regress/create_rt_utility_test.sql index 3ad290925..b0bf90085 100644 --- a/raster/test/regress/create_rt_utility_test.sql +++ b/raster/test/regress/create_rt_utility_test.sql @@ -7,8 +7,6 @@ -- the terms of the GNU General Public Licence. See the COPYING file. ----------------------------------------------------------------------- -SET client_min_messages TO warning; - ----------------------------------------------------------------------- --- Test of "Get" functions for properties of the raster. ----------------------------------------------------------------------- diff --git a/raster/test/regress/rt_raster2worldcoord.sql b/raster/test/regress/rt_raster2worldcoord.sql new file mode 100644 index 000000000..d79ca0c60 --- /dev/null +++ b/raster/test/regress/rt_raster2worldcoord.sql @@ -0,0 +1,69 @@ +CREATE TABLE raster_raster2world ( + 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, + initvalue double precision DEFAULT 1, + nodataval 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', initvalue, nodataval); + + INSERT INTO raster_raster2world VALUES (rid, rast); + + RETURN; + END; + $$ LANGUAGE 'plpgsql'; + +-- no skew +SELECT make_test_raster(0, 4, 4, -2, -2); +SELECT make_test_raster(1, 2, 2, 0, 0, 0, 0, 2); +SELECT make_test_raster(2, 2, 2, 1, -1, 0, 0, 3); +SELECT make_test_raster(3, 2, 2, 1, 1, 0, 0, 4); +SELECT make_test_raster(4, 2, 2, 2, 2, 0, 0, 5); + +-- skew +SELECT make_test_raster(10, 4, 4, -2, -2, 1, -1); +SELECT make_test_raster(11, 2, 2, 0, 0, 1, -1, 2); +SELECT make_test_raster(12, 2, 2, 1, -1, 1, -1, 3); +SELECT make_test_raster(13, 2, 2, 1, 1, 1, -1, 4); +SELECT make_test_raster(14, 2, 2, 2, 2, 1, -1, 5); + +DROP FUNCTION make_test_raster(integer, integer, integer, double precision, double precision, double precision, double precision, double precision, double precision); + +SELECT + rid, + (ST_Raster2WorldCoord(rast, 1, 1)).* +FROM raster_raster2world; +SELECT + rid, + (ST_Raster2WorldCoord(rast, 1, 2)).* +FROM raster_raster2world; +SELECT + rid, + (ST_Raster2WorldCoord(rast, 2, 2)).* +FROM raster_raster2world; +SELECT + rid, + (ST_Raster2WorldCoord(rast, 0, 0)).* +FROM raster_raster2world; +SELECT + rid, + (ST_Raster2WorldCoord(rast, -1, 0)).* +FROM raster_raster2world; + +DROP TABLE raster_raster2world; diff --git a/raster/test/regress/rt_raster2worldcoord_expected b/raster/test/regress/rt_raster2worldcoord_expected new file mode 100644 index 000000000..91c6dc6c2 --- /dev/null +++ b/raster/test/regress/rt_raster2worldcoord_expected @@ -0,0 +1,50 @@ +0|-2|-2 +1|0|0 +2|1|-1 +3|1|1 +4|2|2 +10|-2|-2 +11|0|0 +12|1|-1 +13|1|1 +14|2|2 +0|-2|-1 +1|0|1 +2|1|0 +3|1|2 +4|2|3 +10|-1|-1 +11|1|1 +12|2|0 +13|2|2 +14|3|3 +0|-1|-1 +1|1|1 +2|2|0 +3|2|2 +4|3|3 +10|0|-2 +11|2|0 +12|3|-1 +13|3|1 +14|4|2 +0|-3|-3 +1|-1|-1 +2|0|-2 +3|0|0 +4|1|1 +10|-4|-2 +11|-2|0 +12|-1|-1 +13|-1|1 +14|0|2 +0|-4|-3 +1|-2|-1 +2|-1|-2 +3|-1|0 +4|0|1 +10|-5|-1 +11|-3|1 +12|-2|0 +13|-2|2 +14|-1|3 diff --git a/raster/test/regress/rt_utility.sql b/raster/test/regress/rt_utility.sql index b17768803..1ec176985 100644 --- a/raster/test/regress/rt_utility.sql +++ b/raster/test/regress/rt_utility.sql @@ -15,24 +15,24 @@ SELECT 'test 1.1', id, name FROM rt_utility_test - WHERE st_world2rastercoordx(rast, + WHERE COALESCE(st_world2rastercoordx(rast, ipx, ipy - ) != 1; + ), 0) != 1; SELECT 'test 1.2', id, name FROM rt_utility_test - WHERE st_world2rastercoordx(rast, + WHERE COALESCE(st_world2rastercoordx(rast, scalex * (width - 1) + skewx * (height - 1) + ipx, skewy * (width - 1) + scaley * (height - 1) + ipy - ) != width; + ), 0) != width; SELECT 'test 1.3', id, name FROM rt_utility_test - WHERE st_world2rastercoordx(rast, + WHERE COALESCE(st_world2rastercoordx(rast, scalex * width + skewx * height + ipx, skewy * width + scaley * height + ipy - ) != width + 1; + ), 0) != width + 1; ----------------------------------------------------------------------- -- Test 2 - st_world2rastercoordx(rast raster, xw float8) @@ -41,29 +41,29 @@ SELECT 'test 1.3', id, name SELECT 'test 2.1', id, name FROM rt_utility_test WHERE skewx = 0 and - st_world2rastercoordx(rast, + COALESCE(st_world2rastercoordx(rast, ipx - ) != 1; + ), 0) != 1; SELECT 'test 2.2', id, name FROM rt_utility_test WHERE skewx = 0 and - st_world2rastercoordx(rast, + COALESCE(st_world2rastercoordx(rast, scalex * (width - 1) + ipx - ) != width; + ), 0) != width; SELECT 'test 2.3', id, name FROM rt_utility_test WHERE skewx = 0 and - st_world2rastercoordx(rast, + COALESCE(st_world2rastercoordx(rast, scalex * width + ipx - ) != width + 1; + ), 0) != width + 1; SELECT 'test 2.4', id, name FROM rt_utility_test - WHERE st_world2rastercoordx(rast, + WHERE COALESCE(st_world2rastercoordx(rast, ipx - ) != 1; + ), 0) != 1; ----------------------------------------------------------------------- -- Test 3 - st_world2rastercoordx(rast raster, pt geometry) @@ -71,30 +71,30 @@ SELECT 'test 2.4', id, name SELECT 'test 3.1', id, name FROM rt_utility_test - WHERE st_world2rastercoordx(rast, + WHERE COALESCE(st_world2rastercoordx(rast, st_makepoint( ipx, ipy ) - ) != 1; + ), 0) != 1; SELECT 'test 3.2', id, name FROM rt_utility_test - WHERE st_world2rastercoordx(rast, + WHERE COALESCE(st_world2rastercoordx(rast, st_makepoint( scalex * (width - 1) + skewx * (height - 1) + ipx, skewy * (width - 1) + scaley * (height - 1) + ipy ) - ) != width; + ), 0) != width; SELECT 'test 3.3', id, name FROM rt_utility_test - WHERE st_world2rastercoordx(rast, + WHERE COALESCE(st_world2rastercoordx(rast, st_makepoint( scalex * width + skewx * height + ipx, skewy * width + scaley * height + ipy ) - ) != width + 1; + ), 0) != width + 1; ----------------------------------------------------------------------- -- Test 4 - st_world2rastercoordy(rast raster, xw float8, yw float8) @@ -102,24 +102,24 @@ SELECT 'test 3.3', id, name SELECT 'test 4.1', id, name FROM rt_utility_test - WHERE st_world2rastercoordy(rast, + WHERE COALESCE(st_world2rastercoordy(rast, ipx, ipy - ) != 1; + ), 0) != 1; SELECT 'test 4.2', id, name FROM rt_utility_test - WHERE st_world2rastercoordy(rast, + WHERE COALESCE(st_world2rastercoordy(rast, scalex * (width - 1) + skewx * (height - 1) + ipx, skewy * (width - 1) + scaley * (height - 1) + ipy - ) != height; + ), 0) != height; SELECT 'test 4.3', id, name FROM rt_utility_test - WHERE st_world2rastercoordy(rast, + WHERE COALESCE(st_world2rastercoordy(rast, scalex * width + skewx * height + ipx, skewy * width + scaley * height + ipy - ) != height + 1; + ), 0) != height + 1; ----------------------------------------------------------------------- -- Test 5 - st_world2rastercoordy(rast raster, yw float8) @@ -128,29 +128,29 @@ SELECT 'test 4.3', id, name SELECT 'test 5.1', id, name FROM rt_utility_test WHERE skewy = 0 and - st_world2rastercoordy(rast, + COALESCE(st_world2rastercoordy(rast, ipy - ) != 1; + ), 0) != 1; SELECT 'test 5.2', id, name FROM rt_utility_test WHERE skewy = 0 and - st_world2rastercoordy(rast, + COALESCE(st_world2rastercoordy(rast, scaley * (height - 1) + ipy - ) != height; + ), 0) != height; SELECT 'test 5.3', id, name FROM rt_utility_test WHERE skewy = 0 and - st_world2rastercoordy(rast, + COALESCE(st_world2rastercoordy(rast, scaley * height + ipy - ) != height + 1; + ), 0) != height + 1; SELECT 'test 5.4', id, name FROM rt_utility_test - WHERE st_world2rastercoordy(rast, + WHERE COALESCE(st_world2rastercoordy(rast, ipy - ) != 1; + ), 0) != 1; ----------------------------------------------------------------------- @@ -159,30 +159,30 @@ SELECT 'test 5.4', id, name SELECT 'test 6.1', id, name FROM rt_utility_test - WHERE st_world2rastercoordy(rast, + WHERE COALESCE(st_world2rastercoordy(rast, st_makepoint( ipx, ipy ) - ) != 1; + ), 0) != 1; SELECT 'test 6.2', id, name FROM rt_utility_test - WHERE st_world2rastercoordy(rast, + WHERE COALESCE(st_world2rastercoordy(rast, st_makepoint( scalex * (width - 1) + skewx * (height - 1) + ipx, skewy * (width - 1) + scaley * (height - 1) + ipy ) - ) != height; + ), 0) != height; SELECT 'test 6.3', id, name FROM rt_utility_test - WHERE st_world2rastercoordy(rast, + WHERE COALESCE(st_world2rastercoordy(rast, st_makepoint( scalex * width + skewx * height + ipx, skewy * width + scaley * height + ipy ) - ) != height + 1; + ), 0) != height + 1; ----------------------------------------------------------------------- -- Test 7 - st_raster2worldcoordx(rast raster, xr int, yr int) @@ -190,11 +190,11 @@ SELECT 'test 6.3', id, name SELECT 'test 7.1', id, name FROM rt_utility_test - WHERE st_raster2worldcoordx(rast, 1, 1)::numeric != ipx::numeric; + WHERE COALESCE(st_raster2worldcoordx(rast, 1, 1), 0)::numeric != ipx::numeric; SELECT 'test 7.2', id, name FROM rt_utility_test - WHERE st_raster2worldcoordx(rast, width, height)::numeric != (scalex * (width - 1) + skewx * (height - 1) + ipx)::numeric; + WHERE COALESCE(st_raster2worldcoordx(rast, width, height), 0)::numeric != (scalex * (width - 1) + skewx * (height - 1) + ipx)::numeric; ----------------------------------------------------------------------- -- Test 8 - st_raster2worldcoordx(rast raster, xr int) @@ -202,15 +202,15 @@ SELECT 'test 7.2', id, name SELECT 'test 8.1', id, name FROM rt_utility_test - WHERE skewx = 0 and st_raster2worldcoordx(rast, 1)::numeric != ipx::numeric; + WHERE skewx = 0 and COALESCE(st_raster2worldcoordx(rast, 1), 0)::numeric != ipx::numeric; SELECT 'test 8.2', id, name FROM rt_utility_test - WHERE skewx = 0 and st_raster2worldcoordx(rast, width)::numeric != (scalex * (width - 1) + ipx)::numeric; + WHERE skewx = 0 and COALESCE(st_raster2worldcoordx(rast, width), 0)::numeric != (scalex * (width - 1) + ipx)::numeric; SELECT 'test 8.3', id, name FROM rt_utility_test - WHERE st_raster2worldcoordx(rast, 1)::numeric != ipx::numeric; + WHERE COALESCE(st_raster2worldcoordx(rast, 1), 0)::numeric != ipx::numeric; ----------------------------------------------------------------------- -- Test 9 - st_raster2worldcoordy(rast raster, xr int, yr int) @@ -218,11 +218,11 @@ SELECT 'test 8.3', id, name SELECT 'test 9.1', id, name FROM rt_utility_test - WHERE st_raster2worldcoordy(rast, 1, 1)::numeric != ipy::numeric; + WHERE COALESCE(st_raster2worldcoordy(rast, 1, 1), 0)::numeric != ipy::numeric; SELECT 'test 9.2', id, name FROM rt_utility_test - WHERE round(st_raster2worldcoordy(rast, width, height)::numeric, 10) != round((skewy * (width - 1) + scaley * (height - 1) + ipy)::numeric, 10); + WHERE round(COALESCE(st_raster2worldcoordy(rast, width, height), 0)::numeric, 10) != round((skewy * (width - 1) + scaley * (height - 1) + ipy)::numeric, 10); ----------------------------------------------------------------------- -- Test 10 - st_raster2worldcoordy(rast raster, yr int) @@ -230,15 +230,15 @@ SELECT 'test 9.2', id, name SELECT 'test 10.1', id, name FROM rt_utility_test - WHERE skewy = 0 and st_raster2worldcoordy(rast, 1, 1)::numeric != ipy::numeric; + WHERE skewy = 0 and COALESCE(st_raster2worldcoordy(rast, 1, 1), 0)::numeric != ipy::numeric; SELECT 'test 10.2', id, name FROM rt_utility_test - WHERE skewy = 0 and st_raster2worldcoordy(rast, width, height)::numeric != (scaley * (height - 1) + ipy)::numeric; + WHERE skewy = 0 and COALESCE(st_raster2worldcoordy(rast, width, height), 0)::numeric != (scaley * (height - 1) + ipy)::numeric; SELECT 'test 10.3', id, name FROM rt_utility_test - WHERE st_raster2worldcoordy(rast, 1)::numeric != ipy::numeric; + WHERE COALESCE(st_raster2worldcoordy(rast, 1), 0)::numeric != ipy::numeric; ----------------------------------------------------------------------- -- Test 11 - st_minpossiblevalue(pixtype text) diff --git a/raster/test/regress/rt_utility_expected b/raster/test/regress/rt_utility_expected index 15c448759..8b183b7fe 100644 --- a/raster/test/regress/rt_utility_expected +++ b/raster/test/regress/rt_utility_expected @@ -1,7 +1,19 @@ -ERROR: RASTER_worldToRasterCoord: Latitude and longitude required for computing pixel row and column of a rotated raster -ERROR: RASTER_worldToRasterCoord: Latitude and longitude required for computing pixel row and column of a rotated raster -ERROR: RASTER_rasterToWorldCoord: Pixel row and column required for computing longitude and latitude of a rotated raster -ERROR: RASTER_rasterToWorldCoord: Pixel row and column required for computing longitude and latitude of a rotated raster +NOTICE: Latitude and longitude required for computing pixel row and column of a rotated raster +NOTICE: Latitude and longitude required for computing pixel row and column of a rotated raster +test 2.4|2|1217x1156, ip:782325.5,26744042.5 scale:5,-5 skew:3,3 srid:9102707 width:1217 height:1156 +test 2.4|4|6000x6000, ip:-75.5533328537098,49.2824585505576 scale:0.000805965234044584,-0.00080596523404458 skew:0.000211812383858707,0.000211812383858704 srid:4326 width:6000 height:6000 +NOTICE: Latitude and longitude required for computing pixel row and column of a rotated raster +NOTICE: Latitude and longitude required for computing pixel row and column of a rotated raster +test 5.4|2|1217x1156, ip:782325.5,26744042.5 scale:5,-5 skew:3,3 srid:9102707 width:1217 height:1156 +test 5.4|4|6000x6000, ip:-75.5533328537098,49.2824585505576 scale:0.000805965234044584,-0.00080596523404458 skew:0.000211812383858707,0.000211812383858704 srid:4326 width:6000 height:6000 +NOTICE: Pixel row and column required for computing longitude and latitude of a rotated raster +NOTICE: Pixel row and column required for computing longitude and latitude of a rotated raster +test 8.3|2|1217x1156, ip:782325.5,26744042.5 scale:5,-5 skew:3,3 srid:9102707 width:1217 height:1156 +test 8.3|4|6000x6000, ip:-75.5533328537098,49.2824585505576 scale:0.000805965234044584,-0.00080596523404458 skew:0.000211812383858707,0.000211812383858704 srid:4326 width:6000 height:6000 +NOTICE: Pixel row and column required for computing longitude and latitude of a rotated raster +NOTICE: Pixel row and column required for computing longitude and latitude of a rotated raster +test 10.3|2|1217x1156, ip:782325.5,26744042.5 scale:5,-5 skew:3,3 srid:9102707 width:1217 height:1156 +test 10.3|4|6000x6000, ip:-75.5533328537098,49.2824585505576 scale:0.000805965234044584,-0.00080596523404458 skew:0.000211812383858707,0.000211812383858704 srid:4326 width:6000 height:6000 test 11.1|t test 11.2|t test 11.3|t diff --git a/raster/test/regress/rt_world2rastercoord.sql b/raster/test/regress/rt_world2rastercoord.sql new file mode 100644 index 000000000..97a1c8e3b --- /dev/null +++ b/raster/test/regress/rt_world2rastercoord.sql @@ -0,0 +1,69 @@ +CREATE TABLE raster_world2raster ( + 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, + initvalue double precision DEFAULT 1, + nodataval 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', initvalue, nodataval); + + INSERT INTO raster_world2raster VALUES (rid, rast); + + RETURN; + END; + $$ LANGUAGE 'plpgsql'; + +-- no skew +SELECT make_test_raster(0, 4, 4, -2, -2); +SELECT make_test_raster(1, 2, 2, 0, 0, 0, 0, 2); +SELECT make_test_raster(2, 2, 2, 1, -1, 0, 0, 3); +SELECT make_test_raster(3, 2, 2, 1, 1, 0, 0, 4); +SELECT make_test_raster(4, 2, 2, 2, 2, 0, 0, 5); + +-- skew +SELECT make_test_raster(10, 4, 4, -2, -2, 1, -1); +SELECT make_test_raster(11, 2, 2, 0, 0, 1, -1, 2); +SELECT make_test_raster(12, 2, 2, 1, -1, 1, -1, 3); +SELECT make_test_raster(13, 2, 2, 1, 1, 1, -1, 4); +SELECT make_test_raster(14, 2, 2, 2, 2, 1, -1, 5); + +DROP FUNCTION make_test_raster(integer, integer, integer, double precision, double precision, double precision, double precision, double precision, double precision); + +SELECT + rid, + (ST_World2RasterCoord(rast, -2, -2)).* +FROM raster_world2raster; +SELECT + rid, + (ST_World2RasterCoord(rast, 0, 0)).* +FROM raster_world2raster; +SELECT + rid, + (ST_World2RasterCoord(rast, 1, -1)).* +FROM raster_world2raster; +SELECT + rid, + (ST_World2RasterCoord(rast, 1, 1)).* +FROM raster_world2raster; +SELECT + rid, + (ST_World2RasterCoord(rast, 2, 2)).* +FROM raster_world2raster; + +DROP TABLE raster_world2raster; diff --git a/raster/test/regress/rt_world2rastercoord_expected b/raster/test/regress/rt_world2rastercoord_expected new file mode 100644 index 000000000..f09436b05 --- /dev/null +++ b/raster/test/regress/rt_world2rastercoord_expected @@ -0,0 +1,50 @@ +0|1|1 +1|-1|-1 +2|-2|0 +3|-2|-2 +4|-3|-3 +10|1|1 +11|1|-1 +12|0|-1 +13|1|-2 +14|1|-3 +0|3|3 +1|1|1 +2|0|2 +3|0|0 +4|-1|-1 +10|1|3 +11|1|1 +12|0|1 +13|1|0 +14|1|-1 +0|4|2 +1|2|0 +2|1|1 +3|1|-1 +4|0|-2 +10|2|3 +11|2|1 +12|1|1 +13|2|0 +14|2|-1 +0|4|4 +1|2|2 +2|1|3 +3|1|1 +4|0|0 +10|1|4 +11|1|2 +12|0|2 +13|1|1 +14|1|0 +0|5|5 +1|3|3 +2|2|4 +3|2|2 +4|1|1 +10|1|5 +11|1|3 +12|0|3 +13|1|2 +14|1|1 -- 2.40.0