Pixel Functions
RS_PixelAsCentroid
Introduction: Returns the centroid (point geometry) of the specified pixel’s area. The pixel coordinates specified are 1-indexed. IfcolX and rowY are out of bounds for the raster, they are interpolated assuming the same skew and translate values.
Format: RS_PixelAsCentroid(raster: Raster, colX: Integer, rowY: Integer)
SQL example:
RS_PixelAsCentroids
Introduction: Returns a list of the centroid point geometry, the pixel value and its raster X and Y coordinates for each pixel in the raster at the specified band. Each centroid represents the geometric center of the corresponding pixel’s area. Format:RS_PixelAsCentroids(raster: Raster, band: Integer)
SQL example:
RS_PixelAsPoint
Introduction: Returns a point geometry of the specified pixel’s upper-left corner. The pixel coordinates specified are 1-indexed.If the pixel coordinates specified do not exist in the raster (out of bounds), RS_PixelAsPoint throws an IndexOutOfBoundsException.
RS_PixelAsPoint(raster: Raster, colX: Integer, rowY: Integer)
SQL example:
RS_PixelAsPoints
Introduction: Returns a list of the pixel’s upper-left corner point geometry, the pixel value and its raster X and Y coordinates for each pixel in the raster at the specified band. Format:RS_PixelAsPoints(raster: Raster, band: Integer)
SQL example:
RS_PixelAsPolygon
Introduction: Returns a polygon geometry that bounds the specified pixel. The pixel coordinates specified are 1-indexed. IfcolX and rowY are out of bounds for the raster, they are interpolated assuming the same skew and translate values.
Format: RS_PixelAsPolygon(raster: Raster, colX: Integer, rowY: Integer)
SQL example:
RS_PixelAsPolygons
Introduction: Returns a list of the polygon geometry, the pixel value and its raster X and Y coordinates for each pixel in the raster at the specified band. Format:RS_PixelAsPolygons(raster: Raster, band: Integer)
SQL example:
Geometry Functions
RS_Envelope
Introduction: Returns the envelope of the raster as a Geometry. Format:RS_Envelope (raster: Raster)
SQL example:
RS_ConvexHull
Introduction: Return the convex hull geometry of the raster including the NoDataBandValue band pixels. For regular shaped and non-skewed rasters, this gives more or less the same result as RS_Envelope and hence is only useful for irregularly shaped or skewed rasters. Format:RS_ConvexHull(raster: Raster)
SQL example:
RS_MinConvexHull
Introduction: Returns the min convex hull geometry of the raster excluding the NoDataBandValue band pixels, in the given band. If no band is specified, all the bands are considered when creating the min convex hull of the raster. The created geometry representing the min convex hull has world coordinates of the raster in its CRS as the corner coordinates.If the specified band does not exist in the raster, RS_MinConvexHull throws an IllegalArgumentException
RS_MinConvexHull(raster: Raster)
RS_MinConvexHull(raster: Raster, band: Integer)
SQL example:
Raster Accessors
RS_BandPath
Introduction: Returns the path to the raster file referenced by the out-db raster. If the raster is an in-db raster, this function returns null. Format:RS_BandPath(raster: Raster)
SQL example:
RS_GeoReference
Introduction: Returns the georeference metadata of raster as a string in GDAL or ESRI format. Default is GDAL if not specified. For more information about ScaleX, ScaleY, SkewX, SkewY, please refer to the Affine Transformations section.If you are using The
show() to display the output, it will show special characters as escape sequences. To get the expected behavior use the following code:- Scala
- Java
- Python
sample() function is only there to reduce the data sent to collect(), you may also use filter() if that’s appropriate.RS_GeoReference(raster: Raster, format: String = "GDAL")
Difference between format representation is as follows:
GDAL
ESRI
RS_GeoTransform
Introduction: Returns a struct of parameters that represent the GeoTransformation of the raster. The struct has the following schema:- magnitudeI: size of a pixel along the transformed i axis
- magnitudeJ: size of a pixel along the transformed j axis
- thetaI: angle by which the raster is rotated (Radians positive clockwise)
- thetaIJ: angle from transformed i axis to transformed j axis (Radians positive counter-clockwise)
- offsetX: X ordinate of the upper-left corner of the upper-left pixel
- offsetY: Y ordinate of the upper-left corner of the upper-left pixel
Refer to this image for a clear understanding between i & j axis and x & y axis.
RS_GeoTransform(raster: Raster)
SQL example:
RS_Height
Introduction: Returns the height of the raster. Format:RS_Height(raster: Raster)
SQL example:
RS_RasterToWorldCoordX
Introduction: Returns the upper left X coordinate of the given row and column of the given raster geometric units of the geo-referenced raster. If any out of bounds values are given, the X coordinate of the assumed point considering existing raster pixel size and skew values will be returned. Format:RS_RasterToWorldCoordX(raster: Raster, colX: Integer, rowY: Integer)
SQL example:
RS_RasterToWorldCoordY
Introduction: Returns the upper left Y coordinate of the given row and column of the given raster geometric units of the geo-referenced raster. If any out of bounds values are given, the Y coordinate of the assumed point considering existing raster pixel size and skew values will be returned. Format:RS_RasterToWorldCoordY(raster: Raster, colX: Integer, rowY: Integer)
SQL example:
RS_RasterToWorldCoord
Introduction: Returns the upper left X and Y coordinates of the given row and column of the given raster geometric units of the geo-referenced raster as a Point geometry. If any out of bounds values are given, the X and Y coordinates of the assumed point considering existing raster pixel size and skew values will be returned. Format:RS_RasterToWorldCoord(raster: Raster, colX: Integer, rowY: Integer)
SQL example:
RS_Rotation
Introduction: Returns the uniform rotation of the raster in radian. Format:RS_Rotation(raster: Raster)
SQL example:
RS_ScaleX
Introduction: Returns the pixel width of the raster in CRS units.RS_ScaleX attempts to get an Affine transform on the grid in order to return scaleX (See World File for more details). If the transform on the geometry is not an Affine transform, RS_ScaleX will throw an UnsupportedException:
RS_ScaleX(raster: Raster)
SQL example:
RS_ScaleY
Introduction: Returns the pixel height of the raster in CRS units.RS_ScaleY attempts to get an Affine transform on the grid in order to return scaleX (See World File for more details). If the transform on the geometry is not an Affine transform, RS_ScaleY will throw an UnsupportedException:
RS_ScaleY(raster: Raster)
SQL example:
RS_SkewX
Introduction: Returns the X skew or rotation parameter. Format:RS_SkewX(raster: Raster)
SQL example:
RS_SkewY
Introduction: Returns the Y skew or rotation parameter. Format:RS_SkewY(raster: Raster)
SQL example:
RS_UpperLeftX
Introduction: Returns the X coordinate of the upper-left corner of the raster. Format:RS_UpperLeftX(raster: Raster)
SQL example:
RS_UpperLeftY
Introduction: Returns the Y coordinate of the upper-left corner of the raster. Format:RS_UpperLeftY(raster: Raster)
SQL example:
RS_Width
Introduction: Returns the width of the raster. Format:RS_Width(raster: Raster)
SQL example:
RS_WorldToRasterCoord
Introduction: Returns the grid coordinate of the given world coordinates as a Point. Format:RS_WorldToRasterCoord(raster: Raster, point: Geometry)
RS_WorldToRasterCoord(raster: Raster, x: Double, y: Point)
SQL example:
If the given geometry point is not in the same CRS as the given raster, the given geometry will be transformed to the given raster’s CRS. You can use ST_Transform to transform the geometry beforehand.
RS_WorldToRasterCoordX
Introduction: Returns the X coordinate of the grid coordinate of the given world coordinates as an integer. Format:RS_WorldToRasterCoord(raster: Raster, point: Geometry)
RS_WorldToRasterCoord(raster: Raster, x: Double, y: Double)
SQL example:
RS_WorldToRasterCoordY
Introduction: Returns the Y coordinate of the grid coordinate of the given world coordinates as an integer. Format:RS_WorldToRasterCoordY(raster: Raster, point: Geometry)
RS_WorldToRasterCoordY(raster: Raster, x: Double, y: Double)
SQL example:
Raster Band Accessors
RS_Band
Introduction: Returns a new raster consisting 1 or more bands of an existing raster. It can build new rasters from existing ones, export only selected bands from a multiband raster, or rearrange the order of bands in a raster dataset. Format:RS_Band(raster: Raster, bands: ARRAY[Integer])
SQL example:
RS_BandNoDataValue
Introduction: Returns the no data value of the given band of the given raster. If no band is given, band 1 is assumed. The band parameter is 1-indexed. If there is no data value associated with the given band, RS_BandNoDataValue returns null.If the given band does not lie in the raster, RS_BandNoDataValue throws an IllegalArgumentException
RS_BandNoDataValue (raster: Raster, band: Integer = 1)
SQL example:
RS_BandIsNoData
Returns true if the band is filled with only nodata values. Band 1 is assumed if not specified. Format:RS_BandIsNoData(raster: Raster, band: Integer = 1)
SQL example:
RS_BandPixelType
Introduction: Returns the datatype of each pixel in the given band of the given raster in string format. The band parameter is 1-indexed. If no band is specified, band 1 is assumed.If the given band index does not exist in the given raster, RS_BandPixelType throws an IllegalArgumentException.
REAL_64BITS- For Double valuesREAL_32BITS- For Float valuesSIGNED_32BITS- For Integer valuesSIGNED_16BITS- For Short valuesUNSIGNED_16BITS- For unsigned Short valuesUNSIGNED_8BITS- For Byte values
RS_BandPixelType(rast: Raster, band: Integer = 1)
SQL example:
RS_Count
Introduction: Returns the number of pixels in a given band. If band is not specified then it defaults to1.
If excludeNoDataValue is set
true then it will only count pixels with value not equal to the nodata value of the raster.
Set excludeNoDataValue to false to get count of all pixels in raster.If the mentioned band index doesn’t exist, this will throw an
IllegalArgumentException.RS_Count(raster: Raster, band: Integer = 1, excludeNoDataValue: Boolean = true)
RS_Count(raster: Raster, band: Integer = 1)
RS_Count(raster: Raster)
SQL example:
RS_SummaryStats
Introduction: Returns summary statistic for a particular band based on thestatType parameter. The function defaults to band index of 1 when band is not specified and excludes noDataValue if excludeNoDataValue is not specified.
statType parameter takes the following strings:
count: Total count of all pixels in the specified bandsum: Sum of all pixel values in the specified bandmean: Mean value of all pixel values in the specified bandstddev: Standard deviation of all pixels in the specified bandmin: Minimum pixel value in the specified bandmax: Maximum pixel value in the specified band
If excludeNoDataValue is set
true then it will only count pixels with value not equal to the nodata value of the raster.
Set excludeNoDataValue to false to get count of all pixels in raster.RS_SummaryStats(raster: Raster, statType: String, band: Integer = 1, excludeNoDataValue: Boolean = true)
RS_SummaryStats(raster: Raster, statType: String, band: Integer = 1)
RS_SummaryStats(raster: Raster, statType: String)
SQL Example
RS_SummaryStatsAll
Introduction: Returns summary stats struct consisting of count, sum, mean, stddev, min, max for a given band in raster. If band is not specified then it defaults to1.
If excludeNoDataValue is set
true then it will only count pixels with value not equal to the nodata value of the raster.
Set excludeNoDataValue to false to get count of all pixels in raster.If the mentioned band index doesn’t exist, this will throw an
IllegalArgumentException.RS_SummaryStatsAll(raster: Raster, band: Integer = 1, excludeNoDataValue: Boolean = true)
RS_SummaryStatsAll(raster: Raster, band: Integer = 1)
RS_SummaryStatsAll(raster: Raster)
SQL Example
RS_ZonalStats
Introduction: This returns a statistic value specified bystatType over the region of interest defined by zone. It computes the statistic from the pixel values within the ROI geometry and returns the result. If the excludeNoData parameter is not specified, it will default to true. This excludes NoData values from the statistic calculation. Additionally, if the band parameter is not provided, band 1 will be used by default for the statistic computation. The valid options for statType are:
The allTouched parameter determines how pixels are selected:
- When true, any pixel touched by the geometry will be included.
- When false (default), only pixels whose centroid intersects with the geometry will be included.
-
count: Number of pixels in the region. -
sum: Sum of pixel values. -
mean|average|avg: Arithmetic mean. -
median: Middle value in the region. -
mode: Most occurring value, if there are multiple values with same occurrence then will return the largest number. -
stddev|sd: Standard deviation. -
variance: Variance. -
min: Minimum value in the region. -
max: Maximum value in the region.
If the coordinate reference system (CRS) of the input
zone geometry differs from that of the raster, then zone will be transformed to match the CRS of the raster before computation.The following conditions will throw an IllegalArgumentException if they are not met:- The provided
rasterandzonegeometry should intersect whenlenientparameter is set tofalse. - The option provided to
statTypeshould be valid.
lenient parameter is set to true by default. The function will return null if the raster and zone geometry do not intersect.RS_ZonalStatsAll
Introduction: Returns a struct of statistic values, where each statistic is computed over a region defined by thezone geometry. The struct has the following schema:
The allTouched parameter determines how pixels are selected:
- When true, any pixel touched by the geometry will be included.
- When false (default), only pixels whose centroid intersects with the geometry will be included.
- count: Count of the pixels.
- sum: Sum of the pixel values.
- mean: Arithmetic mean.
- median: Median.
- mode: Mode.
- stddev: Standard deviation.
- variance: Variance.
- min: Minimum value of the zone.
- max: Maximum value of the zone.
If the coordinate reference system (CRS) of the input
zone geometry differs from that of the raster, then zone will be transformed to match the CRS of the raster before computation.The following conditions will throw an IllegalArgumentException if they are not met:- The provided
rasterandzonegeometry should intersect whenlenientparameter is set tofalse. - The option provided to
statTypeshould be valid.
lenient parameter is set to true by default. The function will return null if the raster and zone geometry do not intersect.Raster Predicates
RS_Contains
Introduction: Returns true if the geometry or raster on the left side contains the geometry or raster on the right side. The convex hull of the raster is considered in the test. The rules for testing spatial relationship is the same asRS_Intersects.
Format:
RS_Contains(raster: Raster, geom: Geometry)
RS_Contains(geom: Geometry, raster: Raster)
RS_Contains(raster0: Raster, raster1: Raster)
SQL example:
RS_Intersects
Introduction: Returns true if raster or geometry on the left side intersects with the raster or geometry on the right side. The convex hull of the raster is considered in the test. Rules for testing spatial relationship:- If the raster or geometry does not have a defined SRID, it is assumed to be in WGS84.
- If both sides are in the same CRS, then perform the relationship test directly.
- Otherwise, both sides will be transformed to WGS84 before the relationship test.
RS_Intersects(raster: Raster, geom: Geometry)
RS_Intersects(geom: Geometry, raster: Raster)
RS_Intersects(raster0: Raster, raster1: Raster)
SQL example:
RS_Within
Introduction: Returns true if the geometry or raster on the left side is within the geometry or raster on the right side. The convex hull of the raster is considered in the test. The rules for testing spatial relationship is the same asRS_Intersects.
Format: RS_Within(raster: Raster, geom: Geometry)
Format: RS_Within(geom: Geometry, raster: Raster)
Format: RS_Within(raster0: Raster, raster1: Raster)
SQL example:
Raster Based Operators
RS_AddBand
Introduction: Adds a new band to a rastertoRaster at a specified index toRasterIndex. The new band’s values are copied from fromRaster at a specified band index fromBand.
If no toRasterIndex is provided, the new band is appended to the end of toRaster. If no fromBand is specified, band 1 from fromRaster is copied by default.
IllegalArgumentException will be thrown in these cases:
- The provided Rasters,
toRaster&fromRasterdon’t have same shape. - The provided
fromBandis not infromRaster. - The provided
toRasterIndexis not in or at end oftoRaster.
RS_Clip
Introduction: Returns a raster that is clipped by the given geometry. Ifcrop 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.
The allTouched parameter determines how pixels are selected:
- When true, any pixel touched by the geometry will be included.
- When false (default), only pixels whose centroid intersects with the geometry will be included.
- If the coordinate reference system (CRS) of the input
geomgeometry 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. RS_Clipfunction will returnnullif therasterandgeometrygeometry do not intersect. If you want to throw an exception in this case, you can set thelenientparameter tofalse.
- The
rasteris an out-db raster with no skew - The geometry is a rectangle and is in the same CRS with the raster
noDataValueandcropare not specified
RS_Clip will be an out-db raster in this mode. Otherwise, the result will be an in-db raster. This mode
enables cropping out-db rasters using simple windows without reading and processing any pixel data of the out-db raster.
If you always want to get an in-db raster, you can use the RS_AsInDb function to convert the result to an in-db raster.
Format:



