h3

Prerequisites:

H3-py

Source

Installation avec pip (Recommandé)

A partir de Python 3.5

$ pip install h3

Utilisation dans un script python

from h3 import h3

Conversion depuis latitude / longitude

h3_address = h3.geo_to_h3( 47.3615593, -3.0553238, 5 ) # lat, lng, hex resolution

hex_center_coordinates = h3.h3_to_geo( h3_address ) # array of [lat, lng]

hex_boundary = h3.h3_to_geo_boundary( h3_address ) # array of arrays of [lat, lng]

Voisins

h3.k_ring_distances( h3_address, 4 ) # array of 4 rings with size [1, 6, 12, 18]
h3.k_ring( h3_address, 4 ) # a collection of hexagons within kring sizes from 0 to 3

Polygone

geoJson = {'type': 'Polygon',
 'coordinates': [[
  [47.813318999983238, -3.4089866999972145],
  [ 47.7866302000007224, -3.3805436999997056 ],
  [47.7198061999978478, -3.3544736999993603],
  [ 47.7076131999975672, -3.5123436999983966 ],
  [47.7835871999971715, -3.5247187000021967],
  [47.8151571999998453, -3.4798767000009008]]] }
hexagons = list(h3.polyfill(geoJson, 8)) # resolution 8

OSX Erreur script

Sur OSX, erreur lors de l’installation https://github.com/uber/h3-py/issues/5

which make
which cc
which cmake

Si pas de path pour cmake,

echo $PATH

Si /usr/local/bin n’est pas présent, le rajouter par la commande suivante

export PATH="/usr/local/bin:$PATH"

ou il faut installer cmake.

brew install cmake

Installation depuit Github

git clone https://github.com/uber/h3-py.git
cd h3-py
./install.sh