RS_Clip¶
Introduction: Returns a raster that is clipped by the given geometry.
If crop is not specified then it will default to true, meaning it will make the resulting raster shrink to the geometry's extent and if noDataValue is not specified then the resulting raster will have the minimum possible value for the band pixel data type.
For polygon geometries, the allTouched parameter (Since v1.7.1) determines how pixels are selected:
- When true, pixel selection also includes cells entered by the polygon's boundary, following the RS_AsRaster rules.
- When false (default), pixels whose centroid intersects the polygon will be included.
A polygon never selects a pixel it touches only on the pixel's boundary, whichever edge that is. A polygon aligned with grid lines selects only pixels inside it.
Point geometries select the single pixel containing the point under the half-open rule, regardless of allTouched. A point or line lying on an internal grid edge selects the pixel after it in pixel order; one lying on the raster's last edge selects none. When allTouched is false, a line selects the pixels GDAL selects by default: each segment selects the pixels that contain its two ends and one pixel in every pixel column between them, or in every pixel row when the ends are more rows apart than columns. That is fewer pixels than the segment passes through, it can include a pixel the segment does not pass through, and a line and its reverse can select different pixels. When allTouched is true, a line selects the pixels GDAL selects with ALL_TOUCHED: every pixel a segment passes through, and a pixel it meets only at a single point when that point belongs to the pixel under the half-open rule. Both rules are described for RS_AsRaster. Whether a coordinate lies on a grid line is decided in decimal, as described for RS_AsRaster.
For LineString geometries, allTouched can also change the rasterization window at grid boundaries and therefore the selected pixels.
Note
- Since
v1.5.1, if the coordinate reference system (CRS) of the inputgeomgeometry differs from that of theraster, thengeomwill be transformed to match the CRS of theraster. If therasterorgeomdoesn't have a CRS then it will default to4326/WGS84. - Since
v1.7.0,RS_Clipfunction will returnnullif therasterandgeometrygeometry do not intersect. If you want to throw an exception in this case, you can set thelenientparameter tofalse.
Format:
RS_Clip(raster: Raster, band: Integer, geom: Geometry)
RS_Clip(raster: Raster, band: Integer, geom: Geometry, allTouched: Boolean)
RS_Clip(raster: Raster, band: Integer, geom: Geometry, allTouched: Boolean, noDataValue: Double)
RS_Clip(raster: Raster, band: Integer, geom: Geometry, allTouched: Boolean, noDataValue: Double, crop: Boolean)
RS_Clip(raster: Raster, band: Integer, geom: Geometry, allTouched: Boolean, noDataValue: Double, crop: Boolean, lenient: Boolean)
Return type: Raster
Since: v1.5.1
SQL Example
SELECT RS_Clip(
RS_FromGeoTiff(content), 1,
ST_GeomFromWKT('POLYGON ((236722 4204770, 243900 4204770, 243900 4197590, 221170 4197590, 236722 4204770))'),
false, 200, true
)
SQL Example
SELECT RS_Clip(
RS_FromGeoTiff(content), 1,
ST_GeomFromWKT('POLYGON ((236722 4204770, 243900 4204770, 243900 4197590, 221170 4197590, 236722 4204770))'),
false, 200, false
)