Integration of H3 and GeoPandas
Project description
H3-Pandas ⬢ 🐼
Integrates H3 with GeoPandas and Pandas.
⬢ Try it out ⬢
Installation
pip
pip install h3pandas
conda
TODO
Usage examples
# Prepare data
>>> import pandas
>>> 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 ((...)) |
Aggregate functions
h3pandas
also provides common aggregations in a simple API.
# 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 |
|:----------------|--------:|
| 831e30fffffffff | 102 |
| 831e34fffffffff | 189 |
| 831e35fffffffff | 8744 |
| 831f1bfffffffff | 1040 |
# Aggregate to a lower H3 resolution
>>> df.h3.h3_to_parent_aggregate(2)
| h3_02 | value |
|:----------------|--------:|
| 821e37fffffffff | 9035 |
| 821f1ffffffffff | 1040 |
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
- Allow for alternate h3-py APIs such as memview_int
- Performance improvements through Cythonized h3-py
- Dask integration trough dask-geopandas (experimental as of now)
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
h3pandas-0.1.0a2.tar.gz
(7.0 kB
view details)
File details
Details for the file h3pandas-0.1.0a2.tar.gz
.
File metadata
- Download URL: h3pandas-0.1.0a2.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90e17aba5e7cf01e43b0cfdd48f118df8bf89b92d86ee33d364c5fecac6e9040 |
|
MD5 | de355e9a0e8e623d3b40d05445926ea5 |
|
BLAKE2b-256 | bd5dcf0f97efa57777d70b48014cbf3065f85778c323a0665d1d9e3754ff1cf6 |