Skip to main content

Integration of H3 and GeoPandas

Project description

H3 Logo

 

H3-Pandas ⬢ 🐼

Integrates H3 with GeoPandas and Pandas.

image Binder image image Anaconda-Server Badge image

 


Try it out


example usage

Installation

pip

pip install h3pandas

conda

conda config --add channels conda-forge  # Most dependencies are on conda-forge
conda install -c dahn h3pandas

Usage examples

# Prepare data
>>> import pandas as pd
>>> import h3pandas
>>> df = pd.DataFrame({'lat': [50, 51], 'lng': [14, 15]})

H3 API

h3pandas automatically applies H3 functions to both Pandas Dataframes and GeoPandas Geodataframes

>>> resolution = 10
>>> df = df.h3.geo_to_h3(resolution)
>>> df

| h3_10           |   lat |   lng |
|:----------------|------:|------:|
| 8a1e30973807fff |    50 |    14 |
| 8a1e2659c2c7fff |    51 |    15 |

>>> df = df.h3.h3_to_geo_boundary()
>>> df

| h3_10           |   lat |   lng | geometry        |
|:----------------|------:|------:|:----------------|
| 8a1e30973807fff |    50 |    14 | POLYGON ((...)) |
| 8a1e2659c2c7fff |    51 |    15 | POLYGON ((...)) |

H3-Pandas Extended API

h3pandas also provides some extended functionality out-of-the-box, often simplifying common workflows into a single command.

# Set up data
>>> import numpy as np
>>> import pandas as pd
>>> np.random.seed(1729)
>>> df = pd.DataFrame({
>>>   'lat': np.random.uniform(50, 51, 100),
>>>   'lng': np.random.uniform(14, 15, 100),
>>>   'value': np.random.poisson(100, 100)})
>>> })
# Aggregate values by their location and sum
>>> df = df.h3.geo_to_h3_aggregate(3)
>>> df

| h3_03           |   value | geometry        |
|:----------------|--------:|:----------------|
| 831e30fffffffff |     102 | POLYGON ((...)) |
| 831e34fffffffff |     189 | POLYGON ((...)) |
| 831e35fffffffff |    8744 | POLYGON ((...)) |
| 831f1bfffffffff |    1040 | POLYGON ((...)) |

# Aggregate to a lower H3 resolution
>>> df.h3.h3_to_parent_aggregate(2)

| h3_02           |   value | geometry        |
|:----------------|--------:|:----------------|
| 821e37fffffffff |    9035 | POLYGON ((...)) |
| 821f1ffffffffff |    1040 | POLYGON ((...)) |

API

For a full API documentation and more usage examples, see the documentation.

Development

This package is under active development, suggestions and contributions are very welcome!

In particular, the next steps are:

  • Improve documentation, examples
  • Greater coverage of the H3 API

Additional possible directions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

h3pandas-0.2.0.tar.gz (65.8 kB view details)

Uploaded Source

File details

Details for the file h3pandas-0.2.0.tar.gz.

File metadata

  • Download URL: h3pandas-0.2.0.tar.gz
  • Upload date:
  • Size: 65.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for h3pandas-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c40b84567ccd513ee4f358659429a9c70c1b74f9692fa8b2c27a5b44d1c4684c
MD5 dbb5a33c482651c9379c895a08405349
BLAKE2b-256 f2a0f703a2cb80c1dce7805a8ec94c105c4939f4ead2b80b0e608be3902166de

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page