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 U 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.
| Function | Syntax |
|---|---|
| Python | convert |
| SQL | RT |
| Scala | convert |
For more details, go to the GeoAnalytics Engine API reference for convert_pixel_type.
Examples
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()+--------------------+-------------+
| updated_raster|new_pixeltype|
+--------------------+-------------+
|SqlRaster(1x2x2, ...| Float32|
+--------------------+-------------+Version table
| Release | Notes |
|---|---|
2.0.0 | Python, SQL, and Scala functions introduced |