GithubHelp home page GithubHelp logo

richardscottoz / h3-pandas Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dahnj/h3-pandas

0.0 0.0 0.0 7.75 MB

Integration of H3 with GeoPandas and Pandas

Home Page: http://h3-pandas.readthedocs.io/

License: MIT License

Python 2.93% Shell 0.02% Jupyter Notebook 97.05%

h3-pandas's Introduction

H3 Logo

 

H3-Pandas ⬢ 🐼

Integrates H3 with GeoPandas and Pandas.

image Binder image image Anaconda-Server Badge image Documentation Status

 


Try it out


example usage

Installation

pip

pip install h3pandas

conda

conda install -c conda-forge h3pandas

Usage examples

H3 API

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

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

Further examples

For more examples, see the example notebooks.

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

h3-pandas's People

Contributors

dahnj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.