# Spatial Indexes

Hierarchical grid systems, such as Quadbin and H3, are an essential tool for analysing large spatial datasets, especially when dealing with data sources in different spatial aggregations. These systems are based on geospatial indexes that provide a direct relationship between grid cells at different resolutions, enabling extremely performant spatial operations.

<table data-view="cards"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td>Quadbin (<a href="https://docs.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system">source</a>)</td><td></td><td></td><td><a href="/files/oz3crRb9Q96YEaF0WYxb">/files/oz3crRb9Q96YEaF0WYxb</a></td></tr><tr><td>H3 (<a href="https://h3geo.org/">source</a>)</td><td></td><td></td><td><a href="/files/YxeCzug41GHeHfpgFV4g">/files/YxeCzug41GHeHfpgFV4g</a></td></tr></tbody></table>

Go to the [Reference](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-oracle/sql-reference/quadbin) for the full list of available functions. If you can't find what you need, please let us know by opening an issue in our [Github repository](https://github.com/CartoDB/analytics-toolbox-core) or become a contributor.

## Quadbin <a href="#quadbin" id="quadbin"></a>

Quadbin is a hierarchical geospatial index based on the [Bing Maps Tile System](https://docs.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system) (Quadkey). Designed to be cluster-efficient, it stores in a 64-bit number the information to uniquely identify any of the grid cells that result from uniformly subdividing a map in Mercator projection into four squares at different resolution levels, from 0 to 26 (less than 1m² at the equator). The bit layout is inspired in the H3 design, and provides different modes to store not only cells, but edges, corners or vertices.

In Oracle, Quadbin indexes are represented as a `NUMBER` (the 38-digit precision safely holds the 64-bit cell id). See the [quadbin reference](/data-and-analysis/analytics-toolbox-for-oracle/sql-reference/quadbin.md) for the full list of available functions.

## H3 <a href="#h3" id="h3"></a>

[H3](https://h3geo.org/) is a multiresolution hexagonal global grid system with hierarchical indexing developed by Uber. It supports sixteen resolutions, each of them composed of cells with one-seventh the area of the lower resolution containing cell. Each hexagon cell at a particular resolution is uniquely identified, and these identifiers can be easily truncated to find the coarser-containing cell. However, since a hexagon cannot be exactly subdivided into seven hexagons, this process always results in a fixed amount of shape distortion.

Instead of constructing a grid over a planar projection like Quadbin does, H3 projects from Earth like a sphere to a regular icosahedron, and then lays out hexagonal grid cells on each of its faces.

One of the most powerful properties of H3 is that all neighboring hexagons of a particular cell are at an equal distance. This enables fast computation of grid distances between hexagons and neighbouring areas around an index using the DISTANCE and KRING functions, respectively.

In Oracle, H3 indexes are represented as a `VARCHAR2(16)` hex string. See the [h3 reference](/data-and-analysis/analytics-toolbox-for-oracle/sql-reference/h3.md) for the full list of available functions.

<figure><img src="/files/TzIcoNEwcztsUP2F7GKJ" alt="H3 KRing"><figcaption><p>kRings of distance 1, 2 and 3 around an H3 index of resolution 11.</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.carto.com/data-and-analysis/analytics-toolbox-for-oracle/key-concepts/spatial-indexes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
