Usage
Vgridpandas key features¶
Vgridpandas supports popular geodesic DGGS such as H3, S2, A5, rHEALPix, Open-Eaggr ISEA4T, EASE-DGGS, DGGAL, DGGRID, QTM, and graticule DGGS such as OLC, Geohash, MGRS, GEOREF, Tilecode, Quadkey, Maidenhead, GARS
You can try out vgridpandas by using the cloud-computing platforms below without having to install anything on your computer:
Full VgridPandas DGGS documentation is available at vgridpandas document.
To work with Vgrid in Python or CLI, use vgrid package. Full Vgrid DGGS documentation is available at vgrid document.
To work with Vgrid DGGS in QGIS, install the Vgrid Plugin.
To visualize DGGS in Maplibre GL JS, try the vgrid-maplibre library.
For an interactive demo, visit the Vgrid Homepage.
Install vgridpandas¶
Uncomment the following line to install vgridpandas.
# %pip install vgridpandas
Latlon to DGGS¶
import pandas as pd
from vgridpandas import h3pandas
df = pd.DataFrame({'lat': [14.6657293, -187.5088058], 'lon': [14, 15]})
resolution = 0
df = df.h3.latlon2h3(resolution)
df.head()
| lat | lon | h3 | h3_res | |
|---|---|---|---|---|
| 0 | 14.665729 | 14 | 8059fffffffffff | 0 |
| 1 | -187.508806 | 15 | 8071fffffffffff | 0 |
DGGS to geo boundary¶
df = df.h3.h32geo()
df
| lat | lon | h3 | h3_res | geometry | |
|---|---|---|---|---|---|
| 0 | 14.665729 | 14 | 8059fffffffffff | 0 | POLYGON ((-2.48387 22.19754, -4.014 11.5453, 3... |
| 1 | -187.508806 | 15 | 8071fffffffffff | 0 | POLYGON ((-175.45827 15.28573, -180.78284 5.88... |
(Multi)Linestring/ (Multi)Polygon to DGGS¶
from shapely.geometry import box
from vgridpandas import s2pandas
import geopandas as gpd
gdf = gpd.read_file('https://raw.githubusercontent.com/opengeoshub/vopendata/refs/heads/main/shape/polygon.geojson')
resolution = 17
gdf_polyfill = gdf.s2.polyfill(resolution, compact = True, predicate = "intersects", explode = False)
gdf_polyfill = gdf_polyfill.s2.s22geo(s2_column = "s2")
gdf_polyfill.plot(edgecolor = "white")
<Axes: >
DGGS point binning¶
import pandas as pd
from vgridpandas import rhealpixpandas
resolution = 10
df = pd.read_csv("https://raw.githubusercontent.com/opengeoshub/vopendata/refs/heads/main/csv/dist1_pois.csv")
# df = gpd.read_file("https://raw.githubusercontent.com/opengeoshub/vopendata/refs/heads/main/shape/dist1_pois.geojson")
stats = "count"
df_bin = df.rhealpix.rhealpixbin(resolution=resolution, stats = stats,
# numeric_column="confidence",
# category_column="category",
return_geometry=True)
df_bin.plot(
column=stats, # numeric column to base the colors on
cmap='Spectral_r', # color scheme (matplotlib colormap)
legend=True,
linewidth=0.2 # boundary width (optional)
)
<Axes: >