> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wherobots.com/llms.txt
> Use this file to discover all available pages before exploring further.

# RS_PixelAsCentroids

Returns a list of the centroid point geometry, the pixel value and its raster X and Y coordinates for each pixel in the raster at the specified band.
Each centroid represents the geometric center of the corresponding pixel's area.

<img src="https://mintcdn.com/wherobots/AayJA2u8CknIeTgt/images/sql-functions/RS_PixelAsCentroids/RS_PixelAsCentroids.svg?fit=max&auto=format&n=AayJA2u8CknIeTgt&q=85&s=c37f7eaafce795cecdeed1c0d2c625ad" alt="RS_PixelAsCentroids" width="700" height="380" data-path="images/sql-functions/RS_PixelAsCentroids/RS_PixelAsCentroids.svg" />

## Signatures

```sql theme={"system"}
RS_PixelAsCentroids(raster: Raster, band: Integer)
```

## Parameters

<ParamField body="raster" type="Raster" required>
  The input raster.
</ParamField>

<ParamField body="band" type="Integer" required>
  The band index.
</ParamField>

## Return type

<ResponseField type="Array<Struct<geom: Geometry, val: Double, x: Integer, y: Integer>>">
  A struct containing the result fields.
</ResponseField>

## Examples

```sql theme={"system"}
SELECT ST_AsText(RS_PixelAsCentroids(raster, 1)) from rasters
```

```
[[POINT (-13065222 4021263.75),148.0,0,0], [POINT (-13065151 4021263.75),123.0,0,1], [POINT (-13065077 4021263.75),99.0,1,0], [POINT (-13065007 4021261.75),140.0,1,1]]
```

Spark SQL example for extracting Point, value, raster x and y coordinates:

```scala theme={"system"}
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_PixelAsCentroids(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 (-13095781.835693639 4021226.5856936392)|0.0  |1  |1  |
|POINT (-13095709.507080918 4021226.5856936392)|0.0  |2  |1  |
|POINT (-13095637.178468198 4021226.5856936392)|0.0  |3  |1  |
+----------------------------------------------+-----+---+---+
```
