# GeoTile Aggregation

**URL:** <https://discuss.elastic.co/t/geotile-aggregation/225552>\
**Category:** Elasticsearch\
**Created:** [March 29, 2020, 12:51pm UTC](https://discuss.elastic.co/t/geotile-aggregation/225552 "2020-03-29T12:51:12Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nishant\_Gauttam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nishant_gauttam/32/65047_2.png) [@Nishant\_Gauttam](https://discuss.elastic.co/u/Nishant_Gauttam)\
**Post date:** [March 29, 2020, 12:51pm UTC](https://discuss.elastic.co/t/geotile-aggregation/225552/1 "2020-03-29T12:51:12Z")

</div>

I am working on geo data. where I need to show the heatmaps based on aggregation. The data ponts are quite high in volume in any area so looking for some clustering techniques on server side. I came across geotile grid aggregation. -  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geotilegrid-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geotilegrid-aggregation.html)

```auto
The response - 

"buckets": [
                {
                  "key" : "8/131/84",
                  "doc_count" : 3
                },
                {
                  "key" : "8/129/88",
                  "doc_count" : 2
                },

```

I cant understand how these keys are consumed. How google maps will consume these keys on mobile app or is it specific to Elastic Maps?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 29, 2020, 1:17pm UTC](https://discuss.elastic.co/t/geotile-aggregation/225552/2 "2020-03-29T13:17:38Z")

</div>

The output is:

> Each cell corresponds to a [map tile](https://en.wikipedia.org/wiki/Tiled_web_map) as used by many online map sites. Each cell is labeled using a "{zoom}/{x}/{y}" format, where zoom is equal to the user-specified precision.

I don't know if google maps knows how to use that but for sure, Kibana does know it.

---

<div class="post-metadata">

**Author:** ![Nishant\_Gauttam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nishant_gauttam/32/65047_2.png) [@Nishant\_Gauttam](https://discuss.elastic.co/u/Nishant_Gauttam)\
**Post date:** [March 29, 2020, 5:08pm UTC](https://discuss.elastic.co/t/geotile-aggregation/225552/3 "2020-03-29T17:08:31Z")

</div>

Thanks , Just for the reference can you give me some links how other major map sites can render this response.

```auto
{
                  "key" : "8/131/84",
                  "doc_count" : 3
}

```

I checked [Mapbox](http://mapbox.com), [Leaflet](http://leafletjs.com/). We can pass them Geojson data. but not sure how to pass tileid and aggregation count. It will be great if you can point me in the right direction.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 29, 2020, 6:39pm UTC](https://discuss.elastic.co/t/geotile-aggregation/225552/4 "2020-03-29T18:39:50Z")

</div>

No idea. What's wrong with Kibana?

---

<div class="post-metadata">

**Author:** ![Nishant\_Gauttam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nishant_gauttam/32/65047_2.png) [@Nishant\_Gauttam](https://discuss.elastic.co/u/Nishant_Gauttam)\
**Post date:** [March 30, 2020, 1:53am UTC](https://discuss.elastic.co/t/geotile-aggregation/225552/5 "2020-03-30T01:53:44Z")

</div>

I have to show the maps on mobile apps.

---

<div class="post-metadata">

**Author:** ![nickpeihl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nickpeihl/32/112622_2.png) [@nickpeihl](https://discuss.elastic.co/u/nickpeihl)\
**Post date:** [March 30, 2020, 5:49pm UTC](https://discuss.elastic.co/t/geotile-aggregation/225552/6 "2020-03-30T17:49:14Z")

</div>

Hi @Nishant_Gauttam,

I'm an engineer on the Kibana team. The GeoTile Grid aggregation returns a key to a specific tile in the Web Mercator coordinate system. There are open source libraries such as [SphericalMercator](https://github.com/mapbox/sphericalmercator) which can convert the tile key to a bounding box.

For heat maps you might want to request a GeoTile aggregation with a higher precision than the current zoom level of the client map. So if the map is on zoom level 8, you may want to set a precision of 10-12 for the geo\_grid aggregation. Then you can convert the aggregation results (tile keys & doc\_counts) to centroids and use a client-side heatmap generator (ex. [Mapbox](https://docs.mapbox.com/mapbox-gl-js/example/heatmap-layer/), [Leaflet](https://github.com/Leaflet/Leaflet.heat)) to display the results. This is how Elastic Maps creates heat maps.

There are a few examples for converting tile keys to lat lon here. [https://wiki.openstreetmap.org/wiki/Slippy\_map\_tilenames#Implementations](https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Implementations)

---

<div class="post-metadata">

**Author:** ![Nishant\_Gauttam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nishant_gauttam/32/65047_2.png) [@Nishant\_Gauttam](https://discuss.elastic.co/u/Nishant_Gauttam)\
**Post date:** [March 31, 2020, 1:42pm UTC](https://discuss.elastic.co/t/geotile-aggregation/225552/7 "2020-03-31T13:42:23Z")

</div>

@nickpeihl, Thanks a ton . Understood it now.  
Couple of more points -

1. How can I find what different tiles a city(washington or newyork) or a bounding box would cover at a certain zoom level. Any easy way to find out all tiles at highest zoom level a city or a bounding box would cover ?
2. I am planning to precreate geojson for each city at 10-12 zoom level and pass precreated JSON file as response to client for that city. So that client side map libraries can render the heatmaps.

---

<div class="post-metadata">

**Author:** ![nickpeihl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nickpeihl/32/112622_2.png) [@nickpeihl](https://discuss.elastic.co/u/nickpeihl)\
**Post date:** [March 31, 2020, 8:55pm UTC](https://discuss.elastic.co/t/geotile-aggregation/225552/8 "2020-03-31T20:55:04Z")

</div>

For a quick look at which tiles cover a certain area, I use [bboxfinder](http://bboxfinder.com). For scripting, [tilebelt](https://github.com/mapbox/tilebelt) may be useful. It has functions like `bboxToTile` and `getChildren` that may help. Perhaps you can use those functions directly or look at the math in the source code to figure out what you need.

---

<div class="post-metadata">

**Author:** ![Nishant\_Gauttam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nishant_gauttam/32/65047_2.png) [@Nishant\_Gauttam](https://discuss.elastic.co/u/Nishant_Gauttam)\
**Post date:** [April 1, 2020, 3:19am UTC](https://discuss.elastic.co/t/geotile-aggregation/225552/9 "2020-04-01T03:19:45Z")

</div>

thanks @nickpeihl  
Also for performance considerations on device is clustering better than heatmap. ?

In your earlier reply you mentioned that For heat maps you might want to request a GeoTile aggregation with a higher precision than the current zoom level of the client map. Dont I have to do same stuff If I do clustering ?

---

<div class="post-metadata">

**Author:** ![nickpeihl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nickpeihl/32/112622_2.png) [@nickpeihl](https://discuss.elastic.co/u/nickpeihl)\
**Post date:** [April 2, 2020, 5:33am UTC](https://discuss.elastic.co/t/geotile-aggregation/225552/10 "2020-04-02T05:33:27Z")

</div>

Sorry, I do not have benchmarks on performance of clusters and heatmaps on clients. I think that would depend on which client mapping library you use.

And yes, both clusters and heatmaps would require a higher precision.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 30, 2020, 5:33am UTC](https://discuss.elastic.co/t/geotile-aggregation/225552/11 "2020-04-30T05:33:30Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
