| 57 | ---- |
| 58 | == '''Objective B02x - Being able to clip a raster.''' == |
| 59 | |
| 60 | '''ST_Clip''' |
| 61 | |
| 62 | '''Variants''' |
| 63 | |
| 64 | 1) ST_Clip(raster, ulx, uly, lrx, lry) -> raster |
| 65 | |
| 66 | 2) ST_Clip(raster, geometry) -> raster |
| 67 | |
| 68 | 3) ST_Clip(raster, geometry, 'EXACT') -> raster |
| 69 | |
| 70 | Returns the subset of a raster as a raster. |
| 71 | |
| 72 | All metadata are copied from the source raster (except ulx, uly, width and height which must be computed). |
| 73 | |
| 74 | Variant 1) takes the upper left and lower left corner of the desired zone. Variant 2) determine the extent of this zone from the extent of a geometry. Variant 3) determine the extent of this zone from the extent of a geometry and set all pixel outside the geometry to no data values. |
| 75 | |
| 76 | If the geometry is totally included into one pixel (a point for example), only this pixel is kept in the returned raster. |
| 77 | |
| 78 | '''Implementation details''' |
| 79 | |
| 80 | Implemented as a wrapper around ST_MapAlgebra. |
| 81 | |
| 82 | newrast := ST_AddBand(ST_MakeEmptyRaster(x2 - x1, y2 - y1, |
| 83 | ST_Raster2WorldCoordX(rast, x1, y2), |
| 84 | ST_Raster2WorldCoordY(rast, x1, y2), |
| 85 | ST_PixelSizeX(rast), |
| 86 | ST_PixelSizeY(rast), |
| 87 | ST_SkewX(rast), |
| 88 | ST_SkewY(rast), |
| 89 | ST_SRID(rast)), ‘1BB’, 1, 0) |
| 90 | newrast := ST_MultiBandMapAlgebra(rast, newrast, ‘r1’, ‘INTERSECTION’) |
| 91 | |
| 92 | Could also be implemented as ST_Intersection -> ST_Band(ST_Intersection(geometry, raster, band, “TRIM”), 1) Would require some kind of TRIM and would be slower. |
| 93 | |
| 94 | This function is necessary to optimize ST_Intersection. The raster to be polygonised before proceeding to a vector intersection should first be clipped to the minimal intersecting area using ST_Clip(). |