[postgis-devel] [PostGIS] #2030: [raster] n-raster ST_MapAlgebra
PostGIS
trac at osgeo.org
Thu Oct 4 14:17:48 PDT 2012
#2030: [raster] n-raster ST_MapAlgebra
-------------------------+--------------------------------------------------
Reporter: dustymugs | Owner: dustymugs
Type: enhancement | Status: assigned
Priority: medium | Milestone: PostGIS 2.1.0
Component: raster | Version: trunk
Keywords: |
-------------------------+--------------------------------------------------
Changes (by dustymugs):
* status: new => assigned
Comment:
Core signature for the n-raster ST_MapAlgebra...
With 1 or more rasters being passed to the function, a new composite type
is needed. This type should be usable for many future applications as it
is just denoting a very fundamental idea: Band b of Raster r.
{{{
CREATE TYPE rastbandarg AS (
rast raster,
nband integer
);
}}}
The main function calling the C back-end is a non-user function.
{{{
CREATE OR REPLACE FUNCTION _st_mapalgebra(
rastbandargset rastbandarg[],
callbackfunc regprocedure,
pixeltype text DEFAULT NULL,
distancex integer DEFAULT 0, distancey integer DEFAULT 0,
extenttype text DEFAULT 'INTERSECTION',
customextent raster DEFAULT NULL,
VARIADIC userargs text[] DEFAULT NULL
)
RETURNS boolean
AS 'MODULE_PATHNAME', 'RASTER_nMapAlgebra'
LANGUAGE 'c' STABLE;
}}}
Still haven't thought of actual user function signatures but some actual
use cases that come to mind are below.
Do neighborhood operation on a tile taking into account neighboring tiles.
The output raster would have the extent of the input custom extent, which
is the tile of interest.
{{{
SELECT ST_MapAlgebra(
ARRAY[ROW(ST_Union(f2.rast), 1)]::rastbandarg[],
'ngbfunc(float[][][], boolean[][][], int[][][],
text[])'::regprocedure,
NULL,
1, 1,
'CUSTOM',
f1.rast
)
FROM foo f1
JOIN foo f2
ON ST_Intersects(f1.rast, f2.rast)
WHERE f1.rid = 1
}}}
A multi-band operation, such as for computing EVI or NDVI.
{{{
SELECT ST_MapAlgebra(
ARRAY[ROW(rast, 1), ROW(rast, 4)]::rastbandarg[],
'evi(float[][][], boolean[][][], int[][][], text[])'::regprocedure
)
FROM foo
}}}
If you noticed above, the callback function is different than in PostGIS
2.0. A correct callback should look like...
{{{
callbackfunc(value float[][][], nodata boolean[][][], pos int[][],
variadic userargs text[])
}}}
The parameters "value" and "nodata" are now 3D arrays:
{{{
value[RASTER_NUM][ROW_Y][COLUMN_X] = pixel value
nodata[RASTER_NUM][ROW_Y][COLUMN_X] = pixel is NODATA (TRUE or FALSE)
where RASTER_NUM, ROW_Y, COLUMN_X are 1-based, starting from 1.
}}}
pos[][] is a 2D array with 2 elements in the second dimension of the X, Y
position of the source pixel of interest.
{{{
pos[RASTER_NUM] = [COLUMN_X, ROW_Y]
}}}
--
Ticket URL: <http://trac.osgeo.org/postgis/ticket/2030#comment:4>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.
More information about the postgis-devel
mailing list