Beyond Latitude & Longitude: A Guide to H3, S2, and Discrete Global Grid Systems
Every map traditionally starts with latitude and longitude. But if you are building modern data systems, raw coordinates are often too messy, too slow, and too heavy to scale effectively.
There is a better framework that turns the planet into a manageable grid of unique identifiers: Discrete Global Grid Systems (DGGS).
These frameworks—specifically H3, S2, and A5—allow you to trade a tiny bit of precision for massive gains in speed, storage, and interoperability. Here is why you should consider making the switch and how to choose the right spatial index for your stack.
Key Takeaways
1. What is a Discrete Global Grid System (DGGS)? A DGGS divides the earth into hierarchical cells, each with a unique ID. Instead of storing complex point geometries or polygons, you convert a location into a simple string or integer (an index). This index encodes both where the cell is and how big it is (its resolution).
2. The Speed Advantage: Joins on IDs, Not Geometry Spatial joins (finding points inside a polygon) are computationally expensive. By converting locations to grid IDs, you can perform joins, aggregations, and grouping using simple string or integer matching. This is significantly faster than geometric calculations.
3. The Three Major Players: H3 vs. S2 vs. A5
- H3 (Hexagons): Originally from Uber. Best for visualization, data smoothing, and mobility data. The hexagonal shape is aesthetically pleasing and great for neighbor traversal, though edge precision can vary.
- S2 (Squares/Quads): From Google (used in Pokémon GO). Best for backend hierarchical storage and “contains” queries (e.g., is this point inside this box?).
- A5 (Pentagons): A newer system by Felix Palmer. Its superpower is equal area. Unlike H3, where cell sizes vary slightly, A5 cells maintain consistent area, making it superior for strict statistical analysis.
4. The “Medallion” Architecture Strategy Do not delete your raw data. Moving to a grid system means losing the infinite precision of a raw coordinate. For enterprise systems, use a “Medallion” architecture: keep the raw geometry in your Bronze/Silver layer for precision tasks (like parcel mapping), but create a Gold layer of grid-indexed data for fast analytics and visualization.
5. Perfect for AI and Machine Learning Grid cells are excellent for embedding geospatial context into ML models. You can feature engineer across space (e.g., “average income in this cell”) without forcing the model to interpret raw coordinate pairs, which are often noisy.
How to apply this
If you are ready to test grid systems, follow this 3-step approach:
- Select your primary use case:
- Building a dashboard or visual map? Start with H3.
- Building a high-speed backend lookup service? Start with S2.
- Doing heavy statistical analysis requiring equal areas? Start with A5.
- Use the “purpose-built” bindings: Don’t write your own conversion logic. Use the official bindings for Python, JavaScript, or SQL (e.g.,
h3-pyor H3 functions in PostGIS/BigQuery). - Run a side-by-side test: Take a slow-performing spatial query (like a point-in-polygon count). Convert both datasets to Grid IDs at a specific resolution (e.g., H3 resolution 9) and run the join on the ID column. Measure the performance difference.
Closing
Grid systems aren’t just a technical optimization; they fundamentally change how we visualize and analyze the world. If you are still relying solely on lat/long for big data, you are likely working harder than you need to.
