From: David Zwarg Date: Wed, 8 Feb 2012 00:43:28 +0000 (+0000) Subject: Added ST_Distinct4ma helper neighborhood processing function. See #1318 X-Git-Tag: 2.0.0alpha4~15 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3f209b47b6e406f735294d36a12ec9de87081dfe;p=postgis Added ST_Distinct4ma helper neighborhood processing function. See #1318 git-svn-id: http://svn.osgeo.org/postgis/trunk@9090 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_pg/rtpostgis.sql.in.c b/raster/rt_pg/rtpostgis.sql.in.c index ea1614efe..f166d87ad 100644 --- a/raster/rt_pg/rtpostgis.sql.in.c +++ b/raster/rt_pg/rtpostgis.sql.in.c @@ -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 diff --git a/raster/test/regress/rt_mapalgebrafctngb_userfunc.sql b/raster/test/regress/rt_mapalgebrafctngb_userfunc.sql index abb0e1a63..9a01380d9 100644 --- a/raster/test/regress/rt_mapalgebrafctngb_userfunc.sql +++ b/raster/test/regress/rt_mapalgebrafctngb_userfunc.sql @@ -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; diff --git a/raster/test/regress/rt_mapalgebrafctngb_userfunc_expected b/raster/test/regress/rt_mapalgebrafctngb_userfunc_expected index e73d999c6..9510b3118 100644 --- a/raster/test/regress/rt_mapalgebrafctngb_userfunc_expected +++ b/raster/test/regress/rt_mapalgebrafctngb_userfunc_expected @@ -29,3 +29,5 @@ t|t t|t t t +t|t +t|t