跳转至
🎉 Apache Sedona 1.9.1 已正式发布!🗺️ 新增 Geography SQL 函数、Box2D 与 Box3D 类型、栅格 Python UDF 等。查看发布说明 →

RS_SetValues

Introduction: Returns a raster by replacing the values of pixels in a specified rectangular region. The top left corner of the region is defined by the colX and rowY coordinates. The width and height parameters specify the dimensions of the rectangular region. The new values to be assigned to the pixels in this region can be specified as an array passed to this function.

Note

Since v1.5.1, if the coordinate reference system (CRS) of the input geom geometry differs from that of the raster, then geom will be transformed to match the CRS of the raster. If the raster or geom doesn't have a CRS then it will default to 4326/WGS84.

Format without ROI geom:

RS_SetValues(raster: Raster, bandIndex: Integer, colX: Integer, rowY: Integer, width: Integer, height: Integer, newValues: ARRAY[Double])
RS_SetValues(raster: Raster, bandIndex: Integer, colX: Integer, rowY: Integer, width: Integer, height: Integer, newValues: ARRAY[Double], keepNoData: Boolean = false)

Return type: Raster

Since: v1.5.0

The colX, rowY, and bandIndex are 1-indexed. If keepNoData is true, the pixels with NoData value will not be set to the corresponding value in newValues. The newValues should be provided in rows.

The geometry variant of this function accepts all types of Geometries, and it sets the newValue in the specified region under the geom.

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

If the shape of newValues doesn't match with provided width and height, IllegalArgumentException is thrown.

Note

If the mentioned bandIndex doesn't exist, this will throw an IllegalArgumentException.

Format with ROI geom:

RS_SetValues(raster: Raster, bandIndex: Integer, geom: Geometry, newValue: Double)
RS_SetValues(raster: Raster, bandIndex: Integer, geom: Geometry, newValue: Double, allTouched: Boolean = false)
RS_SetValues(raster: Raster, bandIndex: Integer, geom: Geometry, newValue: Double, allTouched: Boolean = false, keepNoData: Boolean = false)

SQL Example

SELECT RS_BandAsArray(
        RS_SetValues(
            RS_AddBandFromArray(
                RS_MakeEmptyRaster(1, 5, 5, 0, 0, 1, -1, 0, 0, 0),
                Array(1,1,1,0,0,0,1,2,3,3,5,6,7,0,0,3,0,0,3,0,0,0,0,0,0), 1, 0d
                ),
            1, 2, 2, 3, 3, [11,12,13,14,15,16,17,18,19]
            )
        )

Output:

Array(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 11.0, 12.0, 13.0, 3.0, 5.0, 14.0, 15.0, 16.0, 0.0, 3.0, 17.0, 18.0, 19.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)

SQL Example

SELECT RS_BandAsArray(
        RS_SetValues(
            RS_AddBandFromArray(
                RS_MakeEmptyRaster(1, 5, 5, 1, -1, 1, -1, 0, 0, 0),
                Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), 1
                ),
            1, ST_GeomFromWKT('POLYGON((1 -1, 3 -3, 6 -6, 4 -1, 1 -1))'), 255, false, false
            )
           )

Output:

Array(255.0, 255.0, 255.0, 0.0, 0.0, 0.0, 255.0, 255.0, 255.0, 0.0, 0.0, 0.0, 255.0, 255.0, 0.0, 0.0, 0.0, 0.0, 255.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)