01 h3
H3Pandas key features¶
You can try out vgridpandas by using the cloud-computing platforms below without having to install anything on your computer:
Install vgridpandas¶
In [1]:
Copied!
# %pip install vgridpandas
# %pip install vgridpandas
Latlong to H3¶
In [12]:
Copied!
import pandas as pd
from vgridpandas import h3pandas
df = pd.read_csv('https://github.com/uber-web/kepler.gl-data/raw/master/nyctrips/data.csv')
df = df.rename({'pickup_longitude': 'lon', 'pickup_latitude': 'lat'}, axis=1)[['lon', 'lat', 'passenger_count']]
df = df.head(100)
resolution = 8
df = df.h3.latlon2h3(resolution)
df.head()
import pandas as pd
from vgridpandas import h3pandas
df = pd.read_csv('https://github.com/uber-web/kepler.gl-data/raw/master/nyctrips/data.csv')
df = df.rename({'pickup_longitude': 'lon', 'pickup_latitude': 'lat'}, axis=1)[['lon', 'lat', 'passenger_count']]
df = df.head(100)
resolution = 8
df = df.h3.latlon2h3(resolution)
df.head()
Out[12]:
lon | lat | passenger_count | h3_res | |
---|---|---|---|---|
h3 | ||||
882a100d2dfffff | -73.993896 | 40.750111 | 1 | 8 |
882a100d2bfffff | -73.976425 | 40.739811 | 1 | 8 |
882a100d63fffff | -73.968704 | 40.754246 | 5 | 8 |
882a100e25fffff | -73.863060 | 40.769581 | 5 | 8 |
882a10089bfffff | -73.945541 | 40.779423 | 1 | 8 |
H3 to geo boundary¶
In [13]:
Copied!
df = df.h3.h32geo()
df.head()
df = df.h3.h32geo()
df.head()
Out[13]:
lon | lat | passenger_count | h3_res | geometry | |
---|---|---|---|---|---|
h3 | |||||
882a100d2dfffff | -73.993896 | 40.750111 | 1 | 8 | POLYGON ((-73.98804 40.75427, -73.99442 40.753... |
882a100d2bfffff | -73.976425 | 40.739811 | 1 | 8 | POLYGON ((-73.9748 40.74405, -73.98118 40.743,... |
882a100d63fffff | -73.968704 | 40.754246 | 5 | 8 | POLYGON ((-73.9689 40.75743, -73.97528 40.7563... |
882a100e25fffff | -73.863060 | 40.769581 | 5 | 8 | POLYGON ((-73.86237 40.77082, -73.86875 40.769... |
882a10089bfffff | -73.945541 | 40.779423 | 1 | 8 | POLYGON ((-73.94629 40.78183, -73.95267 40.780... |
(Multi)Linestring/ (Multi)Polygon to H3¶
In [18]:
Copied!
from vgridpandas import h3pandas
import geopandas as gpd
from shapely.geometry import box, Polygon
gdf = gpd.GeoDataFrame(geometry=[box(0, 0, 1, 1)])
gdf_polyfill = gdf.h3.polyfill(4, explode = True)
gdf_polyfill.head()
from vgridpandas import h3pandas
import geopandas as gpd
from shapely.geometry import box, Polygon
gdf = gpd.GeoDataFrame(geometry=[box(0, 0, 1, 1)])
gdf_polyfill = gdf.h3.polyfill(4, explode = True)
gdf_polyfill.head()
Out[18]:
geometry | h3 | |
---|---|---|
0 | POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0)) | 8475413ffffffff |
0 | POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0)) | 84754c5ffffffff |
0 | POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0)) | 84754ebffffffff |
0 | POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0)) | 84754e9ffffffff |
0 | POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0)) | 84754edffffffff |
H3 point binning¶
In [11]:
Copied!
import pandas as pd
from vgridpandas import h3pandas
df = pd.read_csv('https://raw.githubusercontent.com/opengeoshub/vopendata/refs/heads/main/csv/dist1_pois.csv')
df.head()
resolution = 10
df = df.h3.geo2h3_aggregate(resolution, return_geometry=True)
df.head()
import pandas as pd
from vgridpandas import h3pandas
df = pd.read_csv('https://raw.githubusercontent.com/opengeoshub/vopendata/refs/heads/main/csv/dist1_pois.csv')
df.head()
resolution = 10
df = df.h3.geo2h3_aggregate(resolution, return_geometry=True)
df.head()
Out[11]:
fid | id | name | category | confidence | h3_res | geometry | |
---|---|---|---|---|---|---|---|
h3 | |||||||
8a65b5644127fff | 1 | 1 | 1 | 1 | 1 | 1 | POLYGON ((106.69194 10.7956, 106.69202 10.7963... |
8a65b564414ffff | 12 | 12 | 12 | 12 | 12 | 12 | POLYGON ((106.68684 10.79616, 106.68692 10.796... |
8a65b5644167fff | 3 | 3 | 3 | 3 | 3 | 3 | POLYGON ((106.68863 10.79485, 106.68871 10.795... |
8a65b564416ffff | 7 | 7 | 7 | 7 | 7 | 7 | POLYGON ((106.68736 10.79499, 106.68743 10.795... |
8a65b5644807fff | 76 | 76 | 76 | 76 | 76 | 76 | POLYGON ((106.69274 10.79105, 106.69282 10.791... |