]> granicus.if.org Git - postgis/commitdiff
Added ST_Distinct4ma helper neighborhood processing function. See #1318
authorDavid Zwarg <dzwarg@azavea.com>
Wed, 8 Feb 2012 00:43:28 +0000 (00:43 +0000)
committerDavid Zwarg <dzwarg@azavea.com>
Wed, 8 Feb 2012 00:43:28 +0000 (00:43 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9090 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_pg/rtpostgis.sql.in.c
raster/test/regress/rt_mapalgebrafctngb_userfunc.sql
raster/test/regress/rt_mapalgebrafctngb_userfunc_expected

index ea1614efec2933c46d3beb634e8e9aed14fbd17c..f166d87aded1459b2cf056e1f994cdd437076669 100644 (file)
@@ -2075,6 +2075,18 @@ CREATE OR REPLACE FUNCTION st_hillshade(rast raster, band integer, pixeltype tex
     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
index abb0e1a63a900f697dea5a2f0af2454f0e4ee956..9a01380d93939238a251566c31561f5825197700 100644 (file)
@@ -218,3 +218,22 @@ SELECT
     ), 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;
index e73d999c6e784c124d1efbe7b4e767fe169d2f1a..9510b311809f225fb86ce5e28497ae400d8c728f 100644 (file)
@@ -29,3 +29,5 @@ t|t
 t|t
 t
 t
+t|t
+t|t