Skip to content

RT_FromBinary takes a binary column and returns a raster column. It supports reading binary data from the following formats: TIFF (.tif), JPEG (.jpg), and PNG (.png). The maximum acceptable size for the input byte array is 2.147 gigabytes. This function loads the data as value rasters. It will return null if the input binary is not a raster.

FunctionSyntax
Pythonfrom_binary(binary_col)
SQLRT_FromBinary(binary_col)
ScalafromBinary(binary)

For more details, go to the GeoAnalytics Engine API reference for from_binary.

Examples

PythonPythonSQLScala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10

from geoanalytics.raster import functions as RT

raster_binary = bytearray(b'II*\x00\x08\x00\x00\x00\x0b\x00\x00\x01\x03\x00\x01\x00\x00\x00\x02\x00\x00\x00\x01\x01\x03\x00\x01\x00\x00\x00\x02\x00\x00\x00\x02\x01\x03\x00\x01\x00\x00\x00 \x00\x00\x00\x03\x01\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x06\x01\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x11\x01\x04\x00\x01\x00\x00\x00\x92\x00\x00\x00\x15\x01\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x16\x01\x03\x00\x01\x00\x00\x00\x02\x00\x00\x00\x17\x01\x04\x00\x01\x00\x00\x00\x10\x00\x00\x00\x1c\x01\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00S\x01\x03\x00\x01\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80?\x00\x00\x00@\x00\x00@@\x00\x00\x80@')

df = spark.createDataFrame([(raster_binary,)], ["binary_content"])
df_from_binary = df.select(RT.from_binary("binary_content").alias("from_binary_raster"))

# Show pixel values of raster
df_from_binary.withColumn("pixel_values", RT.band_values("from_binary_raster", 1)).show(truncate=False)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
+-------------------------+--------------------+
|from_binary_raster       |pixel_values        |
+-------------------------+--------------------+
|SqlRaster(1x2x2, Float32)|[1.0, 2.0, 3.0, 4.0]|
+-------------------------+--------------------+

Version table

ReleaseNotes

2.0.0

Python, SQL, and Scala functions introduced

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.