Schema
Owner
postgres
Descriptions
There is no description for function _st_roughness4ma
Options
Option | Value |
---|---|
Returns |
double precision |
Language |
|
Parameters |
value double precision [] pos integer [] variadic userargs text [] = NULL::text[] |
Definition
CREATE OR REPLACE FUNCTION public._st_roughness4ma (
value double precision [],
pos integer [],
variadic userargs text [] = NULL::text[]
)
RETURNS double precision AS
$span$
DECLARE
x integer;
y integer;
z integer;
minimum double precision;
maximum double precision;
_value double precision[][][];
ndims int;
BEGIN
ndims := array_ndims(value);
-- add a third dimension if 2-dimension
IF ndims = 2 THEN
_value := public._ST_convertarray4ma(value);
ELSEIF ndims != 3 THEN
RAISE EXCEPTION 'First parameter of function must be a 3-dimension array';
ELSE
_value := value;
END IF;
-- only use the first raster passed to this function
IF array_length(_value, 1) > 1 THEN
RAISE NOTICE 'Only using the values from the first raster';
END IF;
z := array_lower(_value, 1);
IF (
array_lower(_value, 2) != 1 OR array_upper(_value, 2) != 3 OR
array_lower(_value, 3) != 1 OR array_upper(_value, 3) != 3
) THEN
RAISE EXCEPTION 'First parameter of function must be a 1x3x3 array with each of the lower bounds starting from 1';
END IF;
-- check that center pixel isn't NODATA
IF _value[z][2][2] IS NULL THEN
RETURN NULL;
-- substitute center pixel for any neighbor pixels that are NODATA
ELSE
FOR y IN 1..3 LOOP
FOR x IN 1..3 LOOP
IF _value[z][y][x] IS NULL THEN
_value[z][y][x] = _value[z][2][2];
END IF;
END LOOP;
END LOOP;
END IF;
minimum := _value[z][1][1];
maximum := _value[z][1][1];
FOR Y IN 1..3 LOOP
FOR X IN 1..3 LOOP
IF _value[z][y][x] < minimum THEN
minimum := _value[z][y][x];
ELSIF _value[z][y][x] > maximum THEN
maximum := _value[z][y][x];
END IF;
END LOOP;
END LOOP;
RETURN maximum - minimum;
END;
$span$
LANGUAGE 'plpgsql'
IMMUTABLE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100;
This file was generated with SQL Manager for PostgreSQL (www.pgsqlmanager.com) at 13/03/2014 13:23 |