Hierarchical hexagonal geospatial indexing system
Project description
h3-py
Python bindings for the H3 Core Library.
For API reference, see the H3 Documentation.
Installation
From PyPI:
pip install h3
From conda:
conda config --add channels conda-forge
conda install h3-py
New since v3.6.1: We upload pre-built Python Wheels to PyPI for Linux/Mac/Windows, which should avoid many previous installation issues.
Usage
>>> import h3
>>> lat, lng = 0, 0
>>> resolution = 0
>>> h3.geo_to_h3(lat, lng, resolution)
'8075fffffffffff'
Example gallery
Browse a collection of example notebooks, and if you have examples or visualizations of your own, please feel free to contribute!
We also have a simple walkthrough of the API. For more information, please see the H3 Documentation.
APIs
We provide multiple APIs in h3-py
.
All APIs have the same set of functions, but differ
in their input/output formats.
h3.api.basic_str
H3 indexes are represented as Python str
s, using list
and set
for collections.
This is the default API provided when you import h3
.
That is, import h3.api.basic_str as h3
and import h3
are basically equivalent.
>>> import h3
>>> h = h3.geo_to_h3(0, 0, 0)
>>> h
'8075fffffffffff'
>>> h3.hex_ring(h, 1)
{'8055fffffffffff',
'8059fffffffffff',
'807dfffffffffff',
'8083fffffffffff',
'8099fffffffffff'}
h3.api.basic_int
H3 indexes are represented as Python int
s, using list
and set
for collections.
>>> import h3.api.basic_int as h3
>>> h = h3.geo_to_h3(0, 0, 0)
>>> h
578536630256664575
>>> h3.hex_ring(h, 1)
{577973680303243263,
578044049047420927,
578677367745019903,
578782920861286399,
579169948954263551}
h3.api.numpy_int
H3 indexes are represented as uint64
s, using numpy.ndarray
for collections.
The intention is for this API to be faster and more memory-efficient by
not requiring int
to str
conversion and by using
no-copy numpy
arrays instead of Python list
s and set
s.
>>> import h3.api.numpy_int as h3
>>> h = h3.geo_to_h3(0, 0, 0)
>>> h
578536630256664575
>>> h3.hex_ring(h, 1)
array([578782920861286399, 578044049047420927, 577973680303243263,
578677367745019903, 579169948954263551], dtype=uint64)
Note that h3
has no runtime dependencies on other libraries, so a standard
pip install
will install no additional libraries.
However, h3.api.numpy_int
requires numpy
. To have numpy
installed (if it isn't already) along
with h3
, run pip install h3[numpy]
.
h3.api.memview_int
H3 indexes are represented as uint64
s, using Python
memoryview
objects
for collections.
This API has the same benefits as numpy_int
, except it uses
(the less well-known but dependency-free) memoryview
.
>>> import h3.api.memview_int as h3
>>> h = h3.geo_to_h3(0, 0, 0)
>>> h
578536630256664575
>>> mv = h3.hex_ring(h, 1)
>>> mv
<MemoryView of 'array' at 0x11188c710>
>>> mv[0]
578782920861286399
>>> list(mv)
[578782920861286399,
578044049047420927,
577973680303243263,
578677367745019903,
579169948954263551]
When using this API with numpy
, note that numpy.array
creates a copy
of the data, while numpy.asarray
does not create a copy and the
result points to the same memory location as the memoryview
object.
Continuing from the example above,
>>> mv = h3.hex_ring(h, 1)
>>> a = np.array(mv)
>>> mv[0] = 0
>>> a
array([578782920861286399, 578044049047420927, 577973680303243263,
578677367745019903, 579169948954263551], dtype=uint64)
>>> mv = h3.hex_ring(h, 1)
>>> a = np.asarray(mv)
>>> mv[0] = 0
>>> a
array([ 0, 578044049047420927, 577973680303243263,
578677367745019903, 579169948954263551], dtype=uint64)
Versioning
h3-py
wraps the H3 Core Library,
which is written in C.
Both projects employ semantic versioning,
with versions taking the form X.Y.Z
.
h3-py
will match the C library
in major and minor numbers (X.Y
), but may be different on the
patch (Z
) number.
Use h3.versions()
to see the version numbers for both
h3-py
and the C library. For example,
>>> import h3
>>> h3.versions()
{'c': '3.6.3', 'python': '3.6.1'}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for h3-3.7.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9617221472d1ea856b388dcd2916e6745169235945a55d970a35a8a0866bf40 |
|
MD5 | ab430fc95bce53d405ae65ebce5cd0bc |
|
BLAKE2b-256 | e61440008d9a9342178d0011cef863c6c8943d094c6a9de11a870e47fc4fe0d6 |
Hashes for h3-3.7.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a09d85c98230509556f9715613271ae1a4bcfbf3c99ad1e9702638edaaaa8f0 |
|
MD5 | 03c0da821e0f002b9cbdcd3a6882b88c |
|
BLAKE2b-256 | 84e04610f980cf797f894de9895751321d3c1ab036af2c4c32b7c7155258d9ac |
Hashes for h3-3.7.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | afb87102dfd3d6b4b89ccb96eae9be98658c4256658e093c5623daa2e161dbef |
|
MD5 | b1a087c7c2f818c1ab426eecc304fd69 |
|
BLAKE2b-256 | f99b45e2f74423fb8a035acc33dd3f8ddd2f56750539142a1cc647fe8f8b2c6d |
Hashes for h3-3.7.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0eebbf4600446ad78c0416482cd6cd3d86383387adbbe3ce30a88418df4496a4 |
|
MD5 | c3e794c25857fe340c9048e21f3cca60 |
|
BLAKE2b-256 | 77e93638a4c9c59eb960d166ef98c9bdb579ee46c1fef5ad3cb1c319b95554fd |
Hashes for h3-3.7.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac6ec8dfb3bd67e32b9b3707ed72b30149dcc3cddb6ce18cb12312b94b57e155 |
|
MD5 | 9abd04eac88b5c82342fd0edc2564691 |
|
BLAKE2b-256 | a9e6047d0bbd663bb7cba53c82ff9339c75e2bd5ebb262bda6d6cdebb6535fcc |
Hashes for h3-3.7.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 905dc33286ffdab67cf9df9b04b33be2c3c9b6a5fa3166f789d760d775a4677d |
|
MD5 | 518724162b17fb3b36913c05e662852e |
|
BLAKE2b-256 | 4903c66bbf4c14bb11d1019f1c32e178f62b1523621f680eea543c287b300ed6 |
Hashes for h3-3.7.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b92b0d4a6c77513e792d75fa1e2e895f873eec11b16eb9b9f46b1174f21ada95 |
|
MD5 | c3d5de664a000356dc9d164b49ed7a3d |
|
BLAKE2b-256 | 746cf23a24064f2c0ffbef234c0c1d7f7655c4317d749d27bea1074d963554b0 |
Hashes for h3-3.7.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 683fafdbf32d10862e874b939c818a4f11c67e4a48afc26cafc43854a97a0254 |
|
MD5 | dd3837950e2ef77f3ca0eaf3e8e64a6a |
|
BLAKE2b-256 | c04ab9d05d8df8f186e8f98c7c09b9b673ea0ca211657fe1ef32ec78cb69f179 |
Hashes for h3-3.7.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbd3a37a54a72c19504dc0c39f1d5aa8338ee774ede9e9a8e8045a88e94dc857 |
|
MD5 | 7ab9b0274c2e623c454f3d64906921f8 |
|
BLAKE2b-256 | 11ba26f899d93aa55cb058e16a13bce9e79c00b6640060495078a1fba3e770dc |
Hashes for h3-3.7.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 155b4b4ceb22f24b48e88c596860123ec1aa60e2b62994ea2b557ba553a90435 |
|
MD5 | d159da86d06fc09b797f8f14a4b0a821 |
|
BLAKE2b-256 | 629b426e47f1a569dd37a6b6026b61a7926557d5c3222da28bcc991618a66a17 |
Hashes for h3-3.7.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aeee8247c312d671d5d3d77f277b6a6f70db9077a9194ca5ab7c597e50188cc6 |
|
MD5 | 70c32131ea1c5f7ed65b92380170e2c0 |
|
BLAKE2b-256 | 44726735f854a5c3293fbde34b4328a9fc87cd13c6569c658bce31aff4247ddd |
Hashes for h3-3.7.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 119b1b1dae60177195d5804c1058a3eeaf1f954dbeaa4920100347994a99f2d5 |
|
MD5 | 060778cc51363533045989fd69c85839 |
|
BLAKE2b-256 | db7e9874bba767027f8e02aca48e760ad818c7b74cafe68af7ffac1af46cc124 |
Hashes for h3-3.7.0-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 317c5a3101c61e9260c47364fee2552e75ff0c0a44b0be59393ff48f7cdb129c |
|
MD5 | f9263e5f3a9a4fb8126169ca0c3c0d65 |
|
BLAKE2b-256 | 38b71aec3f2c6e90d5101ef7a5cacc60151ccab4f37495d3c2df09b728cbec25 |
Hashes for h3-3.7.0-cp35-cp35m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08bd10c2f099f436fa2034c7364a445f5aa58f2926deb524f94562a6b8e91ffe |
|
MD5 | 0084c3cf02e403fc558a125203759cfb |
|
BLAKE2b-256 | 8c23171104ca51824d44735defd77647eb77857cab6f3e7ef30bad4ac68405ea |
Hashes for h3-3.7.0-cp27-cp27mu-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73bf98eaf127200825b1f258b36cfba9e275b70866b8438c94eb145848c57e6b |
|
MD5 | a8b54673c9633f1ef51938cb469f1554 |
|
BLAKE2b-256 | 885c949bb984877169134e139584523870bee5d1843f53cbb76038e07768e7d3 |
Hashes for h3-3.7.0-cp27-cp27m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5cbdfccf12d6f2ccdd5589ce0e5b953cb90a35c1070ac813d09a0dd7220b758 |
|
MD5 | b559c4dfb9cf906fa9cbdc598a47ed29 |
|
BLAKE2b-256 | 8681d23b23be258df749b50334a426536567f4d0147e5a223748536f12827cc6 |
Hashes for h3-3.7.0-cp27-cp27m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 920e977ca51319c857998c88481d137297b5ec078672a82cb5a6dafcda44fcda |
|
MD5 | abb5ef51adfce1686636fd7b03161e94 |
|
BLAKE2b-256 | 8459b13e9cbfbb9aab6f3a8aea89ebf59402c857b781dc84ae59abe204d324c3 |