> ## 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_AsMatrix

Returns a string, that when printed, outputs the raster band as a pretty printed 2D matrix. All the values of the raster are cast to double for the string. RS\_AsMatrix allows specifying the number of digits to be considered after the decimal point.
RS\_AsMatrix expects a raster, and optionally a band (default: 1) and postDecimalPrecision (default: 6). The band parameter is 1-indexed.

<Note>
  If the provided band is not present in the raster, RS\_AsMatrix throws an IllegalArgumentException
</Note>

<Note>
  If the provided raster has integral values, postDecimalPrecision (if any) is simply ignored and integers are printed in the resultant string
</Note>

<Note>
  If you are using `show()` to display the output, it will show special characters as escape sequences. To get the expected behavior use the following code:

  **Scala**

  ```scala theme={"system"}
  println(df.selectExpr("RS_AsMatrix(rast)").sample(0.5).collect().mkString("\n"))
  ```

  **Java**

  ```java theme={"system"}
  System.out.println(String.join("\n", df.selectExpr("RS_AsMatrix(rast)").sample(0.5).collect()))
  ```

  **Python**

  ```python theme={"system"}
  print("\n".join(df.selectExpr("RS_AsMatrix(rast)").sample(0.5).collect()))
  ```

  The `sample()` function is only there to reduce the data sent to `collect()`, you may also use `filter()` if that's appropriate.
</Note>

## Signatures

```sql theme={"system"}
RS_AsMatrix(raster: Raster, band: Integer = 1, postDecimalPrecision: Integer = 6)
```

## Parameters

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

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

<ParamField body="postDecimalPrecision" type="Integer" required default="6">
  The post decimal precision value.
</ParamField>

## Return type

<ResponseField type="String">
  A string representation.
</ResponseField>

## Examples

```scala theme={"system"}
val inputDf = Seq(Seq(1, 3.333333, 4, 0.0001, 2.2222, 9, 10, 11.11111111, 3, 4, 5, 6)).toDF("band")
print(inputDf.selectExpr("RS_AsMatrix(RS_AddBandFromArray(RS_MakeEmptyRaster(1, 'd', 4, 3, 0, 0, 1, -1, 0, 0, 0), band, 1, 0))").sample(0.5).collect()(0))
```

```sql theme={"system"}
| 1.00000   3.33333   4.00000   0.00010|
| 2.22220   9.00000  10.00000  11.11111|
| 3.00000   4.00000   5.00000   6.00000|
```

```scala theme={"system"}
val inputDf = Seq(Seq(1, 3, 4, 0, 2, 9, 10, 11, 3, 4, 5, 6)).toDF("band")
print(inputDf.selectExpr("RS_AsMatrix(RS_AddBandFromArray(RS_MakeEmptyRaster(1, 'i', 4, 3, 0, 0, 1, -1, 0, 0, 0), band, 1, 0))").sample(0.5).collect()(0))
```

```sql theme={"system"}
| 1   3   4   0|
| 2   9  10  11|
| 3   4   5   6|
```