RS_Interpolate
Introduction: This function performs interpolation on a raster using the Inverse Distance Weighted (IDW) method. This method estimates cell values by averaging the values of sample data points in the vicinity of each processing cell. The influence of a sample point on the interpolated value is inversely proportional to the distance from the cell being estimated, with nearer points having more influence or weight in the averaging process. This technique is effective in scenarios where continuity of spatial data is important, and it is essential to estimate values for locations that do not have direct measurements, often represented by NaN or noDataValue in raster data.This method assumes that the spatial influence of a variable diminishes with distance. In geospatial analysis, this means features or phenomena closer to a point of interest are given more weight than those further away. For example, in environmental data analysis, measurements from nearby locations have a greater impact on interpolated values than distant ones, reflecting the natural gradation and spatial continuity.
raster: The raster to be interpolated.band: The band of the raster to be used for interpolation. Ifbandis not provided, interpolation is performed across all bands.power: A positive real number defining the exponent of distance in the IDW calculation. This parameter controls the influence of distant points on the interpolated values, default being set to 2.mode: Specifies the interpolation mode - either"Variable"or"Fixed".- In
"Variable"mode:numPointsOrRadius: Specifies the number of nearest input points to be used for interpolation. Defaults to 12 if not provided.maxRadiusOrMinPoints: Sets the maximum search radius, with the default being the diagonal length of the raster.
- In
"Fixed"mode:numPointsOrRadius: Defines the radius within which input sample points are considered. Defaults to the diagonal length of the raster if not specified.maxRadiusOrMinPoints: Represents the minimum number of points required within the radius. Defaults to 0 if not provided.
- In


