199 | | == '''Objective FV.03 - Being able to use neighbour pixels in !MapAlgebra expressions.''' == |
| 199 | == '''Objective FV.03 - Implement all the necessary version of ST_MapAlgebra''' == |
| 200 | |
| 201 | Different versions of ST_MapAlgebra are planned... |
| 202 | |
| 203 | One raster versions: |
| 204 | |
| 205 | 1) '''ST_MapAlgebraExpr() -''' A one raster version taking an '''expression''' of one pixel at a time. Already implemented... |
| 206 | |
| 207 | 2) '''ST_MapAlgebraFct() -''' A one raster version taking a '''user defined function''' (with optional parameters) of one pixel at a time. The function is a user defined PL/pgSQL function taking a float8 value and returning a value. Code was developped by David Zwarg, needs to be integrated in the source tree. This version is much faster than 1) but requires the user to write a PL/pgSQL function. |
| 208 | |
| 209 | 3) '''ST_MapAlgebraFctNgb() -''' 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. |
| 210 | |
| 211 | 4) '''ST_MapAlgebraFctNgb() -''' A one raster version taking a '''table name and a raster column name''' (in order to work on a '''tiled coverage''') and a '''user defined function''' (with optional parameters) of the set of first, second, etc... '''neighbours''' of a pixel. The passed matrix should include values for out of bound pixels taken from neighbour tiles. |
| 212 | |
| 213 | Two rasters versions. These versions must take into account different alignment, different extents, nodata and non-existent values. |
| 214 | |
| 215 | 5) '''ST_MapAlgebraExpr() -''' A two rasters version taking an expression of two pixels at a time, one from each rasters. |
| 216 | |
| 217 | 6) '''ST_MapAlgebraExpr() -''' A two rasters version taking a '''table name and a raster column name''' (in order to work on a '''tiled coverage''') and an expression of two pixels at a time, one from each rasters. |
| 218 | |
| 219 | 7) '''ST_MapAlgebraFct() -''' A two rasters version taking a '''user defined function''' (with optional parameters) of two pixels at a time, one from each rasters. The function is a user defined PL/pgSQL function taking two float8 values and returning one value. |
| 220 | |
| 221 | 8) '''ST_MapAlgebraFct() -''' A two rasters version taking a '''table name and a raster column name''' (in order to work on a '''tiled coverage''') and a '''user defined function''' (with optional parameters) of two pixels at a time, one from each rasters. The function is a user defined PL/pgSQL function taking two float8 values and returning one value. Non-existent values are found in the neighbour tiles when possible. |
| 222 | |
| 223 | |
| 224 | |
| 225 | '''Details for 3) ST_MapAlgebraFctNgb()''' |
| 265 | |
| 266 | |
| 267 | |
| 268 | '''Details for 5) to 8) Two rasters versions''' |
| 269 | |
| 270 | These function must first determine if a resampling of one raster is necessary: |
| 271 | |
| 272 | '''ST_SameAlignment(raster, raster)''' |
| 273 | |
| 274 | This function returns true if both rasters' grids are aligned. |
| 275 | |
| 276 | Two rasters grid are aligned if: |
| 277 | |
| 278 | -They share the same pixel scales and skews |
| 279 | |
| 280 | -At least one of any of the four corner of any pixel of one raster fall on any corner of the grid of the other raster. |
| 281 | |
| 282 | Alignment is not the same concept as georeference. Two rasters can be aligned but not have the same georeference. |
| 283 | |
| 284 | Rotation is important here since two rasters grid might look perfectly aligned but are not if their rotated are different. |
| 285 | |
| 286 | Knowing if two rasters share the same alignment is useful when it is time to decide if one of them must be resampled before doing other operations (like ST_MapAlgebra on two rasters). |
| 287 | |
| 288 | '''Variants''' |
| 289 | |
| 290 | 1) ST_SameAlignment(ulx1, uly1, scalex1, scaley1, skewx1, skewy1, ulx2, uly2, scalex2, scaley2, skewx2, skewy2) |
| 291 | |
| 292 | 2) ST_SameAlignment(rast1 raster, rast2 raster) |
| 293 | |
| 294 | The first variant is useful to PL/pgSQL function which have already get the values of the parameters. |
| 295 | |
| 296 | '''Implementation Details''' |
| 297 | |
| 298 | Only the first variant should be implemented in C. The second one is a PL/pgSQL variants. The C implementation should follow the PL/pgSQL version implemented in http://trac.osgeo.org/postgis/browser/trunk/raster/scripts/plpgsql/st_mapalgebra.sql |
| 299 | |
| 300 | It is not clear if this PL/pgSQL implementation works when raster are rotated. To verify. |
| 301 | |
| 302 | See discussion in http://trac.osgeo.org/postgis/ticket/589 |
| 303 | |
| 304 | |
| 305 | '''ST_MapAlgebra on two rasters''' |
| 306 | |
| 307 | Specifications of ST_MapAlgebra on two rasters are still in progress as a new optimised version, filling large areas of same value more quickly, is planned. See http://trac.osgeo.org/postgis/browser/trunk/raster/scripts/plpgsql/st_mapalgebra_optimized.sql |
| 308 | |
| 309 | See discussion in http://trac.osgeo.org/postgis/ticket/590 |
| 310 | |