Search by

ligorikus / h3-php

ligorikus

Pure PHP implementation of H3 geospatial indexing system

Package info

github.com/ligorikus/h3-php

pkg:composer/ligorikus/h3-php

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 5

Open Issues: 1

0.1.0 2026-10-02 20:42 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.

Indexing

Official documentation

  • ๐ŸŸข latLngToCell
  • ๐ŸŸข cellToLatLng
  • ๐Ÿ”ด cellToBoundary
Inspection

Official documentation

  • ๐Ÿ”ด getResolution
  • ๐Ÿ”ด getBaseCellNumber
  • ๐Ÿ”ด getIndexDigit
  • ๐Ÿ”ด constructCell
  • ๐Ÿ”ด stringToH3
  • ๐Ÿ”ด h3ToString
  • ๐Ÿ”ด isValidCell
  • ๐Ÿ”ด isValidIndex
  • ๐Ÿ”ด isResClassIII
  • ๐Ÿ”ด isPentagon
  • ๐Ÿ”ด getIcosahedronFaces
  • ๐Ÿ”ด maxFaceCount
Traversal

Official documentation

  • ๐Ÿ”ด gridDistance
  • ๐Ÿ”ด gridRing
  • ๐Ÿ”ด gridRingUnsafe
  • ๐Ÿ”ด maxGridRingSize
  • ๐Ÿ”ด gridDisk
  • ๐Ÿ”ด maxGridDiskSize
  • ๐Ÿ”ด gridDiskDistances
  • ๐Ÿ”ด gridDiskUnsafe
  • ๐Ÿ”ด gridDiskDistancesUnsafe
  • ๐Ÿ”ด gridDiskDistancesSafe
  • ๐Ÿ”ด gridDisksUnsafe
  • ๐Ÿ”ด gridPathCells
  • ๐Ÿ”ด gridPathCellsSize
  • ๐Ÿ”ด cellToLocalIj
  • ๐Ÿ”ด localIjToCell
Hierarchy

Official documentation

  • ๐Ÿ”ด cellToParent
  • ๐Ÿ”ด cellToChildren
  • ๐Ÿ”ด cellToChildrenSize
  • ๐Ÿ”ด cellToCenterChild
  • ๐Ÿ”ด cellToChildPos
  • ๐Ÿ”ด childPosToCell
  • ๐Ÿ”ด compactCells
  • ๐Ÿ”ด uncompactCells
  • ๐Ÿ”ด uncompactCellsSize
Regions

Official documentation

  • ๐Ÿ”ด polygonToCells
  • ๐Ÿ”ด maxPolygonToCellsSize
  • ๐Ÿ”ด polygonToCellsExperimental
  • ๐Ÿ”ด maxPolygonToCellsSizeExperimental
  • ๐Ÿ”ด cellsToLinkedMultiPolygon / cellsToMultiPolygon
  • ๐Ÿ”ด destroyLinkedMultiPolygon
Directed edges

Official documentation

  • ๐Ÿ”ด areNeighborCells
  • ๐Ÿ”ด cellsToDirectedEdge
  • ๐Ÿ”ด isValidDirectedEdge
  • ๐Ÿ”ด getDirectedEdgeOrigin
  • ๐Ÿ”ด getDirectedEdgeDestination
  • ๐Ÿ”ด directedEdgeToCells
  • ๐Ÿ”ด originToDirectedEdges
  • ๐Ÿ”ด directedEdgeToBoundary
  • ๐Ÿ”ด reverseDirectedEdge
Vertexes

Official documentation

  • ๐Ÿ”ด cellToVertex
  • ๐Ÿ”ด cellToVertexes
  • ๐Ÿ”ด vertexToLatLng
  • ๐Ÿ”ด isValidVertex
Miscellaneous

Official documentation

  • ๐Ÿ”ด 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