RS_MetaData
Introduction: Returns the metadata of the raster as a struct. The struct has the following schema:- upperLeftX: upper left x coordinate of the raster, in terms of CRS units
- upperLeftX: upper left y coordinate of the raster, in terms of CRS units
- gridWidth: width of the raster, in terms of pixels
- gridHeight: height of the raster, in terms of pixels
- scaleX: ScaleX: the scaling factor in the x direction
- scaleY: ScaleY: the scaling factor in the y direction
- skewX: skew in x direction (rotation x)
- skewY: skew in y direction (rotation y)
- srid: srid of the raster
- numSampleDimensions: number of bands
- tileWidth: width of tiles in the raster
- tileHeight: height of tiles in the raster
tileWidth and tileHeight are the dimensions of the tiles in the raster. For example,
rasters written by RS_FromGeoTiff uses the tiling scheme of the loaded GeoTIFF file. For rasters that has only 1 tile,
tileWidth and tileHeight will be equal to gridWidth and gridHeight respectively.
Format: RS_MetaData (raster: Raster)
SQL example:
RS_NormalizeAll
Introduction: Normalizes values in all bands of a raster between a given normalization range. The function maintains the data type of the raster values by ensuring that the normalized values are cast back to the original data type of each band in the raster. By default, the values are normalized to range [0, 255]. RS_NormalizeAll can take upto 7 of the following arguments.raster: The raster to be normalized.minLimandmaxLim(Optional): The lower and upper limits of the normalization range. By default, normalization range is set to [0, 255].normalizeAcrossBands(Optional): A boolean flag to determine the normalization method. If set to true (default), normalization is performed across all bands based on global min and max values. If false, each band is normalized individually based on its own min and max values.noDataValue(Optional): Defines the value to be used for missing or invalid data in raster bands. By default, noDataValue is set tomaxLimand Safety mode is triggered.minValueandmaxValue(Optional): Optionally, specific minimum and maximum values of the input raster can be provided. If not provided, these values are computed from the raster data.
noDataValue is not given. This sets noDataValue to maxLim and normalizes valid data values to the range [minLim, maxLim-1]. This is to avoid replacing valid data that might coincide with the new noDataValue.
Formats:
RS_NumBands
Introduction: Returns the number of the bands in the raster. Format:RS_NumBands (raster: Raster)
SQL example:
RS_ReprojectMatch
Introduction: Reproject a raster to match the geo-reference, CRS, and envelope of a reference raster. The output raster always have the same extent and resolution as the reference raster. For pixels not covered by the input raster, nodata value is assigned, or 0 is assigned if the input raster does not have nodata value. The default resampling algorithm isNearestNeighbor. The following resampling algorithms are supported (case-insensitive):
- NearestNeighbor
- Bilinear
- Bicubic
RasterArray.reproject_match function in rioxarray.
Format:
RS_ReprojectMatch (raster: Raster, reference: Raster, algorithm: String)
SQL Example

