[postgis-users] Behavior of ST_MapAlgebraFctNgb

dustymugs dustymugs at gmail.com
Thu Sep 13 14:41:54 PDT 2012


Hey all,

I'm trying to make use of ST_MapAlgebraFctNgb to do some inverse
distance weighting and noticed some unexpected behavior.

{{{
CREATE OR REPLACE FUNCTION ngb_test(matrix float8[][], nodatamode text,
VARIADIC args text[])
	RETURNS float8
	AS $$
	DECLARE
	BEGIN
		RAISE NOTICE '%', matrix;
		RETURN 255;
	END;
	$$ LANGUAGE 'plpgsql';

WITH foo AS (
SELECT
	ST_SetValues(
		ST_AddBand(
			ST_MakeEmptyRaster(5, 5, 0, 0, 1, -1, 0, 0, 0)
			, 1, '8BUI', 0, 0
		)
		, 1, 1, 1, ARRAY[
			[ 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]
		]::double precision[]
	) AS rast
)
SELECT
	(ST_PixelAsPoints(
		st_mapalgebrafctngb(rast, 1, NULL, 1, 1,
'ngb_test(float8[][],text,text[])'::regprocedure, 'NULL', NULL)
	)).*
FROM foo
}}}

In testing the neighborhood, the ngb_test function is only being called
for the interior pixels.  The function isn't called for the pixels found
at the edges.

Is this expected behavior?  My guess is no as far as my understanding of
the specs...

http://trac.osgeo.org/postgis/wiki/WKTRaster/SpecificationWorking02

"3) ST_MapAlgebraFctNgb(rast raster, band int, pixeltype text, radius
int, funcname text[, funcargs text]) - A one raster version taking a
user defined function (with optional parameters) of the set of first,
second, etc... neighbours of a pixel. The function is a user defined
PL/pgSQL function taking a matrix containing the neighbour values and
returning one value. Code do not exist yet but will be very much similar
to 2). Out of bound pixels values are set to NULL. This version requires
the user to write a PL/pgSQL function. Many predefined function should
be delivered."

The key part for me is that "Out of bound pixels values are set to
NULL.", which isn't how ST_MapAlgebraFctNgb is currently behaving.

-bborie



More information about the postgis-users mailing list