/php-h3

PHP binding for Uber's H3 spatial coordinate library. https://uber.github.io/h3

Primary LanguageC

h3 Extension for PHP

Build Status

PHP binding for Uber's H3 spatial coordinate library write by c extension for php7.

For more information on H3 and for the full API documentation, please see the H3 Documentation.

Build from sources

first install official h3 library

% git clone https://github.com/uber/h3.git
% cd h3
% cmake3 -DBUILD_SHARED_LIBS=ON .
% make -j4
% make install

before compile php h3 extension, you may need run this:

sudo cp /usr/local/lib/libh3.* /usr/local/lib64/
sudo cp /usr/local/lib/libh3.* /usr/lib/
sudo cp /usr/local/lib/libh3.* /usr/lib64/
sudo echo '/usr/local/lib64/' >> /etc/ld.so.conf
sudo echo '/usr/lib64/' >> /etc/ld.so.conf
sudo ldconfig

then compile and install h3 php binding:

% cd php-h3
% phpize
% ./configure
% make
% make install

Configration

enable h3.so extension in your php configration:

extension=h3.so

修复原版geoToH3 得到h3index 之后再h3ToGeo得到的值不一样的问题 zend_register_resource( &indexed, le_h3_index) 后在 H3Index *indexed = (H3Index ) Z_RES_VAL_P(index_resource_zval); 获得的indexed值不对 此处改为了 zend_register_resource( indexed, le_h3_index) H3Index *indexed = (H3Index *) Z_RES_VAL_P(index_resource_zval); 使用indexed 问题解决了 但原理咱不是很懂 有懂的大佬再修复修复其他的

只处理了geoToH3 h3ToLong h3GetResolution h3ToGeo kRing h3ToGeoBoundary h3GetBaseCell h3IsValid h3IsResClassIII h3IsPentagon hexRange方法

h3ToGeoBoundary中原版输出的lat lon 没有进行radsToDegs操作此处增加了

☑ TODO

Global Helpers

  • h3ToLong
  • h3FromLong

Indexing

  • geoToH3
  • h3ToGeoBoundary
  • h3ToGeo

Inspection

  • h3GetResolution
  • h3GetBaseCell
  • h3ToString
  • h3IsValid
  • h3IsResClassIII
  • h3IsPentagon

Neighbors

  • kRing
  • maxKringSize
  • kRingDistances
  • hexRange
  • hexRangeDistances
  • hexRanges
  • hexRing

Distance

  • h3Distance

Hierarchy

  • h3ToParent
  • h3ToChildren
  • maxH3ToChildrenSize
  • compact
  • uncompact
  • maxUncompactSize

Regions

  • polyfill
  • maxPolyfillSize
  • h3SetToLinkedGeo
  • destroyLinkedPolygon

Unidirectional Edges

  • h3IndexesAreNeighbors
  • getH3UnidirectionalEdge
  • h3UnidirectionalEdgeIsValid
  • getOriginH3IndexFromUnidirectionalEdge
  • getDestinationH3IndexFromUnidirectionalEdge
  • getH3IndexesFromUnidirectionalEdge
  • getH3UnidirectionalEdgesFromHexagon
  • getH3UnidirectionalEdgeBoundary

Miscellaneous

  • degsToRads
  • radsToDegs
  • hexAreaKm2
  • hexAreaM2
  • edgeLengthKm
  • edgeLengthM
  • numHexagons

Examples

$index = geoToH3(40.689167, -74.044444, 10);

var_dump($index);

var_dump(h3ToGeo($index));

var_dump(h3ToGeoBoundary($index));

var_dump(h3GetResolution($index));

var_dump(h3GetBaseCell($index));

var_dump(h3ToString($index, "hello world"));

var_dump(h3IsValid($index));

var_dump(h3IsResClassIII($index));

var_dump(h3IsPentagon($index));

var_dump(kRing($index, 5));

var_dump(maxKringSize(5));

var_dump(kRingDistances($index, 5));

var_dump(hexRange($index, 5));

var_dump(hexRangeDistances($index, 5));

$index1 = geoToH3(341.689167, -173.044444, 10);

var_dump(hexRanges([$index, $index1], 5));

var_dump(hexRing($index, 5));

var_dump(h3Distance($index, $index1));

var_dump(h3ToParent($index, 5));

var_dump(h3ToChildren($index, 2));

var_dump(maxH3ToChildrenSize($index, 2));

var_dump($rads = degsToRads(40.689167));

var_dump(radsToDegs($rads));

var_dump(hexAreaKm2(10));

var_dump(hexAreaM2(10));

var_dump(edgeLengthKm(10));

var_dump(edgeLengthM(10));

var_dump(numHexagons(2));


var_dump(h3IndexesAreNeighbors($index, $index1));
var_dump(getH3UnidirectionalEdge($index, $index1));
var_dump(h3UnidirectionalEdgeIsValid($index));
var_dump(getOriginH3IndexFromUnidirectionalEdge($index));
var_dump(getDestinationH3IndexFromUnidirectionalEdge($index));
var_dump(getH3IndexesFromUnidirectionalEdge($index));
var_dump(getH3UnidirectionalEdgesFromHexagon($index));
var_dump(getH3UnidirectionalEdgeBoundary($index));

var_dump($compacts = h3Compact([$index, $index1]));
var_dump(uncompact($compacts, 2));
var_dump(maxUncompactSize($compacts, 2));