# Spatial Indexes

Components to operate with spatial indexes: H3 and Quadbin. [Learn more](https://carto.com/solutions/spatial-indexes/) about how to leverage spatial indexes in your analyses.

## H3 Boundary

{% hint style="info" %}
This component requires [the CARTO Analytics Toolbox](https://docs.carto.com/data-and-analysis/analytics-toolbox-overview) installed in the chosen connection to build the workflow.
{% endhint %}

**Description**

This component takes a table with H3 cell indices and generates a new one with an additional column containing the boundaries of those H3 cells.

**Inputs**

* `Source table [Table]`
* `H3 column [Column]`

**Outputs**

* `Result table [Table]`

**External links**

[BigQuery reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/h3#h3_boundary)

[Snowflake reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-snowflake/sql-reference/h3#h3_boundary)

## H3 Center

{% hint style="info" %}
This component requires [the CARTO Analytics Toolbox](https://docs.carto.com/data-and-analysis/analytics-toolbox-overview) installed in the chosen connection to build the workflow.
{% endhint %}

**Description**

This component adds a new column containing the centers of H3 cells.

**Inputs**

* `Source table [Table]`
* `H3 column [Column]`

**Outputs**

* `Result table [Table]`:

**External links**

[BigQuery reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/h3#h3_center)

## H3 Grid Distance

{% hint style="info" %}
This component requires [the CARTO Analytics Toolbox](https://docs.carto.com/data-and-analysis/analytics-toolbox-overview) installed in the chosen connection to build the workflow.
{% endhint %}

**Description**

This component computes the H3 grid distance between two H3 index columns, creating a new table with the same columns as the source one and adding a new 'h3\_distance' column.

The H3 distance is defined as the length of the shortest path between the cells in the graph formed by connecting adjacent cells.

This function will return 'null' if the cells are too far apart to compute the distance.

**Inputs**

* `Source table [Table]`
* `First H3 index column [Column]`
* `Second H3 index column [Column]`

**Outputs**

* `Result table [Table]`:

**External links**

[BigQuery reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/h3#h3_distance)

## H3 from GeoPoint

{% hint style="info" %}
This component requires [the CARTO Analytics Toolbox](https://docs.carto.com/data-and-analysis/analytics-toolbox-overview) installed in the chosen connection to build the workflow.
{% endhint %}

**Description**

This component adds a new column containing the indices of H3 cells corresponding to points.

**Inputs**

* `Source table [Table]`
* `Points column [Column]`
* `Resolution [Number]`

**Outputs**

* `Result table [Table]`

**External links**

[BigQuery reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/h3#h3_fromgeogpoint)

[Snowflake reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-snowflake/sql-reference/h3#h3_fromgeogpoint)

## H3 KRing

{% hint style="info" %}
This component requires [the CARTO Analytics Toolbox](https://docs.carto.com/data-and-analysis/analytics-toolbox-overview) installed in the chosen connection to build the workflow.
{% endhint %}

**Description**

Expands each H3 cell to include all neighboring cells within K hexagonal rings. Creates one row per neighbor cell, useful for spatial smoothing, neighborhood analysis, and buffer operations on H3 grids. Optionally includes the ring distance (0 = original cell, 1 = immediate neighbors, etc.).

**Inputs**

* `Source table [Table]`
* `H3 index [Column]`
* `Size [Number]`
* `Include distance [Boolean]`: add or not column with the value of H3 distance
* `Include columns [Boolean]`: copy or not source columns in the result table

**Outputs**

* `Result table [Table]`:

**External links**

[BigQuery reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/h3#h3_kring)

[Snowflake reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-snowflake/sql-reference/h3#h3_kring)

[Postgres reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-postgresql/sql-reference/h3#_kring)

## H3 Polyfill

{% hint style="info" %}
This component requires [the CARTO Analytics Toolbox](https://docs.carto.com/data-and-analysis/analytics-toolbox-overview) installed in the chosen connection to build the workflow.
{% endhint %}

**Description**

This generates a table with indices of all H3 cells included within a given extent for a given resolution.

The extent is specified using a table with polygons.

**Inputs**

* `Source table [Table]`
* `Geo column [Column]`
* `Resolution [Number]`
* `Keep input table columns`: If checked, all the original columns of the source table will be added to the result table. Otherwise, only columns with the geometry and the H3 index will be added.
* `Mode:`
  * `Center:`Returns only the cells which centroid intersects with the input features.
  * `Intersects:`Returns all cells that intersect with the input features.
  * `Contains:`Returns only the cells that are entirely contained within the input features.

**Outputs**

* `Result table [Table]`:

**External links**

[BigQuery reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/h3#h3_polyfill)

[Snowflake reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-snowflake/sql-reference/h3#h3_polyfill)

[Postgres reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-postgresql/sql-reference/h3#h3_polyfill)

## H3 To Parent

{% hint style="info" %}
This component requires [the CARTO Analytics Toolbox](https://docs.carto.com/data-and-analysis/analytics-toolbox-overview) installed in the chosen connection to build the workflow.
{% endhint %}

**Description**

Adds a new column named h3\_parent with the value of the parent h3 at a specific resolution. If required resolution is higher than h3 column, a null value will be set.

**Inputs**

* `Source table [Table]`
* `H3 index [Column]`
* `Resolution [Number]`

**Outputs**

* `Result table [Table]`:

**External links**

[BigQuery reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/h3#h3_toparent)

[Snowflake reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-snowflake/sql-reference/h3#h3_toparent)

[Postgres reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-postgresql/sql-reference/h3#_toparent)

## Quadbin Boundary

{% hint style="info" %}
This component requires [the CARTO Analytics Toolbox](https://docs.carto.com/data-and-analysis/analytics-toolbox-overview) installed in the chosen connection to build the workflow.
{% endhint %}

**Description**

This component takes a table with Quadbin cell indices and generates a new one with an additional column containing the boundaries of those Quadbin cells.

**Inputs**

* `Source table [Table]`
* `Quadbin column [Column]`

**Outputs**

* `Result table [Table]`

**External links**

[BigQuery reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/quadbin#quadbin_boundary)

[Snowflake reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-snowflake/sql-reference/quadbin#quadbin_boundary)

[Redshift reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-redshift/sql-reference/quadbin#quadbin_boundary)

[PostgreSQL reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-postgresql/sql-reference/quadbin#quadbin_boundary)

## Quadbin Center

{% hint style="info" %}
This component requires [the CARTO Analytics Toolbox](https://docs.carto.com/data-and-analysis/analytics-toolbox-overview) installed in the chosen connection to build the workflow.
{% endhint %}

**Description**

This component adds a new column containing the centers of Quadbin cells.

**Inputs**

* `Source table [Table]`
* `Quadbin column [Column]`

**Outputs**

* `Result table [Table]`

**External links**

[BigQuery reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/quadbin#quadbin_center)

[Snowflake reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-snowflake/sql-reference/quadbin#quadbin_center)

[Redshift reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-redshift/sql-reference/quadbin#quadbin_center)

[PostgreSQL reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-postgresql/sql-reference/quadbin#quadbin_center)

## Quadbin from GeoPoint

{% hint style="info" %}
This component requires [the CARTO Analytics Toolbox](https://docs.carto.com/data-and-analysis/analytics-toolbox-overview) installed in the chosen connection to build the workflow.
{% endhint %}

**Description**

This component adds a new column containing the indices of Quadbin cells corresponding to points.

**Inputs**

* `Source table [Table]`
* `Points column [Column]`
* `Resolution [Number]`

**Outputs**

* `Result table [Table]`

**External links**

[BigQuery reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/quadbin#quadbin_fromgeogpoint)

[Snowflake reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-snowflake/sql-reference/quadbin#quadbin_fromgeogpoint)

[Redshift reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-redshift/sql-reference/quadbin#quadbin_fromgeogpoint)

[PostgreSQL reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-postgresql/sql-reference/quadbin#quadbin_fromgeogpoint)

## Quadbin Kring

{% hint style="info" %}
This component requires [the CARTO Analytics Toolbox](https://docs.carto.com/data-and-analysis/analytics-toolbox-overview) installed in the chosen connection to build the workflow.
{% endhint %}

**Description**

Returns all Quadbin cell indexes and their distances in a filled square k-ring of a user defined size centered at the origin in no particular order.

**Inputs**

* `Source table [Table]`
* `Quadbin index [Column]`
* `Size [Number]`
* `Include distance [Boolean]`: add or not column with the value of Quadbin distance
* `Include columns [Boolean]`: copy or not source columns in the result table

**Outputs**

* `Result table [Table]`

**External links**

[BigQuery reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/quadbin#quadbin_kring)

[Snowflake reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-snowflake/sql-reference/quadbin#quadbin_kring)

[Redshift reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-redshift/sql-reference/quadbin#quadbin_kring)

[PostgreSQL reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-postgresql/sql-reference/quadbin#quadbin_kring)

## Quadbin Polyfill

{% hint style="info" %}
This component requires [the CARTO Analytics Toolbox](https://docs.carto.com/data-and-analysis/analytics-toolbox-overview) installed in the chosen connection to build the workflow.
{% endhint %}

**Description**

This generates a table with indices of all Quadbin cells included within a given extent for a given resolution.

The extent is specified using a table with polygons.

**Inputs**

* `Source table [Table]`
* `Geo column [Column]`
* `Resolution [Number]`
* `Mode:`
  * `Center:`Returns only the cells which centroid intersects with the input features.
  * `Intersects:`Returns all cells that intersect with the input features.
  * `Contains:`Returns only the cells that are entirely contained within the input features.

**Outputs**

* `Result table [Table]`

**External links**

[BigQuery reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/quadbin#quadbin_polyfill)

[Snowflake reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-snowflake/sql-reference/quadbin#quadbin_polyfill)

[Redshift reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-redshift/sql-reference/quadbin#quadbin_polyfill)

[PostgreSQL reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-postgresql/sql-reference/quadbin#quadbin_polyfill)

## Quadbin To Parent

{% hint style="info" %}
This component requires [the CARTO Analytics Toolbox](https://docs.carto.com/data-and-analysis/analytics-toolbox-overview) installed in the chosen connection to build the workflow.
{% endhint %}

**Description**

It adds a new column named quadbin\_parent with the value of the parent quadbin at a specific resolution. If required resolution is higher than quadbin column, than an "Invalid resolution" query error will be returned.

**Inputs**

* `Source table [Table]`
* `Quadbin index [Column]`
* `Resolution [Number]`

**Outputs**

* `Result table [Table]`

**External links**

[BigQuery reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/quadbin#quadbin_toparent)

[Snowflake reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-snowflake/sql-reference/quadbin#quadbin_kring)

[Redshift reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-redshift/sql-reference/quadbin#quadbin_kring)

[PostgreSQL reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-postgresql/sql-reference/quadbin#quadbin_kring)
