Image-based visualization
Sedona offers APIs to visualize a raster in an image form. This API only works for rasters with byte data, and bands ≤ 4 (Grayscale - RGBA). You can check the data type of an existing raster by using RS_BandPixelType or create your own raster by passing ‘B’ while using RS_MakeEmptyRaster.RS_AsBase64
Introduction: Returns a base64 encoded string of the given raster. If the datatype is integral then this function internally takes the first 4 bands as RGBA, and converts them to the PNG format, finally produces a base64 string. When the datatype is not integral, the function converts the raster to TIFF format, and then generates a base64 string. To visualize other bands, please use it together withRS_Band. You can take the resulting base64 string in an online viewer to check how the image looks like.
Format:
RS_AsBase64(raster: Raster, maxWidth: Integer)
RS_AsBase64(raster: Raster)
SQL Example
RS_AsImage
Introduction: Returns a HTML that when rendered using an HTML viewer or via a Jupyter Notebook, displays the raster as a square image of side lengthimageWidth. Optionally, an imageWidth parameter can be passed to RS_AsImage in order to increase the size of the rendered image (default: 200).
Format: RS_AsImage(raster: Raster, imageWidth: Integer = 200)
SQL example:

Text-based visualization
RS_AsMatrix
Introduction: Returns a string, that when printed, outputs the raster band as a pretty printed 2D matrix. All the values of the raster are cast to double for the string. RS_AsMatrix allows specifying the number of digits to be considered after the decimal point. RS_AsMatrix expects a raster, and optionally a band (default: 1) and postDecimalPrecision (default: 6). The band parameter is 1-indexed.If the provided band is not present in the raster, RS_AsMatrix throws an IllegalArgumentException
If the provided raster has integral values, postDecimalPrecision (if any) is simply ignored and integers are printed in the resultant string
If you are using
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.
Format:

