ligorikus / h3-php
Pure PHP implementation of H3 geospatial indexing system
Requires
- php: ^8.2
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^11.0 || ^12.0 || ^13.0
- vimeo/psalm: ^6.16
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-04 09:02:27 UTC
README
Pure PHP implementation of H3 - Uber's hexagonal hierarchical geospatial indexing system.
Installation
composer require ligorikus/h3-php
Requirements
- PHP 8.2+
Development Approach
The library's implementation is developed without large language models (LLMs). LLMs are used only for documentation and writing tests.
Development
Use PHP 8.2.27 or newer to run the development tools. Composer resolves the locked dependencies against PHP 8.2.27 so they also install on PHP 8.2.
composer install
composer test
CI checks the following compatible combinations:
| PHP | PHPUnit |
|---|---|
| 8.2 | 11 |
| 8.3 | 11, 12 |
| 8.4 | 11, 12, 13 |
| 8.5 | 11, 12, 13 |
The matrix resolves dependencies for each actual PHP version. A separate PHP 8.2
job validates and installs composer.lock, audits dependencies, runs tests,
PHPStan, and Psalm.
Quick Start
<?php use H3\H3; use H3\ValueObject\LatLng; $latLng = new LatLng(37.7749, -122.4194); $resolution = 9; $cell = H3::latLngToCell($latLng, $resolution); echo dechex($cell) . "\n"; // 89283082803ffff $center = H3::cellToLatLng($cell); printf("Latitude: %.6f, Longitude: %.6f\n", $center->lat, $center->lng); // Latitude: 37.773515, Longitude: -122.418271
H3::cellToLatLng(int $h3): LatLng returns the center of an H3 cell as a
LatLng object. getLat() and getLng() return coordinates in degrees.
The cell center may differ from the coordinates originally passed to latLngToCell.
H3 indexes are passed as integers; use hexdec('89283082803ffff') to convert a
hexadecimal H3 index string before calling cellToLatLng.
API implementation status
Functions are grouped and ordered as in the official H3 4.x API reference, including experimental functions and C memory-management helpers.
๐ข Implemented ยท ๐ด Not implemented
Status refers to the API exposed by H3\H3. Low-level helpers such as
H3Modification::h3GetResolution() and H3Modification::h3GetIndexDigit()
are available internally but do not expose the corresponding official API methods.
Inspection
- ๐ด
getResolution - ๐ด
getBaseCellNumber - ๐ด
getIndexDigit - ๐ด
constructCell - ๐ด
stringToH3 - ๐ด
h3ToString - ๐ด
isValidCell - ๐ด
isValidIndex - ๐ด
isResClassIII - ๐ด
isPentagon - ๐ด
getIcosahedronFaces - ๐ด
maxFaceCount
Traversal
- ๐ด
gridDistance - ๐ด
gridRing - ๐ด
gridRingUnsafe - ๐ด
maxGridRingSize - ๐ด
gridDisk - ๐ด
maxGridDiskSize - ๐ด
gridDiskDistances - ๐ด
gridDiskUnsafe - ๐ด
gridDiskDistancesUnsafe - ๐ด
gridDiskDistancesSafe - ๐ด
gridDisksUnsafe - ๐ด
gridPathCells - ๐ด
gridPathCellsSize - ๐ด
cellToLocalIj - ๐ด
localIjToCell
Hierarchy
- ๐ด
cellToParent - ๐ด
cellToChildren - ๐ด
cellToChildrenSize - ๐ด
cellToCenterChild - ๐ด
cellToChildPos - ๐ด
childPosToCell - ๐ด
compactCells - ๐ด
uncompactCells - ๐ด
uncompactCellsSize
Regions
- ๐ด
polygonToCells - ๐ด
maxPolygonToCellsSize - ๐ด
polygonToCellsExperimental - ๐ด
maxPolygonToCellsSizeExperimental - ๐ด
cellsToLinkedMultiPolygon/cellsToMultiPolygon - ๐ด
destroyLinkedMultiPolygon
Directed edges
- ๐ด
areNeighborCells - ๐ด
cellsToDirectedEdge - ๐ด
isValidDirectedEdge - ๐ด
getDirectedEdgeOrigin - ๐ด
getDirectedEdgeDestination - ๐ด
directedEdgeToCells - ๐ด
originToDirectedEdges - ๐ด
directedEdgeToBoundary - ๐ด
reverseDirectedEdge
Vertexes
- ๐ด
cellToVertex - ๐ด
cellToVertexes - ๐ด
vertexToLatLng - ๐ด
isValidVertex
Miscellaneous
- ๐ด
degsToRads - ๐ด
radsToDegs - ๐ด
getHexagonAreaAvgKm2 - ๐ด
getHexagonAreaAvgM2 - ๐ด
cellAreaRads2 - ๐ด
cellAreaKm2 - ๐ด
cellAreaM2 - ๐ด
getHexagonEdgeLengthAvgKm - ๐ด
getHexagonEdgeLengthAvgM - ๐ด
edgeLengthKm - ๐ด
edgeLengthM - ๐ด
edgeLengthRads - ๐ด
getNumCells - ๐ด
getRes0Cells - ๐ด
res0CellCount - ๐ด
getPentagons - ๐ด
pentagonCount - ๐ด
greatCircleDistanceKm - ๐ด
greatCircleDistanceM - ๐ด
greatCircleDistanceRads - ๐ด
describeH3Error
License
Apache License 2.0 - see LICENSE