Skip to main content
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. RS_PixelAsPoints

Signatures

RS_PixelAsPoints(raster: Raster, band: Integer)

Parameters

raster
Raster
required
The input raster.
band
Integer
required
The band index.

Return type

A struct containing the result fields.

Examples

SELECT ST_AsText(RS_PixelAsPoints(raster, 1)) from rasters
[[POINT (-13065223 4021262.75),148.0,0,0], [POINT (-13065150 4021262.75),123.0,0,1], [POINT (-13065078 4021262.75),99.0,1,0], [POINT (-13065006 4021262.75),140.0,1,1]]
Spark SQL example for extracting Point, value, raster x and y coordinates:
val pointDf = sedona.read...
val rasterDf = sedona.read.format("binaryFile").load("/some/path/*.tiff")
var df = sedona.read.format("binaryFile").load("/some/path/*.tiff")
df = df.selectExpr("RS_FromGeoTiff(content) as raster")

df.selectExpr(
  "explode(RS_PixelAsPoints(raster, 1)) as exploded"
).selectExpr(
  "exploded.geom as geom",
  "exploded.value as value",
  "exploded.x as x",
  "exploded.y as y"
).show(3)
+--------------------------------------+-----+---+---+
|geom                                  |value|x  |y  |
+--------------------------------------+-----+---+---+
|POINT (-13095818 4021262.75)          |0.0  |1  |1  |
|POINT (-13095745.67138728 4021262.75) |0.0  |2  |1  |
|POINT (-13095673.342774557 4021262.75)|0.0  |3  |1  |
+--------------------------------------+-----+---+---+