Skip to content

RT_ConvertPixelType takes a raster column and a string column which represents the pixel type value and returns a raster column. The function updates the input raster to utilize the specified pixel type, returning the modified raster column. Converting raster data from a larger pixel type like Float64 to a smaller pixel type such as UInt8 could lead to a loss of data due to the limitations in range and precision of the smaller type.

The supported pixel types are: uint1, uint2, uint4, uint8, uint16, uint32, int8, int16, int32, float32 and float64.

The short version of pixel type is also supported. For example, u1 can be used instead of uint1 or f32 instead of float32. Also, the pixel type representation is bit-based. For example, u1 is one bit and not one byte, which means that it uses one bit per pixel.

FunctionSyntax
Pythonconvert_pixel_type(raster_col, pixel_type)
SQLRT_ConvertPixelType(raster_col, pixel_type)
ScalaconvertPixelType(raster, pixelType)

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

Examples

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

from geoanalytics.raster import functions as RT

data = [([1,2,3,4], )]
df = spark.createDataFrame(data, ["pixels"]) \
     .withColumn("raster", RT.create_raster("pixels", 2, 2, "int32"))

df.select(RT.convert_pixel_type("raster", "float32").alias("updated_raster")) \
  .withColumn("new_pixeltype", RT.pixel_type("updated_raster")).show()
Result
Use dark colors for code blocksCopy
1
2
3
4
5
+--------------------+-------------+
|      updated_raster|new_pixeltype|
+--------------------+-------------+
|SqlRaster(1x2x2, ...|      Float32|
+--------------------+-------------+

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.