AS $$ SELECT st_mapalgebrafctngb($1, $2, $3, 1, 1, '_st_hillshade4ma(float[][], text, text[])'::regprocedure, 'value', st_pixelwidth($1)::text, st_pixelheight($1)::text, $4::text, $5::text, $6::text, $7::text) $$
LANGUAGE 'SQL' STABLE;
+CREATE OR REPLACE FUNCTION st_distinct4ma(matrix float[][], nodatamode TEXT, VARIADIC args TEXT[])
+ RETURNS float
+ AS
+ $$
+ DECLARE
+ _count integer;
+ BEGIN
+ RETURN (SELECT COUNT(DISTINCT unnest) FROM unnest(matrix));
+ END;
+ $$
+ LANGUAGE 'plpgsql' IMMUTABLE;
+
-----------------------------------------------------------------------
-- Get information about the raster
), 3, 3, 2477
) AS rast;
+-- test st_distinct4ma, all one value
+SELECT
+ ST_Value(rast, 2, 2) = 10,
+ ST_Value(
+ ST_MapAlgebraFctNgb(rast, 1, NULL, 1, 1, 'st_distinct4ma(float[][], text, text[])'::regprocedure, '1', NULL), 2, 2
+ ) = 1
+ FROM ST_TestRasterNgb(3, 3, 10) AS rast;
+
+-- test st_distinct4ma, three distinct values
+SELECT
+ ST_Value(rast, 2, 2) = 1,
+ ST_Value(
+ ST_MapAlgebraFctNgb(rast, 1, NULL, 1, 1, 'st_distinct4ma(float[][], text, text[])'::regprocedure, '1', NULL), 2, 2
+ ) = 3
+ FROM ST_SetValue(
+ ST_SetValue(
+ ST_TestRasterNgb(3, 3, 1), 1, 1, 5
+ ), 3, 3, 7
+ ) AS rast;