08 dggal
DGGALPandas key features¶
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.
In [1]:
Copied!
# %pip install vgridpandas
# %pip install vgridpandas
Latlon to DGGAL¶
In [2]:
Copied!
import pandas as pd
from vgridpandas import dggalpandas
df = pd.read_csv('https://github.com/uber-web/kepler.gl-data/raw/master/nyctrips/data.csv')
df = df.head(100)
df = df.rename({'pickup_longitude': 'lon', 'pickup_latitude': 'lat'}, axis=1)[['lon', 'lat', 'passenger_count']]
resolution = 6
dggs_type = "isea9r" # choose one from ['gnosis','isea3h','isea9r','ivea3h',
# 'ivea9r','rtea3h','rtea9r','rhealpix']
df = df.dggal.latlon2dggal(dggs_type, resolution,set_index=False)
df.head()
import pandas as pd
from vgridpandas import dggalpandas
df = pd.read_csv('https://github.com/uber-web/kepler.gl-data/raw/master/nyctrips/data.csv')
df = df.head(100)
df = df.rename({'pickup_longitude': 'lon', 'pickup_latitude': 'lat'}, axis=1)[['lon', 'lat', 'passenger_count']]
resolution = 6
dggs_type = "isea9r" # choose one from ['gnosis','isea3h','isea9r','ivea3h',
# 'ivea9r','rtea3h','rtea9r','rhealpix']
df = df.dggal.latlon2dggal(dggs_type, resolution,set_index=False)
df.head()
Out[2]:
| lon | lat | passenger_count | dggal_isea9r | dggal_isea9r_res | |
|---|---|---|---|---|---|
| 0 | -73.993896 | 40.750111 | 1 | G0-6BABB | 6 |
| 1 | -73.976425 | 40.739811 | 1 | G0-6BABB | 6 |
| 2 | -73.968704 | 40.754246 | 5 | G0-6BABB | 6 |
| 3 | -73.863060 | 40.769581 | 5 | G0-6BABC | 6 |
| 4 | -73.945541 | 40.779423 | 1 | G0-6BABB | 6 |
DGGAL to geo boundary¶
In [3]:
Copied!
df = df.dggal.dggal2geo(dggs_type)
df.head()
df = df.dggal.dggal2geo(dggs_type)
df.head()
Out[3]:
| lon | lat | passenger_count | dggal_isea9r | dggal_isea9r_res | geometry | |
|---|---|---|---|---|---|---|
| 0 | -73.993896 | 40.750111 | 1 | G0-6BABB | 6 | POLYGON ((-74.01084 40.80323, -74.0132 40.8010... |
| 1 | -73.976425 | 40.739811 | 1 | G0-6BABB | 6 | POLYGON ((-74.01084 40.80323, -74.0132 40.8010... |
| 2 | -73.968704 | 40.754246 | 5 | G0-6BABB | 6 | POLYGON ((-74.01084 40.80323, -74.0132 40.8010... |
| 3 | -73.863060 | 40.769581 | 5 | G0-6BABC | 6 | POLYGON ((-73.88184 40.77904, -73.88421 40.776... |
| 4 | -73.945541 | 40.779423 | 1 | G0-6BABB | 6 | POLYGON ((-74.01084 40.80323, -74.0132 40.8010... |
(Multi)Linestring/ (Multi)Polygon to DGGAL¶
In [4]:
Copied!
from vgridpandas import dggalpandas
import geopandas as gpd
gdf = gpd.read_file('https://raw.githubusercontent.com/opengeoshub/vopendata/refs/heads/main/shape/polygon.geojson')
resolution = 10
gdf_polyfill = gdf.dggal.polyfill(dggs_type, resolution, compact = True, predicate = "intersects", explode = False)
gdf_polyfill = gdf_polyfill.dggal.dggal2geo(dggs_type)
gdf_polyfill.plot(edgecolor = "white")
from vgridpandas import dggalpandas
import geopandas as gpd
gdf = gpd.read_file('https://raw.githubusercontent.com/opengeoshub/vopendata/refs/heads/main/shape/polygon.geojson')
resolution = 10
gdf_polyfill = gdf.dggal.polyfill(dggs_type, resolution, compact = True, predicate = "intersects", explode = False)
gdf_polyfill = gdf_polyfill.dggal.dggal2geo(dggs_type)
gdf_polyfill.plot(edgecolor = "white")
Out[4]:
<Axes: >
DGGAL point binning¶
In [5]:
Copied!
import pandas as pd
from vgridpandas import dggalpandas
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.dggal.dggalbin(dggs_type, 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 dggalpandas
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.dggal.dggalbin(dggs_type, 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[5]:
<Axes: >