> For the complete documentation index, see [llms.txt](https://docs.carto.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.carto.com/carto-user-manual/workflows/components/raster-operations.md).

# Raster Operations

Components to work with raster data sources

## Get Values from Raster

**Description**

This component allows obtaining values from a raster table. The values included in the output can be determined by a vector data source input.

**Inputs**

* `Raster table [Table]`: raster data source that will be used as source for the values.
* `Vector table [Table]`: vector data source that will be used to determine which pixel values are going to be obtained
* `Geo column`: Column in the Vector table that contains a geography to determine which pixel values are going to be obtained.
* `Raster properties` : List of band values that are going to be obtained from the raster, in the areas where it intersects with the vector table features.
* `Custom expression`: (optional) Add a custom SQL expression containing an operation that uses values from the different bands in the raster, for example `band_1+band_2 as sum`

**Advanced options**

* `Include pixel [boolean]`: Default `false`. If true, the output table will include a `pixel` column containing the quadbin id of the corresponding pixel in the raster.

**Outputs**

* `Result table [Table]`: A table that contains a row for each pixel in the raster source that intersects with the vector source. It will contains an optional `pixel` column and a column for each selected property, plus any additional column generated by a custom expression.

## Intersect and Aggregate Raster

**Description**

This component intersects a raster table with a table containing polygons and aggregates the values extracted from the intersection areas.

**Inputs**

* `Raster table [Table]`: raster data source that will be used as source for the aggregated values.
* `Vector table [Table]`: vector data source that contains the geographies to be enriched with aggragated data from the raster pixel values.
* `Geo column`: Geography column in the Vector table that will be intersected with the raster.
* `Raster aggregated properties` : List of aggregated band values that are going to be obtained from the raster, in the areas where it intersects with each of the vector table rows.
* `Custom expression`: (optional) Add a custom SQL expression containing an operation that aggregates values from the different bands in the raster, for example `AVG(band_1+band_2) as avg_band_sum`

**Outputs**

* `Result table [Table]`: A table that contains the same rows as the input Vector table, with an additional column for each raster aggregated property and any additional property defined as a custom expression. The values for those columns are the computed aggregation from all pixels in the raster that intersect with the vector feature.

## Raster Algebra

**Description**

This component computes a new raster from one or more rasters by evaluating an expression pixel by pixel. Use it to compare rasters (for example, the difference between a before and an after raster), to compute band indices like NDVI, or to build masks and classifications. The result is a new [RaQuet](https://www.raquet.io/) v0.5.0 raster table.

The connected rasters are referenced in the expression as `$a`, `$b`, `$c` and `$d`, and their bands as `$a.band_1` (by name) or `$a[1]` (by position). A single-band raster can also be referenced simply as `$a`.

To compute several output bands at once, separate the expressions with `;`. Line breaks don't separate them. Each output can have a name, and unnamed outputs are called `band_1`, `band_2` and so on. For example:

`ndvi = ($a.band_4 - $a.band_3) / ($a.band_4 + $a.band_3); vegetation = $a.band_4 > 1000`

Output names must be unique, ignoring case. They can't be `block` or `metadata`, and they can't end in `_count`, `_min`, `_max`, `_sum`, `_mean` or `_stddev`, because the result uses those names for its statistics columns.

The expression supports the following syntax:

| Syntax                                                                                                                                                | Description                                                                   |
| ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| `+`, `-`, `*`, `/`, `%`, `^` (or `**`)                                                                                                                | Arithmetic.                                                                   |
| `<`, `<=`, `>`, `>=`, `==`, `!=`                                                                                                                      | Comparisons, returning `1` or `0`.                                            |
| `and`, `or`, `not`                                                                                                                                    | Logical operators, returning `1` or `0`.                                      |
| `if(condition, a, b)`                                                                                                                                 | `a` where `condition` is not `0`, `b` otherwise.                              |
| `abs`, `sqrt`, `exp`, `log`, `log10`, `log2`, `pow`, `min`, `max`, `floor`, `ceil`, `round`, `clamp(x, lo, hi)`, `sin`, `cos`, `tan`, `atan`, `atan2` | Math functions. `log` is the natural logarithm, and `round` rounds halves up. |
| `pi`, `e`                                                                                                                                             | Constants.                                                                    |

An output pixel is empty (nodata) when any input pixel used in its expression is empty, or when the result is not a valid number (for example, a division by zero). This also applies to both branches of `if()`: `if($a > 0, $a, $b)` is empty wherever `$b` is empty, even where `$a > 0`.

The component runs the `RASTER_ALGEBRA` procedure of the Analytics Toolbox ([BigQuery](/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/raster.md#raster_algebra), [Snowflake](/data-and-analysis/analytics-toolbox-for-snowflake/sql-reference/raster.md#raster_algebra)), and needs version 1.26.0 or later on BigQuery and 1.28.0 or later on Snowflake. If you manage your own Analytics Toolbox installation, update it to one of these versions to use the component.

**Inputs**

* `Raster $a [Table]`: raster data source referenced as `$a` in the expression.
* `Raster $b`, `Raster $c`, `Raster $d [Table]`: (optional) additional raster data sources, referenced as `$b`, `$c` and `$d`. Connect them in order. Every connected raster must be used in the expression.
* `Expression`: the expression to compute for each pixel.

All the rasters must be RaQuet v0.5.0 raster tables. Rasters you [import into CARTO](/carto-user-manual/data-explorer/importing-data.md) are in this format, and so are those written by the [raquet](https://github.com/CartoDB/raquet) tools. Rasters imported earlier, in a previous RaQuet version, are rejected with an error that asks for v0.5.0: import them again. Rasters with a time dimension or with lossy (JPEG/WebP) compression are not supported.

{% hint style="warning" %}
When you import an RGB image (three 8-bit bands tagged as red, green and blue), CARTO compresses it as WebP, so you can't use it in Raster Algebra. See [RGB images](/carto-user-manual/data-explorer/importing-data.md#rgb-images) to import it with separate bands.
{% endhint %}

The rasters must also share the same block size and resolution. Rasters with a different resolution are not resampled, so import them again at a common resolution. Their extents can be different: each output band covers the area where the rasters used in its expression overlap.

**Advanced options**

* `Output data type`: Default `float32`. Data type of the output bands. Integer types round the results, and values that don't fit the type become empty. Integer types also use one of their values to mark empty pixels: the minimum for signed types and the maximum for unsigned types (for example, `255` for `uint8`). A result equal to that value is empty too.
* `Overviews`: Default `Compute all zoom levels`, which computes the expression on every zoom level the rasters share, so the result can be visualized at any zoom level right away. `Native resolution only` computes only the full-resolution pixels.
* `Use physical values (apply band scale and offset)`: Default `true`. Band values are converted with the scale and offset defined in the raster metadata, if any, before evaluating the expression. Disable it to work on the values as stored.

**Outputs**

* `Result table [Table]`: a RaQuet v0.5.0 raster table with one column per output band, per-tile statistics columns for each band (`<band>_count`, `_min`, `_max`, `_sum`, `_mean` and `_stddev`) and a metadata row with the band statistics and the expression used.

The **Map** tab previews the result. To keep it, or to open it in Builder, connect a [Save as Table](/carto-user-manual/workflows/components/input-output.md#save-as-table) component.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.carto.com/carto-user-manual/workflows/components/raster-operations.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
