20 | | |
21 | | ---- |
22 | | |
23 | | == '''Objective FV.02 - Being able to intersect vector and raster to produce raster.''' == |
24 | | |
25 | | |
26 | | '''ST_Intersects(raster, raster) -> boolean - done see below'''[[BR]] |
27 | | |
28 | | '''ST_AsRaster(geometry, pixeltype, val, nodataval, ulx, uly, width, height, pixelsizex, pixelsizey, skewx, skewy) -> raster - done see below''' |
29 | | |
30 | | '''ST_Intersection(geometry, val, raster, band) -> raster''' |
31 | | |
32 | | The first series of variant return a raster having the same extent as the provided raster. |
33 | | |
34 | | Variant 1: ST_Intersection(geometry, val, raster, band, pixeltype, nodatavalue) -> raster |
35 | | |
36 | | Variant 2: ST_Intersection(raster, band, geometry, val, pixeltype, nodatavalue) -> raster |
37 | | |
38 | | Variant 3: ST_Intersection(geometry, val, raster, pixeltype, nodatavalue) -> raster |
39 | | |
40 | | Variant 4: ST_Intersection(raster, geometry, val, pixeltype, nodatavalue) -> raster |
41 | | |
42 | | The second series of variant return a raster having the minimal extent. |
43 | | |
44 | | Variant 5: ST_Intersection(geometry, val, raster, band, pixeltype, nodatavalue, 'TRIM') -> raster |
45 | | |
46 | | Variant 6: ST_Intersection(raster, band, geometry, val, pixeltype, nodatavalue, 'TRIM') -> raster |
47 | | |
48 | | Variant 7: ST_Intersection(geometry, val, raster, pixeltype, nodatavalue, 'TRIM') -> raster |
49 | | |
50 | | Variant 8: ST_Intersection(raster, geometry, val, pixeltype, nodatavalue, 'TRIM') -> raster |
51 | | |
52 | | Returns a two bands raster the first band containing only the pixels from the provided raster intersecting with the geometry and the second band containing the same area filled with the provided value. |
53 | | |
54 | | The second band gets its pixeltype and nodatavalue from the parameters. |
55 | | |
56 | | Non intersecting pixels are filled with nodata values. |
57 | | |
58 | | Variant 1 return a raster having the same extent as the provided raster. |
59 | | |
60 | | Variant 3, 4, 7 and 8 defaults the band number to 1. |
61 | | |
62 | | Variant 5 to 8 "trim" or "crop" the raster to the withvalue extent (removing extra nodata value pixels surrounding the extent of the resulting withvalue extent). |
63 | | |
64 | | |
65 | | '''Open questions''' |
66 | | |
67 | | PR: Shoud we return one raster per raster/geometry couple or split the raster into as many small rasters as there are areas sharing a same value? The second behavior seems more coherent with the present behavior of ST_Intersection(raster, geometry) -> geometry even if this would produce tons of small two bands rasters. |
68 | | |
69 | | '''Implementation details''' |
70 | | |
71 | | Rasterize the geometry as a new raster (ST_AsRaster(geometry, pixeltype, val, nodataval, raster)) and then copy only pixels for which both raster bands have a value. |
72 | | Should be implemented as a wrapper around ST_MapAlgebra after rasterizing the geometry to a raster having the same alignment as the raster. |
| 1432 | '''ST_Intersection(raster, band, geometry) -> raster''' |
| 1433 | |
| 1434 | ST_Intersection is plpgsql function wrapping the two-raster ST_MapAlgebra functions. Performance should be about the same as calling ST_MapAlgebra directly except for the case where returnband is BOTH as that results in two separate ST_MapAlgebra calls. |
| 1435 | |
| 1436 | A set of ST_Intersection functions for raster, raster. |
| 1437 | |
| 1438 | {{{ |
| 1439 | 1. ST_Intersection( |
| 1440 | rast1 raster, nband1 int, |
| 1441 | rast2 raster, nband2 int, |
| 1442 | returnband text DEFAULT 'BOTH', |
| 1443 | otheruserfunc regprocedure DEFAULT NULL |
| 1444 | ); |
| 1445 | }}} |
| 1446 | |
| 1447 | returnband: can be FIRST, SECOND, BOTH, OTHER |
| 1448 | |
| 1449 | * FIRST returns the band of rast1 in the intersecting extent. returning raster will have one band. |
| 1450 | * SECOND returns the band of rast2 in the intersecting extent. returning raster will have one band. |
| 1451 | * BOTH returns the bands of rast1 and rast2 in the intersection extent. returning raster will have two bands. |
| 1452 | * OTHER returns the computed band based upon rast1 and rast2 in the intersecting extent. returning raster will have one band. If OTHER, must provide a regprocedure to otherfunc |
| 1453 | |
| 1454 | otheruserfunc: function to call when returnband = OTHER. Function format must be identical to tworastuserfunc of 2-raster ST_MapAlgebraFct. |
| 1455 | |
| 1456 | {{{ |
| 1457 | 2. ST_Intersection( |
| 1458 | rast1 raster, nband1 int, |
| 1459 | rast2 raster, nband2 int, |
| 1460 | otheruserfunc regprocedure |
| 1461 | ); |
| 1462 | }}} |
| 1463 | |
| 1464 | {{{ |
| 1465 | 3. ST_Intersection( |
| 1466 | rast1 raster, |
| 1467 | rast2 raster, |
| 1468 | returnband text DEFAULT 'BOTH', |
| 1469 | otheruserfunc regprocedure DEFAULT NULL |
| 1470 | ); |
| 1471 | }}} |
| 1472 | |
| 1473 | {{{ |
| 1474 | 4. ST_Intersection( |
| 1475 | rast1 raster, |
| 1476 | rast2 raster, |
| 1477 | otheruserfunc regprocedure |
| 1478 | ); |
| 1479 | }}} |
| 1480 | |
| 1481 | A set of ST_Intersection functions for raster, geometry (converted to raster). |
| 1482 | |
| 1483 | {{{ |
| 1484 | 1. ST_Intersection( |
| 1485 | rast raster, nband int, |
| 1486 | geom geometry, |
| 1487 | extent text DEFAULT 'INTERSECTION', |
| 1488 | otheruserfunc regprocedure DEFAULT NULL |
| 1489 | ) |
| 1490 | }}} |
| 1491 | |
| 1492 | extent: can be INTERSECTION, FIRST, SECOND, UNION though FIRST and INTERSECTION will probably be the most commonly used |
| 1493 | |
| 1494 | {{{ |
| 1495 | 2. ST_Intersection( |
| 1496 | rast raster, nband int, |
| 1497 | geom geometry, |
| 1498 | otheruserfunc regprocedure |
| 1499 | ); |
| 1500 | }}} |
| 1501 | |
| 1502 | {{{ |
| 1503 | 3. ST_Intersection( |
| 1504 | rast raster, |
| 1505 | geom geometry, |
| 1506 | extent text DEFAULT 'INTERSECTON', |
| 1507 | otheruserfunc regprocedure DEFAULT NULL |
| 1508 | ); |
| 1509 | }}} |
| 1510 | |
| 1511 | {{{ |
| 1512 | 4. ST_Intersection( |
| 1513 | rast raster, |
| 1514 | geom geometry, |
| 1515 | otheruserfunc regprocedure |
| 1516 | ); |
| 1517 | }}} |
| 1518 | |
| 1519 | ~~ The first series of variant return a raster having the same extent as the provided raster. |
| 1520 | |
| 1521 | ~~ Variant 1: ST_Intersection(geometry, val, raster, band, pixeltype, nodatavalue) -> raster |
| 1522 | |
| 1523 | ~~ Variant 2: ST_Intersection(raster, band, geometry, val, pixeltype, nodatavalue) -> raster |
| 1524 | |
| 1525 | ~~ Variant 3: ST_Intersection(geometry, val, raster, pixeltype, nodatavalue) -> raster |
| 1526 | |
| 1527 | ~~ Variant 4: ST_Intersection(raster, geometry, val, pixeltype, nodatavalue) -> raster |
| 1528 | |
| 1529 | ~~ The second series of variant return a raster having the minimal extent. |
| 1530 | |
| 1531 | ~~ Variant 5: ST_Intersection(geometry, val, raster, band, pixeltype, nodatavalue, 'TRIM') -> raster |
| 1532 | |
| 1533 | ~~ Variant 6: ST_Intersection(raster, band, geometry, val, pixeltype, nodatavalue, 'TRIM') -> raster |
| 1534 | |
| 1535 | ~~ Variant 7: ST_Intersection(geometry, val, raster, pixeltype, nodatavalue, 'TRIM') -> raster |
| 1536 | |
| 1537 | ~~ Variant 8: ST_Intersection(raster, geometry, val, pixeltype, nodatavalue, 'TRIM') -> raster |
| 1538 | |
| 1539 | ~~ Returns a two bands raster the first band containing only the pixels from the provided raster intersecting with the geometry and the second band containing the same area filled with the provided value. |
| 1540 | |
| 1541 | ~~ The second band gets its pixeltype and nodatavalue from the parameters. |
| 1542 | |
| 1543 | ~~ Non intersecting pixels are filled with nodata values. |
| 1544 | |
| 1545 | ~~ Variant 1 return a raster having the same extent as the provided raster. |
| 1546 | |
| 1547 | ~~ Variant 3, 4, 7 and 8 defaults the band number to 1. |
| 1548 | |
| 1549 | ~~ Variant 5 to 8 "trim" or "crop" the raster to the withvalue extent (removing extra nodata value pixels surrounding the extent of the resulting withvalue extent). |
| 1550 | |
| 1551 | |
| 1552 | ~~ '''Open questions''' |
| 1553 | |
| 1554 | ~~ PR: Shoud we return one raster per raster/geometry couple or split the raster into as many small rasters as there are areas sharing a same value? The second behavior seems more coherent with the present behavior of ST_Intersection(raster, geometry) -> geometry even if this would produce tons of small two bands rasters. |
| 1555 | |
| 1556 | ~~ '''Implementation details''' |
| 1557 | |
| 1558 | ~~ Rasterize the geometry as a new raster (ST_AsRaster(geometry, pixeltype, val, nodataval, raster)) and then copy only pixels for which both raster bands have a value. |
| 1559 | ~~ Should be implemented as a wrapper around ST_MapAlgebra after rasterizing the geometry to a raster having the same alignment as the raster. |
| 1560 | |