Convert Figma logo to code with AI

uber logoh3

Hexagonal hierarchical geospatial indexing system

5,396
511
5,396
126

Top Related Projects

10,872

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

Computational geometry and spatial indexing on the sphere

2,101

The JTS Topology Suite is a Java library for creating and manipulating vector geometry.

Official GeoTools repository

Quick Overview

H3 is a hexagonal hierarchical geospatial indexing system developed by Uber. It provides a way to efficiently index and analyze location data using a grid of hexagonal cells at multiple resolutions. H3 offers a unique approach to geospatial indexing, combining the benefits of hexagonal grids with hierarchical organization.

Pros

  • Hierarchical structure allows for efficient multi-resolution analysis
  • Hexagonal grid provides more uniform coverage compared to square grids
  • Supports various operations like hierarchical grid traversal and hexagon neighbor finding
  • Available in multiple programming languages through bindings

Cons

  • Learning curve for developers unfamiliar with hexagonal grid systems
  • May require additional processing overhead compared to simpler indexing systems
  • Limited built-in support for complex geospatial operations beyond basic indexing
  • Potential precision loss at certain resolutions due to the discrete nature of the grid

Code Examples

  1. Converting lat/lon to H3 index:
from h3 import h3

lat, lng = 37.7752, -122.4185
resolution = 9
h3_index = h3.geo_to_h3(lat, lng, resolution)
print(h3_index)  # Output: '8928308280fffff'
  1. Getting the hexagon boundary:
from h3 import h3

h3_index = '8928308280fffff'
boundary = h3.h3_to_geo_boundary(h3_index)
print(boundary)  # Output: list of [lat, lng] coordinates
  1. Finding neighboring hexagons:
from h3 import h3

h3_index = '8928308280fffff'
neighbors = h3.k_ring(h3_index, 1)
print(neighbors)  # Output: set of neighboring H3 indexes

Getting Started

To get started with H3, first install the library:

pip install h3

Then, you can use H3 in your Python code:

from h3 import h3

# Convert lat/lon to H3 index
lat, lng = 37.7752, -122.4185
resolution = 9
h3_index = h3.geo_to_h3(lat, lng, resolution)

# Get hexagon center
center = h3.h3_to_geo(h3_index)

# Find neighboring hexagons
neighbors = h3.k_ring(h3_index, 1)

print(f"H3 Index: {h3_index}")
print(f"Center: {center}")
print(f"Neighbors: {neighbors}")

This example demonstrates basic H3 operations: converting coordinates to an H3 index, retrieving the hexagon center, and finding neighboring hexagons.

Competitor Comparisons

10,872

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

Pros of Kepler.gl

  • Interactive and user-friendly visualization tool for geospatial data
  • Supports multiple data formats and layer types
  • Offers a wide range of customization options for maps and charts

Cons of Kepler.gl

  • Larger file size and more complex setup compared to H3
  • May have a steeper learning curve for users new to geospatial visualization
  • Less suitable for low-level, programmatic geospatial operations

Code Comparison

H3:

H3Index h3_index = geoToH3(&geo_coord, resolution);

Kepler.gl:

const map = new KeplerGl({
  mapboxApiAccessToken: 'YOUR_MAPBOX_TOKEN',
  container: 'map'
});

H3 focuses on efficient hexagonal indexing and geospatial calculations, while Kepler.gl provides a comprehensive framework for creating interactive geospatial visualizations. H3 is more suitable for backend processing and analysis, whereas Kepler.gl excels in creating visually appealing, interactive maps for frontend applications. The code examples highlight the difference in complexity and use cases between the two libraries.

Computational geometry and spatial indexing on the sphere

Pros of S2Geometry

  • More flexible geometry support, including arbitrary polygons and polylines
  • Better support for spherical geometry calculations and projections
  • More extensive documentation and examples

Cons of S2Geometry

  • Steeper learning curve due to more complex API
  • Larger codebase and potentially slower performance for simple use cases
  • Less focus on hierarchical indexing compared to H3

