| 540 | == '''Objective FV.19 - Being able burn geometries to existing raster''' == |
| 541 | |
| 542 | '''ST_BurnToRaster(rast, geometry[, value, expression, nodata1expr, nodata2expr, nodatanodataexpr]) -> raster''' |
| 543 | |
| 544 | * Burn a raster to the band of an existing raster. |
| 545 | |
| 546 | * No geoferencing metadata have to be provided since the ones of the provided raster are used. |
| 547 | |
| 548 | * This function is mostly different from the ST_AsRaster(geometry) by the fact that it must provide some options to take into account the existing pixel values when burning the new value associated with the geometry. |
| 549 | |
| 550 | * It should be implemented as some wrappers around ST_MapAlgebra(raster, band, ST_AsRaster(geometry, val, raster, "CROP"), 'expression', 'nodata1expr', 'nodata2expr', 'nodatanodataexpr'). |
| 551 | |
| 552 | * 'expression', 'nodata1expr', 'nodata2expr', 'nodatanodataexpr' are SQL expressions passed to the underlying two raster map algebra function: |
| 553 | |
| 554 | -'expression' is evaluated when both pixels have a value associated with them. The default for this expression is 'LAST'.[[BR]] |
| 555 | -'nodata1expr' is evaluated when rast1 is a nodata value and rast2 has a value associated with it. The default for this expression is NULL.[[BR]] |
| 556 | -'nodata2expr' is evaluated when rast2 is a nodata value and rast1 has a value associated with it. The default for this expression is NULL.[[BR]] |
| 557 | -'nodatanodataexpr' is evaluated when both pixels are nodata values. The default for this expression is NULL. |
| 558 | |
| 559 | * Here are some commonly used predefined expressions and how they materialize as the ST_Mapalgebra(rast1, rast2) expression, nodata1expr and nodata2expr, and nodatanodataexpr. |
| 560 | |
| 561 | -LAST: expression = 'rast2'. This is the default ST_BurnToRaster expression. |
| 562 | |
| 563 | -COUNT: expression = '2', nodata1expr = '1', nodata2expr = '1', nodatanodataexpr = '0' |
| 564 | |
| 565 | -MAX: expression = 'GREATEST(rast1, rast2)' , nodata1expr = 'rast2', nodata2expr = 'rast1', nodatanodataexpr = 'NULL' |
| 566 | |
| 567 | -MIN: expression = 'LEAST(rast1, rast2)' , nodata1expr = 'rast2', nodata2expr = 'rast1', nodatanodataexpr = 'NULL' |
| 568 | |
| 569 | -RANGE: expression = 'ABS(rast1 - rast2)' , nodata1expr = '0', nodata2expr = '0', nodatanodataexpr = 'NULL' |
| 570 | |
| 571 | -SUM: expression = 'rast1 + rast2' , nodata1expr = 'rast2', nodata2expr = 'rast1', nodatanodataexpr = 'NULL' |
| 572 | |
| 573 | -MEAN: expression = '(rast1 + rast2)/2' , nodata1expr = 'rast2', nodata2expr = 'rast1', nodatanodataexpr = 'NULL' |
| 574 | |
| 575 | * When expression is 'LAST' the process can be implemented with GDALRasterizeLayers since, apparently GDALRasterizeLayers do not allow other burning rules. |
| 576 | |
| 577 | '''ST_UnionToRaster(set of geometry[, p_expr, t_expr, f_expr]) -> raster''' |
| 578 | |
| 579 | * ST_UnionToRaster is an aggregate function very similar to ST_Union(set of raster) which burn, one after the other, all the geometries of a table, or selected by a GROUP BY clause, into a unique raster. |
| 580 | |
| 581 | * It is implemented as a wrapper around ST_Union(ST_AsRaster(geometry, value, raster, band, p_expression, t_expression, f_expression)) function. |
| 582 | |
| 583 | * Variants |
| 584 | |
| 585 | 1) ToRaster(raster, band, geometry, val) |
| 586 | 2) ToRaster(raster, band, geometry, val, p_expression) |
| 587 | 3) ToRaster(raster, band, geometry, val, p_expression, t_expression) |
| 588 | 4) ToRaster(raster, band, geometry, val, p_expression, t_expression, f_expression) |
| 589 | |
| 590 | ---- |