RS_Resample
Introduction: Resamples a raster using a given resampling algorithm and new dimensions (width and height), a new grid corner to pivot the raster at (gridX and gridY) and a set of georeferencing attributes (scaleX and scaleY). RS_Resample also provides an option to pass a reference raster to draw the georeferencing attributes out of. However, the SRIDs of the input and reference raster must be same, otherwise RS_Resample throws an IllegalArgumentException. For the purpose of resampling, width-height pair and scaleX-scaleY pair are mutually exclusive, meaning any one of them can be used at a time. TheuseScale parameter controls whether to use width-height or scaleX-scaleY. If useScale is false, the provided widthOrScale and heightOrScale values will be floored to integers and considered as width and height respectively (floating point width and height are not allowed). Otherwise, they are considered as scaleX and scaleY respectively.
Currently, RS_Resample does not support skewed rasters, and hence even if a skewed reference raster is provided, its skew values are ignored. If the input raster is skewed, the output raster geometry and interpolation may be incorrect.
The default algorithm used for resampling is NearestNeighbor, and hence if a null, empty or invalid value of algorithm is provided, RS_Resample defaults to using NearestNeighbor. However, the algorithm parameter is non-optional.
Following are valid values for the algorithm parameter (Case-insensitive):
- NearestNeighbor
- Bilinear
- Bicubic
RS_SetBandNoDataValue
Introduction: This sets the no data value for a specified band in the raster. If the band index is not provided, band 1 is assumed by default. Passing anull value for noDataValue will remove the no data value and that will ensure all pixels are included in functions rather than excluded as no data.
This function supports the ability to replace the current no-data value with the new noDataValue.
When
replace is true, any pixels matching the provided noDataValue will be considered as no-data in the output raster.An IllegalArgumentException will be thrown if the input raster does not already have a no-data value defined. Replacing existing values with noDataValue requires a defined no-data baseline to evaluate against.To use this for no-data replacement, the input raster must first set its no-data value, which can then be selectively replaced via this function.RS_SetGeoReference
Introduction: Sets the Georeference information of an object in a single call. Accepts inputs inGDAL and ESRI format.
Default format is GDAL. If all 6 parameters are not provided then will return null.
For more information about ScaleX, ScaleY, SkewX, SkewY, please refer to the Affine Transformations section.
Format:
GDAL
ESRI
RS_SetPixelType
Introduction: Returns a modified raster with the desired pixel data type. ThedataType parameter accepts one of the following strings.
- “D” - 64 bits Double
- “F” - 32 bits Float
- “I” - 32 bits signed Integer
- “S” - 16 bits signed Short
- “US” - 16 bits unsigned Short
- “B” - 8 bits unsigned Byte
If the specified
dataType is narrower than the original data type, the function will truncate the pixel values to fit the new data type range.RS_SetValue
Introduction: Returns a raster by replacing the value of pixel specified bycolX and rowY.
Format:
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 thecolX 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.
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.geom:
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.
The allTouched parameter determines how pixels are selected:
- When true, any pixel touched by the geometry will be included.
- When false (default), only pixels whose centroid intersects with the geometry will be included.
If the shape of
newValues doesn’t match with provided width and height, IllegalArgumentException is thrown.If the mentioned
bandIndex doesn’t exist, this will throw an IllegalArgumentException.geom:
RS_SetSRID
Introduction: Sets the spatial reference system identifier (SRID) of the raster geometry. Format:RS_SetSRID (raster: Raster, srid: Integer)
SQL example:
RS_SRID
Introduction: Returns the spatial reference system identifier (SRID) of the raster geometry. Format:RS_SRID (raster: Raster)
SQL example:
RS_StackTileExplode
Introduction: Stack a given array of rasters into a single raster. The rasters are stacked in the order they are provided in the array. The function also explode the stacked raster into multiple tiles. This function handles rasters that are not aligned and having different resolutions, data types and coordinate reference systems:- The CRS and resolution of the output raster will be the same as the selected reference raster.
- The data type of the output raster will be the most precise data type among all stacked bands.
rastersis an array of rasters to be stacked.refRasterIndexis the zero-based index of the reference raster in the array of rasters. The CRS and resolution of the output raster will be the same as the reference raster. IfrefRasterIndexis -1, the last raster in the array will be used as the reference raster.tileWidthandtileHeightare the dimensions of the tiles in the output raster.padWithNoDatais a boolean flag to determine whether to pad the output raster with no data values. IfpadWithNoDatais true, the output raster will be padded withnoDataValue.
RS_Union
Introduction: Returns a combined multi-band raster from 2 or more input Rasters. The order of bands in the resultant raster will be in the order of the input rasters. For example ifRS_Union is called on two 2-banded raster, raster1 and raster2, the first 2 bands of the resultant 4-banded raster will be from raster1 and the last 2 from raster 2.
If the provided input Rasters don’t have same shape an IllegalArgumentException will be thrown.
RS_Value
Introduction: Returns the value at the given point in the raster. If no band number is specified it defaults to 1.If the coordinate reference system (CRS) of the input
point geometry differs from that of the raster, then point will be transformed to match the CRS of the raster. If the raster or point doesn’t have a CRS then it will default to 4326/WGS84.RS_Value (raster: Raster, point: Geometry)
RS_Value (raster: Raster, point: Geometry, band: Integer)
RS_Value (raster: Raster, colX: Integer, colY: Integer, band: Integer)
SQL examples:
- For Point Geometry:
- For Grid Coordinates:
RS_Values
Introduction: Returns the values at the given points or grid coordinates in the raster. If no band number is specified it defaults to 1. RS_Values is similar to RS_Value but operates on an array of points or grid coordinates. RS_Values can be significantly faster since a raster only has to be loaded once for several points.If the coordinate reference system (CRS) of the input
points geometries differs from that of the raster, then points will be transformed to match the CRS of the raster. If the raster or points doesn’t have a CRS then it will default to 4326/WGS84.RS_Values (raster: Raster, points: ARRAY[Geometry])
RS_Values (raster: Raster, points: ARRAY[Geometry], band: Integer)
- For Array of Point geometries:
- For Arrays of grid coordinates:
RS_AsInDb
Introduction: convert an out-db raster to an in-db raster. If the input raster is already an in-db raster, the input raster will be returned as-is. Format:RS_AsInDb(raster: Raster)
SQL Example:
RS_FromGeoTiff for loading GeoTiff files as in-db rasters.
Raster Tiles
RS_Tile
Introduction: Returns an array of rasters resulting from the split of the input raster based upon the desired dimensions of the output rasters. Format:RS_Tile(raster: Raster, width: Int, height: Int, padWithNoData: Boolean = false, noDataVal: Double = null)
Format: RS_Tile(raster: Raster, bandIndices: Array[Int], width: Int, height: Int, padWithNoData: Boolean = false, noDataVal: Double = null)
width and height specifies the size of generated tiles. If bandIndices is NULL or not specified, all bands will be included in the output tiles,
otherwise bands specified by bandIndices will be included. Band indices are 1-based.
If padWithNoData = false, edge tiles on the right and bottom sides of the raster may have different dimensions than the rest of
the tiles. If padWithNoData = true, all tiles will have the same dimensions with the possibility that edge tiles being padded with
NODATA values. If raster band(s) do not have NODATA value(s) specified, one can be specified by setting noDataVal.
If the input raster is an out-db raster, the output tiles will also be out-db rasters.
noDataVal only works for in-db rasters.EXPLODE function to expand the array of tiles into a table of tiles.
RS_TileExplode
Introduction: Generates records containing raster tiles resulting from the split of the input raster based upon the desired dimensions of the output rasters. Format:RS_TileExplode(raster: Raster, width: Int, height: Int, padWithNoData: Boolean = false, noDataVal: Double = null)
Format: RS_TileExplode(raster: Raster, bandIndex: Int, width: Int, height: Int, padWithNoData: Boolean = false, noDataVal: Double = null)
Format: RS_TileExplode(raster: Raster, bandIndices: Array[Int], width: Int, height: Int, padWithNoData: Boolean = false, noDataVal: Double = null)
width and height specifies the size of generated tiles. If bandIndices is NULL or not specified, all bands will be included in the output tiles,
otherwise bands specified by bandIndices will be included. bandIndex can be specified if there is only one selected band, which is equivalent to
specifying bandIndices as ARRAY(bandIndex).Band indices are 1-based.
If padWithNoData = false, edge tiles on the right and bottom sides of the raster may have different dimensions than the rest of
the tiles. If padWithNoData = true, all tiles will have the same dimensions with the possibility that edge tiles being padded with
NODATA values. If raster band(s) do not have NODATA value(s) specified, one can be specified by setting noDataVal.
The returned records have the following schema:
x: The index of the tile along X axis (0-based).y: The index of the tile along Y axis (0-based).tile: The tile.
If the input raster is an out-db raster, the output tiles will also be out-db rasters.
noDataVal only works for in-db rasters.Raster to Map Algebra Operators
To bridge the gap between the raster and map algebra worlds, the following operators are provided. These operators convert a raster to a map algebra object. The map algebra object can then be used with the map algebra operators described in the next section.RS_BandAsArray
Introduction: Extract a band from a raster as an array of doubles. Format:RS_BandAsArray (raster: Raster, bandIndex: Integer).
BandIndex is 1-based and must be between 1 and RS_NumBands(raster). It returns null if the bandIndex is out of range or the raster is null.
SQL example:
RS_AddBandFromArray
Introduction: Add a band to a raster from an array of doubles. Format:RS_AddBandFromArray (raster: Raster, band: ARRAY[Double])
RS_AddBandFromArray (raster: Raster, band: ARRAY[Double], bandIndex: Integer)
RS_AddBandFromArray (raster: Raster, band: ARRAY[Double], bandIndex: Integer, noDataValue: Double)
The bandIndex is 1-based and must be between 1 and RS_NumBands(raster) + 1. It throws an exception if the bandIndex is out of range or the raster is null. If not specified, the noDataValue of the band is assumed to be null.
When the bandIndex is RS_NumBands(raster) + 1, it appends the band to the end of the raster. Otherwise, it replaces the existing band at the bandIndex.
If the bandIndex and noDataValue is not given, a convenience implementation adds a new band with a null noDataValue.
Adding a new band with a custom noDataValue requires bandIndex = RS_NumBands(raster) + 1 and non-null noDataValue to be explicitly specified.
Modifying or Adding a customNoDataValue is also possible by giving an existing band in RS_AddBandFromArray
In order to remove an existing noDataValue from an existing band, pass null as the noDataValue in the RS_AddBandFromArray.
Note that: bandIndex == RS_NumBands(raster) + 1 is an experimental feature and might lead to the loss of raster metadata and properties such as color models.
RS_AddBandFromArray typecasts the double band values to the given datatype of the raster. This can lead to overflow values if values beyond the range of the raster’s datatype are provided.
RS_MapAlgebra
Introduction: Apply a map algebra script on a raster. Format:RS_MapAlgebra runs a script on a raster. The script is written in a map algebra language called Jiffle. The script takes a raster
as input and returns a raster of the same size as output. The script can be used to apply a map algebra expression on a raster. The input raster is named rast in the Jiffle script, and the output raster is named out.
SQL example:
Calculate the NDVI of a raster with 4 bands (R, G, B, NIR):
RS_MapAlgebra:
RS_MapAlgebra, please refer to the Map Algebra documentation.
To learn how to write map algebra script, please refer to Jiffle language summary.
Map Algebra Operators
Map algebra operators work on a single band of a raster. Each band is represented as an array of doubles. The operators return an array of doubles.RS_Add
Introduction: Add two spectral bands in a Geotiff image Format:RS_Add (Band1: ARRAY[Double], Band2: ARRAY[Double])
SQL example:
RS_Array
Introduction: Create an array that is filled by the given value Format:RS_Array(length: Integer, value: Double)
SQL example:
RS_BitwiseAND
Introduction: Find Bitwise AND between two bands of Geotiff image Format:RS_BitwiseAND (Band1: ARRAY[Double], Band2: ARRAY[Double])
SQL example:
RS_BitwiseOR
Introduction: Find Bitwise OR between two bands of Geotiff image Format:RS_BitwiseOR (Band1: ARRAY[Double], Band2: ARRAY[Double])
SQL example:
RS_CountValue
Introduction: Returns count of a particular value from a spectral band in a raster image Format:RS_CountValue (Band1: ARRAY[Double], Target: Double)
SQL example:
RS_Divide
Introduction: Divide band1 with band2 from a geotiff image Format:RS_Divide (Band1: ARRAY[Double], Band2: ARRAY[Double])
SQL example:
RS_FetchRegion
Introduction: Fetch a subset of region from given Geotiff image based on minimumX, minimumY, maximumX and maximumY index as well original height and width of image Format:RS_GreaterThan
Introduction: Mask all the values with 1 which are greater than a particular target value Format:RS_GreaterThan (Band: ARRAY[Double], Target: Double)
SQL example:
RS_GreaterThanEqual
Introduction: Mask all the values with 1 which are greater than equal to a particular target value Format:RS_GreaterThanEqual (Band: ARRAY[Double], Target: Double)
SQL example:
RS_LessThan
Introduction: Mask all the values with 1 which are less than a particular target value Format:RS_LessThan (Band: ARRAY[Double], Target: Double)
SQL example:
RS_LessThanEqual
Introduction: Mask all the values with 1 which are less than equal to a particular target value Format:RS_LessThanEqual (Band: ARRAY[Double], Target: Double)
SQL example:
RS_LogicalDifference
Introduction: Return value from band 1 if a value in band1 and band2 are different, else return 0 Format:RS_LogicalDifference (Band1: ARRAY[Double], Band2: ARRAY[Double])
SQL example:
RS_LogicalOver
Introduction: Return value from band1 if it’s not equal to 0, else return band2 value Format:RS_LogicalOver (Band1: ARRAY[Double], Band2: ARRAY[Double])
SQL example:
RS_Mean
Introduction: Returns Mean value for a spectral band in a Geotiff image Format:RS_Mean (Band: ARRAY[Double])
SQL example:
RS_Mode
Introduction: Returns Mode from a spectral band in a Geotiff image in form of an array Format:RS_Mode (Band: ARRAY[Double])
SQL example:
RS_Modulo
Introduction: Find modulo of pixels with respect to a particular value Format:RS_Modulo (Band: ARRAY[Double], Target: Double)
SQL example:
RS_Multiply
Introduction: Multiply two spectral bands in a Geotiff image Format:RS_Multiply (Band1: ARRAY[Double], Band2: ARRAY[Double])
SQL example:
RS_MultiplyFactor
Introduction: Multiply a factor to a spectral band in a geotiff image Format:RS_MultiplyFactor (Band1: ARRAY[Double], Factor: Double)
SQL example:
v1.5.0.
RS_Normalize
Introduction: Normalize the value in the array to [0, 255]. Uniform arrays are set to 0 after normalization. Format:RS_Normalize (Band: ARRAY[Double])
SQL example:
RS_NormalizedDifference
Introduction: Returns Normalized Difference between two bands(band2 and band1) in a Geotiff image(example: NDVI, NDBI) Format:RS_NormalizedDifference (Band1: ARRAY[Double], Band2: ARRAY[Double])
SQL example:
RS_SquareRoot
Introduction: Find Square root of band values in a geotiff image Format:RS_SquareRoot (Band: ARRAY[Double])
SQL example:
RS_Subtract
Introduction: Subtract two spectral bands in a Geotiff image(band2 - band1) Format:RS_Subtract (Band1: ARRAY[Double], Band2: ARRAY[Double])
SQL example:

