| 1440 | |
| 1441 | == '''Objective FV.03 - ST_MapAlgebra (1 and 2 raster variants)''' == |
| 1442 | |
| 1443 | '''Two raster ST_MapAlgebra''' |
| 1444 | |
| 1445 | These set of functions take two input rasters and create a 1-band output raster with the extent defined by extenttype. |
| 1446 | |
| 1447 | |
| 1448 | 1. ST_MapAlgebra2Expr( |
| 1449 | rast1 raster, band1 integer,[[BR]] |
| 1450 | rast2 raster, band2 integer,[[BR]] |
| 1451 | expression text,[[BR]] |
| 1452 | pixeltype text DEFAULT NULL, extenttype text DEFAULT 'INTERSECTION',[[BR]] |
| 1453 | nodata1expr text DEFAULT NULL, nodata2expr text DEFAULT NULL,[[BR]] |
| 1454 | nodatanodataval double precision DEFAULT NULL |
| 1455 | ) -> raster |
| 1456 | |
| 1457 | rast1: the FIRST raster upon which a map algebra operation is to be done |
| 1458 | |
| 1459 | band1: the band index (1-based) of the FIRST raster upon whose pixels a map algebra operation is to be done |
| 1460 | |
| 1461 | rast2: the SECOND raster upon which a map algebra operation is to be done |
| 1462 | |
| 1463 | band2: the band index (1-based) of the SECOND raster upon whose pixels a map algebra operation is to be done |
| 1464 | |
| 1465 | expression: valid SQL expression resulting in a double precision value or NULL. called when band 1 pixel AND band 2 pixel are NOT NODATA |
| 1466 | |
| 1467 | pixeltype: the datatype of the output raster's one band |
| 1468 | |
| 1469 | extenttype: one of the following (INTERSECTION, UNION, FIRST, SECOND) |
| 1470 | |
| 1471 | nodata1expr: valid SQL expression resulting in a double precision value or NULL. called when band 1 pixel IS NODATA and band 2 pixel IS NOT NODATA |
| 1472 | |
| 1473 | nodata2expr: valid SQL expression resulting in a double precision value or NULL. called when band 1 pixel IS NOT NODATA and band 2 pixel IS NODATA |
| 1474 | |
| 1475 | nodatanodataval: double precision value used when band1 pixel and band 2 pixel are NODATA |
| 1476 | |
| 1477 | {{{ |
| 1478 | ST_MapAlgebra2Expr(r1.rast, 1, r2.rast, 2, 'rast1', '32BF', 'INTERSECTION') |
| 1479 | |
| 1480 | ST_MapAlgebra2Expr(r1.rast, 1, r2.rast, 2, '((rast1 + rast2)/2.)::numeric', '32BF', 'UNION', 'rast2', 'rast1', NULL) |
| 1481 | |
| 1482 | ST_MapAlgebra2Expr(r1.rast, 1, r2.rast, 2, 'CASE WHEN rast2 IS NOT NULL THEN NULL ELSE rast1 END', '32BF', 'FIRST', NULL, 'rast1', NULL) |
| 1483 | |
| 1484 | ST_MapAlgebra2Expr(r1.rast, 1, r2.rast, 2, 'CASE WHEN rast1 IS NOT NULL THEN NULL ELSE rast2 END', '32BF', 'SECOND', 'rast2', NULL, NULL) |
| 1485 | }}} |
| 1486 | |
| 1487 | 2. ST_MapAlgebra2Expr( |
| 1488 | rast1 raster,[[BR]] |
| 1489 | rast2 raster,[[BR]] |
| 1490 | expression text,[[BR]] |
| 1491 | pixeltype text DEFAULT NULL, extenttype text DEFAULT 'INTERSECTION',[[BR]] |
| 1492 | nodata1expr text DEFAULT NULL, nodata2expr text DEFAULT NULL,[[BR]] |
| 1493 | nodatanodataval double precision DEFAULT NULL |
| 1494 | ) -> raster |
| 1495 | |
| 1496 | {{{ |
| 1497 | ST_MapAlgebra2Expr(r1.rast, r2.rast, 'rast1', '32BF', 'INTERSECTION') |
| 1498 | |
| 1499 | ST_MapAlgebra2Expr(r1.rast, r2.rast, '((rast1 + rast2)/2.)::numeric', '32BF', 'UNION', 'rast2', 'rast1', NULL) |
| 1500 | |
| 1501 | ST_MapAlgebra2Expr(r1.rast, r2.rast, 'CASE WHEN rast2 IS NOT NULL THEN NULL ELSE rast1 END', '32BF', 'FIRST', NULL, 'rast1', NULL) |
| 1502 | |
| 1503 | ST_MapAlgebra2Expr(r1.rast, r2.rast, 'CASE WHEN rast1 IS NOT NULL THEN NULL ELSE rast2 END', '32BF', 'SECOND', 'rast2', NULL, NULL) |
| 1504 | }}} |
| 1505 | |
| 1506 | |
| 1507 | ---- |