Inter-American Development BankGet the code
What is it?
BabelGrid is a Python package that unifies established geospatial indexing system APIs like H3, S2 and QuadTree.
Why was it created?
A geospatial indexing systems (GIS) is a structured way to divide the world in regular grids. Once defined, these grids have properties that are quite helpful for developers and researchers. For instance, each grid tile has a unique identifier, a parent (a tile hat contains it) and children (tiles that it contains). Another property is the tile shape. Depending on the system, a grid tile can be a square or a hexagon. Even though the goal is the same, each GIS is developed to accomplish certain goals. Let’s take a look at some of the most used systems.
QuadTree was first developed to address the problem of loading satellite images in the web. When you are navigating through a map, each time that you move or zoom, the app has to load a new image. At the highest zoom level, the app needs to search through millions of satellite images as fast as possible. To address this problem, the QuadTree system divides the world in decreasingly smaller squares that contain a satellite image. Each square, contains other 4 smaller squares. As you can notice from the image below, each new square carries the unique identifier of their parents. A property that allows a mapping app to look for an image almost instantly.
(Image source: from https://docs.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system)
The H3 indexing system developed by Uber, was designed to solve a different problem. Uber needs to provide geospatial insights about user demand and pricing to its drivers and staff. It does that by aggregating point-like data in areas to create heatmaps (see image below). Given that it solves a different problem, the H3 has hexagon tiles. The uniform distance between the hexagon center point and its neighbours is a great feature for statistical models. Which is one of the reasons that attracted the research community to H3
(Image source: from https://eng.uber.com/h3/)
There are other geospatial indexing systems like Google’s S2, GeoHash and XYZ. Each with its specific design decisions was developed to solve a specific problem. But, with the rise of the Data for Good movement, more and more companies are using these established grids to share their data.
Facebook shares its Movement datasets using the QuadTree system. On the other hand, Waze prefers the S2 system. And, the research community usually uses H3. However, even though the systems have equivalent properties, each of them has a different Python API. This implies that a researcher needs to learn and adapt her code to each API, a task that can be quite cumbersome, given that some APIs are not intuitive and have poor documentation. BabelGrid intends to tackle this issue.
BabelGrid unifies geospatial indexing system APIs around a common Python API. BabelGrid is simple to use and intuitive. The image below shows how one can easily get a tile using geographical coordinates. The user can choose the resolution of the tile or the tile closest to an area in kilometers.
One can also easily change the grid. Currently, BabelGrid supports H3, S2 and QuadTree.
If a user wants to get all tiles inside a boundary, BabelGrid has a convenient function that makes it super simple.
Why are we sharing it?
As a Python package, BabelGrid is a tool that can be easily used by researchers, data scientists, and companies. Since there is no tool that achieves the same goal, it has the potential to become a reference in the geocommunity. In the future, it can be expanded to cover more systems and have more functionalities.