Code Comparison

H3:

H3Index h3_index = geoToH3(&geo, resolution);
GeoCoord center;
h3ToGeo(h3_index, &center);

S2Geometry:

S2LatLng latlng(S2LatLng::FromDegrees(lat, lng));
S2CellId cellId = S2CellId::FromLatLng(latlng);
S2Cell cell(cellId);

Both libraries provide methods for converting between geographic coordinates and their respective cell/index systems. H3 uses a simpler API with fewer steps, while S2Geometry offers more flexibility and options for working with spherical geometry.

S2Geometry is generally better suited for complex geometric operations and analysis on a sphere, while H3 excels in hierarchical indexing and simple location-based queries. The choice between the two depends on the specific requirements of your project and the level of geometric complexity you need to handle.

2,101

The JTS Topology Suite is a Java library for creating and manipulating vector geometry.

Pros of JTS

  • More comprehensive geometric operations and algorithms
  • Supports a wider range of spatial data types and formats
  • Better suited for complex spatial analysis and GIS applications

Cons of JTS

  • Larger library size and potentially higher resource usage
  • Steeper learning curve due to more extensive API
  • May be overkill for simpler geospatial tasks

Code Comparison

H3:

H3Index h3_index = geoToH3(&geo, resolution);
GeoCoord center;
h3ToGeo(h3_index, &center);

JTS:

Geometry point = geometryFactory.createPoint(new Coordinate(lon, lat));
Geometry buffer = point.buffer(distance);
Geometry intersection = buffer.intersection(otherGeometry);

Summary

JTS offers a more comprehensive set of geometric operations and supports a wider range of spatial data types, making it better suited for complex spatial analysis. However, it has a larger footprint and steeper learning curve compared to H3. H3 is more focused on hexagonal grid systems and may be more efficient for specific use cases involving hierarchical indexing and simple distance calculations.

Official GeoTools repository

Pros of GeoTools

  • Comprehensive geospatial library with a wide range of functionalities
  • Supports various data formats and coordinate reference systems
  • Active community and extensive documentation

Cons of GeoTools

  • Larger footprint and potentially steeper learning curve
  • May be overkill for simpler geospatial tasks
  • Java-centric, which might not be ideal for all projects

Code Comparison

GeoTools example (Java):

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
Coordinate coord = new Coordinate(5, 5);
Point point = geometryFactory.createPoint(coord);

H3 example (C):

GeoCoord location = {0.0, 0.0};
H3Index indexed = geoToH3(&location, 10);

H3 focuses on hexagonal hierarchical geospatial indexing, while GeoTools offers a broader range of geospatial operations. H3 is more lightweight and specialized, making it suitable for specific use cases like efficient spatial indexing and analysis. GeoTools, on the other hand, provides a more comprehensive toolkit for various geospatial tasks but may require more resources and setup time.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

H3 Logo

H3: A Hexagonal Hierarchical Geospatial Indexing System

test-linux test-macos test-windows test-website Coverage Status License

H3 is a geospatial indexing system using a hexagonal grid that can be (approximately) subdivided into finer and finer hexagonal grids, combining the benefits of a hexagonal grid with S2's hierarchical subdivisions.

Documentation is available at https://h3geo.org/. Developer documentation in Markdown format is available under the dev-docs directory.

Installing

We recommend using prebuilt bindings if they are available for your programming language. Bindings for Java, JavaScript, Python, and others are available.

On macOS, you can install H3 using brew:

brew install h3

Otherwise, to build H3 from source, please see the following instructions.

Building from source

Still here? To build the H3 C library, you'll need a C compiler (tested with gcc and clang), CMake, and Make. If you intend to contribute to H3, you must have clang-format installed and we recommend installing ccmake and LCOV to configure the cmake arguments to build and run the tests and generate the code coverage report. We also recommend using gcc for the code coverage as some versions of clang generate annotations that aren't compatible with lcov. Doxygen is needed to build the API documentation.

Install build-time dependencies

  • Alpine
