Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ jobs:

strategy:
matrix:
php: [ '8.1', '8.2', '8.3' ]
h3: [ '3.7.2' ]
php: [ '8.1', '8.2', '8.3', '8.4', '8.5' ]
h3: [ '4.2.1' ]

steps:
- name: Checkout
Expand All @@ -20,6 +20,11 @@ jobs:
ref: v${{ matrix.h3 }}
path: h3-lib

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake make gcc g++

- name: Build H3 lib
working-directory: h3-lib
run: |
Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Release

on:
release:
types: [created]

jobs:
build:
strategy:
matrix:
php: [ '8.1', '8.2', '8.3', '8.4', '8.5' ]
h3: [ '4.2.1' ]
os: [ ubuntu-latest, macos-latest ]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Checkout H3 lib
uses: actions/checkout@v3
with:
repository: uber/h3
ref: v${{ matrix.h3 }}
path: h3-lib

- name: Install dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y cmake make gcc g++

- name: Install dependencies (macOS)
if: runner.os == 'macOS'
run: |
brew install cmake

- name: Build H3 lib
working-directory: h3-lib
run: |
cmake -DBUILD_SHARED_LIBS=ON .
make
sudo make install

- name: Fix shared library cache (Linux)
if: runner.os == 'Linux'
run: sudo ldconfig

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}

- name: Build extension
run: |
phpize
./configure --with-h3
make
sudo make install

