Skip to main content
Your Nile database arrives with h3_postgis extension and its dependencies h3 and postgis already installed and enabled.

H3_postgis Functions and Usage

The h3_postgis extension provides several functions that enable interoperability between H3 and PostGIS.

Converting a Geometry to an H3 Index

To convert a PostGIS geometry (Point) into an H3 index at a given resolution:

Converting an H3 Index to a Geometry

To convert an H3 index into a PostGIS polygon geometry:

Finding Neighboring H3 Cells as Geometries

To get the neighboring H3 cells as PostGIS geometries:

Checking if a Point is Within an H3 Cell

To check if a given point lies within an H3 indexed cell:

Example: Storing H3 Indices and Geometries in a Table

A common use case is storing H3 indices alongside geospatial data:

Querying Locations by Proximity

To find all locations within a given H3 ring distance:

Use Cases

  • Efficient geospatial indexing using hexagonal grids.
  • Spatial analysis integrating H3 with PostGIS functions.
  • Fast proximity searches based on geospatial cells rather than bounding boxes.

Limitations

  • H3 cells approximate real-world geography and do not align with political or administrative boundaries.
  • Higher-resolution H3 cells increase data granularity but also computational costs.

Conclusion

The h3_postgis extension in PostgreSQL enables seamless integration between H3 spatial indexing and PostGIS geometry operations, making it an excellent choice for advanced geospatial analysis and location-based applications. For more details, refer to the h3-pg GitHub repository.