# Installing the bare build requirements
apk add cmake make gcc libtool musl-dev
  • Debian/Ubuntu
# Installing the bare build requirements
sudo apt install cmake make gcc libtool
# Installing useful tools for development
sudo apt install clang-format cmake-curses-gui lcov doxygen
  • macOS (using brew)

First make sure you have the developer tools installed and then

# Installing the bare build requirements
brew install cmake
# Installing useful tools for development
brew install clang-format lcov doxygen
  • Windows (Visual Studio)

You will need to install CMake and Visual Studio, including the Visual C++ compiler. For building on Windows, please follow the Windows build instructions.

  • FreeBSD
# Installing the build requirements
sudo pkg install bash cmake gmake doxygen lcov

Compilation

When checking out the H3 Git repository, by default you will check out the latest development version of H3. When using H3 in an application, you will want to check out the most recently released version:

git checkout v$(<VERSION)

From the repository root, you can compile H3 with:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make

All subsequent make commands should be run from within the build directory.

Note: There are several ways to build H3 with CMake; the method above is just one example that restricts all build artifacts to the build directory.

You can install system-wide with:

sudo make install

If using the method above, from the repository root, you can clean all build artifacts with:

rm -rf build

Testing

After making the project, you can test with make test. You can run a faster test suite that excludes the most expensive tests with make test-fast.

Coverage

You can generate a code coverage report if lcov is installed, and if the project was built with the CMAKE_BUILD_TYPE=Debug and ENABLE_COVERAGE=ON options. For example, from a clean repository, you could run:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_COVERAGE=ON ..
make
make coverage

You can then view a detailed HTML coverage report by opening coverage/index.html in your browser.

Benchmarks

You can run timing benchmarks by building with the CMAKE_BUILD_TYPE=Release, and running make benchmarks:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make
make benchmarks

Documentation

You can build developer documentation with make docs if Doxygen was installed when CMake was run. Index of the documentation will be dev-docs/_build/html/index.html.

After making the project, you can build KML files to visualize the hexagon grid with make kml. The files will be placed in KML.

To build the documentation website, see the website/ directory.

Usage

From the command line

To get the H3 index for some location:

./bin/latLngToCell --resolution 10 --latitude 40.689167 --longitude -74.044444

10 is the H3 resolution, between 0 (coarsest) and 15 (finest). The coordinates entered are the latitude and longitude, in degrees, you want the index for (these coordinates are the Statue of Liberty). You should get an H3 index as output, like 8a2a1072b59ffff.

You can then take this index and get some information about it, for example:

./bin/cellToBoundary --index 8a2a1072b59ffff

This will produce the vertices of the hexagon at this location:

8a2a1072b59ffff
{
   40.690058601 -74.044151762
   40.689907695 -74.045061792
   40.689270936 -74.045341418
   40.688785091 -74.044711031
   40.688935993 -74.043801021
   40.689572744 -74.043521377
}

You can get the center coordinate of the hexagon like so:

./bin/cellToLatLng --index 8a2a1072b59ffff

This will produce some coordinate:

40.6894218437 -74.0444313999

From C

The above features of H3 can also be used from C. For example, you can compile and run examples/index.c like so:

cc -lh3 examples/index.c -o example
./example

You should get output like:

The index is: 8a2a1072b59ffff
Boundary vertex #0: 40.690059, -74.044152
Boundary vertex #1: 40.689908, -74.045062
Boundary vertex #2: 40.689271, -74.045341
Boundary vertex #3: 40.688785, -74.044711
Boundary vertex #4: 40.688936, -74.043801
Boundary vertex #5: 40.689573, -74.043521
Center coordinates: 40.689422, -74.044431

Contributing

Pull requests and Github issues are welcome. Please see our contributing guide for more information.

Before we can merge your changes, you must agree to the Uber Contributor License Agreement.

Legal and Licensing

H3 is licensed under the Apache 2.0 License.

DGGRID Copyright (c) 2015 Southern Oregon University

NPM DownloadsLast 30 Days