Usage
Vgridpandas key features¶
Vgridpandas supports popular geodesic DGGS such as H3, S2, A5, rHEALPix, Open-Eaggr ISEA4T, EASE-DGGS, 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:
Install vgridpandas¶
In [1]:
Copied!
# %pip install vgridpandas
# %pip install vgridpandas
Latlong to DGGS¶
In [ ]:
Copied!
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()
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()
Out[ ]:
lat | lon | h3_res | |
---|---|---|---|
h3 | |||
8059fffffffffff | 14.665729 | 14 | 0 |
8071fffffffffff | -187.508806 | 15 | 0 |
DGGS to geo boundary¶
In [3]:
Copied!
df = df.h3.h32geo()
df
df = df.h3.h32geo()
df
Out[3]:
lat | lon | h3_res | geometry | |
---|---|---|---|---|
h3 | ||||
8059fffffffffff | 14.665729 | 14 | 0 | POLYGON ((-2.48387 22.19754, -4.014 11.5453, 3... |
8071fffffffffff | -187.508806 | 15 | 0 | POLYGON ((-175.45827 15.28573, -180.78284 5.88... |
(Multi)Linestring/ (Multi)Polygon to DGGS¶
In [6]:
Copied!
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, predicate = "largest_overlap", explode = False)
gdf_polyfill = gdf_polyfill.s2.s22geo(s2_column = "s2")
gdf_polyfill.plot(edgecolor = "white")
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, predicate = "largest_overlap", explode = False)
gdf_polyfill = gdf_polyfill.s2.s22geo(s2_column = "s2")
gdf_polyfill.plot(edgecolor = "white")
Out[6]:
<Axes: >
DGGS point binning¶
In [17]:
Copied!
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)
)
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)
)
Out[17]:
<Axes: >