- name: Run tests
run: |
export NO_INTERACTION=1
export REPORT_EXIT_STATUS=1
export TEST_PHP_EXECUTABLE=$(which php)
php run-tests.php --show-diff -d extension=h3.so ./tests/*.phpt

- name: Prepare release asset
run: |
if [ "${{ runner.os }}" = "Linux" ]; then
cp modules/h3.so "h3-php${{ matrix.php }}-linux-$(uname -m).so"
else
cp modules/h3.so "h3-php${{ matrix.php }}-macos-$(uname -m).so"
fi

- name: Upload release asset
uses: softprops/action-gh-release@v2
with:
files: h3-php${{ matrix.php }}-*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
164 changes: 82 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ PHP extension that implements [H3 library](https://github.com/uber/h3) bindings
# Requirements

* PHP: `^8.1`
* H3 Library: `^3.7.2`
* H3 Library: `^4.0`

# Examples

```php
<?php

use H3\GeoCoord;
use H3\LatLng;
use H3\H3Index;
use function H3\compact as h3_compact;
use function H3\edge_length;
Expand All @@ -23,7 +23,7 @@ $h3 = H3Index::fromLong(0x881196404bfffff);
// or
$h3 = H3Index::fromString('881196404bfffff');
// or
$h3 = H3Index::fromGeo(geo: new GeoCoord(lat: 50.00572553034654, lon: 36.229191466601634), res: 8);
$h3 = H3Index::fromGeo(geo: new LatLng(lat: 50.00572553034654, lon: 36.229191466601634), res: 8);

$resolution = $h3->getResolution(); // 8
$kRing = $h3->kRing(k: 3); // H3Index[]
Expand All @@ -42,7 +42,7 @@ $edgeLength = edge_length(res: 8, unit: H3_LENGTH_UNIT_M); // 461.3546837
```bash
git clone https://github.com/uber/h3.git
cd h3
git checkout v3.7.2
git checkout v4.2.1
cmake -DBUILD_SHARED_LIBS=ON .
make -j "$(nproc)"
sudo make install
Expand All @@ -62,94 +62,94 @@ sudo make install
# Binding table

## Indexing
| C | PHP |
|-------------------|-----------------------------|
| geoToH3() | H3\H3Index::fromGeo() |
| h3ToGeo() | H3\H3Index::toGeo() |
| h3ToGeoBoundary() | H3\H3Index::toGeoBoundary() |
| C | PHP |
|--------------------|-----------------------------|
| latLngToCell() | H3\H3Index::fromGeo() |
| cellToLatLng() | H3\H3Index::toGeo() |
| cellToBoundary() | H3\H3Index::toGeoBoundary() |

## Inspection
| C | PHP |
|-------------------|-----------------------------|
| h3GetResolution() | H3\H3Index::getResolution() |
| h3GetBaseCell() | H3\H3Index::getBaseCell() |
| stringToH3() | H3\H3Index::fromString() |
| h3ToString() | H3\H3Index::toString() |
| h3IsValid() | H3\H3Index::isValid() |
| h3IsResClassIII() | H3\H3Index::isResClassIII() |
| h3IsPentagon() | H3\H3Index::isPentagon() |
| h3GetFaces() | H3\H3Index::getFaces() |
| maxFaceCount() | - |
| C | PHP |
|----------------------|-----------------------------|
| getResolution() | H3\H3Index::getResolution() |
| getBaseCellNumber() | H3\H3Index::getBaseCell() |
| stringToH3() | H3\H3Index::fromString() |
| h3ToString() | H3\H3Index::toString() |
| isValidCell() | H3\H3Index::isValid() |
| isResClassIII() | H3\H3Index::isResClassIII() |
| isPentagon() | H3\H3Index::isPentagon() |
| getIcosahedronFaces()| H3\H3Index::getFaces() |
| maxFaceCount() | - |

## Traversal
| C | PHP |
|---------------------------|-----------------------------------------------|
| kRing() | H3\H3Index::kRing() |
| maxKringSize() | - |
| kRingDistances() | H3\H3Index::kRingDistances() |
| hexRange() | H3\H3Index::hexRange() |
| hexRangeDistances() | H3\H3Index::hexRangeDistances() |
| hexRanges() | H3\H3Index::hexRanges() |
| hexRing() | H3\H3Index::hexRing() |
| h3Line() | H3\line()<br/>H3\H3Index::getLineTo() |
| h3LineSize() | - |
| h3Distance() | H3\distance()<br/>H3\H3Index::getDistanceTo() |
| experimentalH3ToLocalIj() | H3\experimental_h3_to_local_ij |
| experimentalLocalIjToH3() | H3\experimental_local_ij_to_h3 |
| C | PHP |
|----------------------|-----------------------------------------------|
| gridDisk() | H3\H3Index::kRing() |
| maxGridDiskSize() | - |
| gridDiskDistances() | H3\H3Index::kRingDistances() |
| gridDiskUnsafe() | H3\H3Index::hexRange() |
| gridDiskDistancesUnsafe() | H3\H3Index::hexRangeDistances() |
| gridRingUnsafe() | H3\H3Index::hexRing() |
| gridPathCells() | H3\line()<br/>H3\H3Index::getLineTo() |
| gridPathCellsSize() | - |
| gridDistance() | H3\distance()<br/>H3\H3Index::getDistanceTo() |
| cellToLocalIj() | H3\experimental_h3_to_local_ij |
| localIjToCell() | H3\experimental_local_ij_to_h3 |

## Hierarchy
| C | PHP |
|-----------------------|-----------------------------|
| h3ToParent() | H3\H3Index::toParent() |
| h3ToChildren() | H3\H3Index::toChildren() |
| maxH3ToChildrenSize() | - |
| h3ToCenterChild() | H3\H3Index::toCenterChild() |
| compact() | H3\compact() |
| uncompact() | H3\uncompact() |
| maxUncompactSize() | - |
| C | PHP |
|----------------------|-----------------------------|
| cellToParent() | H3\H3Index::toParent() |
| cellToChildren() | H3\H3Index::toChildren() |
| cellToChildrenSize() | - |
| cellToCenterChild() | H3\H3Index::toCenterChild() |
| compactCells() | H3\compact() |
| uncompactCells() | H3\uncompact() |
| uncompactCellsSize() | - |

## Regions
| C | PHP |
|------------------------|------------------------------|
| polyfill() | H3\polyfill() |
| maxPolyfillSize() | - |
| h3SetToLinkedGeo() | H3\h3_set_to_multi_polygon() |
| destroyLinkedPolygon() | - |

## Unidirectional edges
| C | PHP |
|-----------------------------------------------|---------------------------------------------------------|
| h3IndexesAreNeighbors() | H3\indexes_are_neighbors<br/>H3\H3Index::isNeighborTo() |
| getH3UnidirectionalEdge() | H3\H3Index::getUnidirectionalEdge() |
| h3UnidirectionalEdgeIsValid() | H3\UniEdge::isValid() |
| getOriginH3IndexFromUnidirectionalEdge() | H3\UniEdge::getOrigin() |
| getDestinationH3IndexFromUnidirectionalEdge() | H3\UniEdge::getDestination() |
| getH3IndexesFromUnidirectionalEdge() | H3\UniEdge::getIndexes() |
| getH3UnidirectionalEdgesFromHexagon() | H3\H3Index::getUnidirectionalEdges() |
| getH3UnidirectionalEdgeBoundary() | H3\UniEdge::getBoundary() |
| C | PHP |
|------------------------------|------------------------------|
| polygonToCells() | H3\polyfill() |
| maxPolygonToCellsSize() | - |
| cellsToLinkedMultiPolygon() | H3\h3_set_to_multi_polygon() |
| destroyLinkedMultiPolygon() | - |

## Directed edges
| C | PHP |
|-------------------------------|--------------------------------------------------------------|
| areNeighborCells() | H3\indexes_are_neighbors<br/>H3\H3Index::isNeighborTo() |
| cellsToDirectedEdge() | H3\H3Index::getDirectedEdge() |
| isValidDirectedEdge() | H3\H3DirectedEdge::isValid() |
| getDirectedEdgeOrigin() | H3\H3DirectedEdge::getOrigin() |
| getDirectedEdgeDestination() | H3\H3DirectedEdge::getDestination() |
| directedEdgeToCells() | H3\H3DirectedEdge::getIndexes() |
| originToDirectedEdges() | H3\H3Index::getDirectedEdges() |
| directedEdgeToBoundary() | H3\H3DirectedEdge::getBoundary() |

## Miscellaneous
| C | PHP |
|-----------------------|---------------------------|
| degsToRads() | H3\degs_to_rads() |
| radsToDegs() | H3\rads_to_degs() |
| hexAreaKm2() | H3\hex_area() |
| hexAreaM2() | H3\hex_area() |
| cellAreaM2() | H3\H3Index::getCellArea() |
| cellAreaRads2() | H3\H3Index::getCellArea() |
| edgeLengthKm() | H3\edge_length() |
| edgeLengthM() | H3\edge_length() |
| exactEdgeLengthKm() | H3\UniEdge::getLength() |
| exactEdgeLengthM() | H3\UniEdge::getLength() |
| exactEdgeLengthRads() | H3\UniEdge::getLength() |
| numHexagons() | H3\num_hexagons() |
| getRes0Indexes() | H3\get_res0_indexes() |
| res0IndexCount() | - |
| getPentagonIndexes() | H3\get_pentagon_indexes() |
| pentagonIndexCount() | - |
| pointDistKm() | H3\point_dist() |
| pointDistM() | H3\point_dist() |
| pointDistRads() | H3\point_dist() |
| C | PHP |
|------------------------------|----------------------------------|
| degsToRads() | H3\degs_to_rads() |
| radsToDegs() | H3\rads_to_degs() |
| getHexagonAreaAvgKm2() | H3\hex_area() |
| getHexagonAreaAvgM2() | H3\hex_area() |
| cellAreaKm2() | H3\H3Index::getCellArea() |
| cellAreaM2() | H3\H3Index::getCellArea() |
| cellAreaRads2() | H3\H3Index::getCellArea() |
| getHexagonEdgeLengthAvgKm() | H3\edge_length() |
| getHexagonEdgeLengthAvgM() | H3\edge_length() |
| edgeLengthKm() | H3\H3DirectedEdge::getLength() |
| edgeLengthM() | H3\H3DirectedEdge::getLength() |
| edgeLengthRads() | H3\H3DirectedEdge::getLength() |
| getNumCells() | H3\num_hexagons() |
| getRes0Cells() | H3\get_res0_indexes() |
| res0CellCount() | - |
| getPentagons() | H3\get_pentagon_indexes() |
| pentagonCount() | - |
| greatCircleDistanceKm() | H3\point_dist() |
| greatCircleDistanceM() | H3\point_dist() |
| greatCircleDistanceRads() | H3\point_dist() |

# License

Expand Down
4 changes: 2 additions & 2 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ if test "$PHP_H3" != "no"; then
AC_MSG_ERROR([Could not find $SEARCH_FOR])
fi

PHP_ADD_INCLUDE($LIBH3_DIR/include/h3)
PHP_ADD_INCLUDE($LIBH3_DIR/include)

LIBNAME=h3
LIBSYMBOL=geoToH3
LIBSYMBOL=latLngToCell

PHP_CHECK_LIBRARY($LIBNAME, $LIBSYMBOL,
[
Expand Down
Loading