Added regression tests for ST_InvDistWeight4ma()

git-svn-id: http://svn.osgeo.org/postgis/trunk@10302 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
Bborie Park 2012-09-19 18:48:08 +00:00
parent 695de54c02
commit ce7f81ffdc
3 changed files with 112 additions and 5 deletions

View file

@ -85,18 +85,21 @@ TEST_UTILITY = \
rt_astiff \
rt_asjpeg \
rt_aspng \
rt_reclass \
rt_resample \
rt_asraster \
TEST_MAPALGEBRA = \
rt_mapalgebraexpr \
rt_mapalgebrafct \
rt_mapalgebraexpr_2raster \
rt_mapalgebrafct_2raster \
rt_mapalgebrafctngb \
rt_mapalgebrafctngb_userfunc \
rt_reclass \
rt_resample \
rt_asraster \
rt_intersection \
rt_clip \
rt_union
rt_union \
rt_invdistweight4ma
TEST_GIST = \
rt_above \
@ -138,7 +141,7 @@ TEST_LOADER = \
TESTS = $(TEST_FIRST) $(TEST_METADATA) $(TEST_IO) $(TEST_BASIC_FUNC) \
$(TEST_PROPS) $(TEST_GIST) $(TEST_BANDPROPS) \
$(TEST_UTILITY) $(TEST_SREL) \
$(TEST_UTILITY) $(TEST_MAPALGEBRA) $(TEST_SREL) \
$(TEST_BUGS) \
$(TEST_LOADER)

View file

@ -0,0 +1,88 @@
DROP TABLE IF EXISTS raster_value_arrays;
CREATE TABLE raster_value_arrays (
id integer,
val double precision[][]
);
CREATE OR REPLACE FUNCTION make_value_array(
rows integer DEFAULT 3,
columns integer DEFAULT 3,
start_val double precision DEFAULT 1,
step double precision DEFAULT 1,
skip_expr text DEFAULT NULL
)
RETURNS double precision[][]
AS $$
DECLARE
x int;
y int;
value double precision;
values double precision[][];
result boolean;
expr text;
BEGIN
value := start_val;
values := array_fill(NULL::double precision, ARRAY[columns, rows]);
FOR y IN 1..columns LOOP
FOR x IN 1..rows LOOP
IF skip_expr IS NULL OR length(skip_expr) < 1 THEN
result := TRUE;
ELSE
expr := replace(skip_expr, '[v]'::text, value::text);
EXECUTE 'SELECT (' || expr || ')::boolean' INTO result;
END IF;
IF result IS TRUE THEN
values[y][x] := value;
END IF;
value := value + step;
END LOOP;
END LOOP;
RETURN values;
END;
$$ LANGUAGE 'plpgsql';
INSERT INTO raster_value_arrays VALUES
(1, make_value_array()),
(2, make_value_array(5, 5)),
(3, make_value_array(5, 5, 100)),
(4, make_value_array(3, 3, 15, -1)),
(5, make_value_array(5, 5, 15, -1)),
(6, make_value_array(3, 3, 1, 2)),
(7, make_value_array(5, 5, 1, 3)),
(10, make_value_array(3, 3, 1, 1, '0')),
(11, make_value_array(5, 5, 1, 1, '0')),
(12, make_value_array(3, 3, 1, 1, '[v] % 2')),
(13, make_value_array(5, 5, 1, 1, '[v] % 2')),
(14, make_value_array(3, 3, 1, 1, '([v] % 2) = 0')),
(15, make_value_array(5, 5, 1, 1, '([v] % 2) = 0')),
(16, make_value_array(3, 3, 1, 2.1, '([v] NOT IN (7.3, 9.4, 15.7, 17.8))')),
(17, make_value_array(3, 3, 0, 3.14, '([v] IN (3.14, 12.56, 25.12))'))
;
SELECT
id,
val,
round(st_invdistweight4ma(val, NULL::text, NULL)::numeric, 6) AS test1,
round(st_invdistweight4ma(val, NULL::text, '0')::numeric, 6) AS test2,
round(st_invdistweight4ma(val, NULL::text, '0.5')::numeric, 6) AS test3,
round(st_invdistweight4ma(val, NULL::text, '0.9')::numeric, 6) AS test4,
round(st_invdistweight4ma(val, NULL::text, '1')::numeric, 6) AS test5,
round(st_invdistweight4ma(val, NULL::text, '0.9', '1')::numeric, 6) AS test6,
round(st_invdistweight4ma(val, NULL::text, '0.9', '0.9')::numeric, 6) AS test7,
round(st_invdistweight4ma(val, NULL::text, '0.9', '0.75')::numeric, 6) AS test8,
round(st_invdistweight4ma(val, NULL::text, '0.9', '0.5')::numeric, 6) AS test9,
round(st_invdistweight4ma(val, NULL::text, '0.9', '0.25')::numeric, 6) AS test10,
round(st_invdistweight4ma(val, NULL::text, '0.9', '0.1')::numeric, 6) AS test11,
round(st_invdistweight4ma(val, NULL::text, '0.9', '0.01')::numeric, 6) AS test12,
round(st_invdistweight4ma(val, NULL::text, '0.9', '0.001')::numeric, 6) AS test13,
round(st_invdistweight4ma(val, NULL::text, '0.9', '0')::numeric, 6) AS test14
FROM raster_value_arrays
ORDER BY id;
DROP TABLE IF EXISTS raster_value_arrays;
DROP FUNCTION IF EXISTS make_value_array(integer, integer, double precision, double precision, text);

View file

@ -0,0 +1,16 @@
NOTICE: table "raster_value_arrays" does not exist, skipping
1|{{1,2,3},{4,5,6},{7,8,9}}|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000
2|{{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15},{16,17,18,19,20},{21,22,23,24,25}}|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000
3|{{100,101,102,103,104},{105,106,107,108,109},{110,111,112,113,114},{115,116,117,118,119},{120,121,122,123,124}}|112.000000|112.000000|112.000000|112.000000|112.000000|112.000000|112.000000|112.000000|112.000000|112.000000|112.000000|112.000000|112.000000|112.000000
4|{{15,14,13},{12,11,10},{9,8,7}}|11.000000|11.000000|11.000000|11.000000|11.000000|11.000000|11.000000|11.000000|11.000000|11.000000|11.000000|11.000000|11.000000|11.000000
5|{{15,14,13,12,11},{10,9,8,7,6},{5,4,3,2,1},{0,-1,-2,-3,-4},{-5,-6,-7,-8,-9}}|3.000000|3.000000|3.000000|3.000000|3.000000|3.000000|3.000000|3.000000|3.000000|3.000000|3.000000|3.000000|3.000000|3.000000
6|{{1,3,5},{7,9,11},{13,15,17}}|9.000000|9.000000|9.000000|9.000000|9.000000|9.000000|9.000000|9.000000|9.000000|9.000000|9.000000|9.000000|9.000000|9.000000
7|{{1,4,7,10,13},{16,19,22,25,28},{31,34,37,40,43},{46,49,52,55,58},{61,64,67,70,73}}|37.000000|37.000000|37.000000|37.000000|37.000000|37.000000|37.000000|37.000000|37.000000|37.000000|37.000000|37.000000|37.000000|37.000000
10|{{NULL,NULL,NULL},{NULL,NULL,NULL},{NULL,NULL,NULL}}||||||||||||||
11|{{NULL,NULL,NULL,NULL,NULL},{NULL,NULL,NULL,NULL,NULL},{NULL,NULL,NULL,NULL,NULL},{NULL,NULL,NULL,NULL,NULL},{NULL,NULL,NULL,NULL,NULL}}||||||||||||||
12|{{1,NULL,3},{NULL,5,NULL},{7,NULL,9}}|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000
13|{{1,NULL,3,NULL,5},{NULL,7,NULL,9,NULL},{11,NULL,13,NULL,15},{NULL,17,NULL,19,NULL},{21,NULL,23,NULL,25}}|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000
14|{{NULL,2,NULL},{4,NULL,6},{NULL,8,NULL}}|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000|5.000000
15|{{NULL,2,NULL,4,NULL},{6,NULL,8,NULL,10},{NULL,12,NULL,14,NULL},{16,NULL,18,NULL,20},{NULL,22,NULL,24,NULL}}|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000|13.000000
16|{{1,3.1,5.2},{NULL,NULL,11.5},{13.6,NULL,NULL}}|6.939697|6.880000|6.909550|6.933641|6.939697|6.933641|6.933641|6.933641|6.933641|6.933641|6.933641|6.933641|6.933641|6.933641
17|{{NULL,3.14,NULL},{NULL,12.56,NULL},{NULL,NULL,25.12}}|12.560000|12.560000|12.560000|12.560000|12.560000|12.560000|12.546978|12.527446|12.494891|12.462337|12.442804|12.431085|12.429913|12.429783