Polygon-to-polygon weight calculation.#
This notebook demonstrates generating weights, or creating a cross-walk between a source GeoDataFrame and a target GeoDataFrame. The example here demonstrates calculating the weights from HUC-12 to HUC-8 polygons encompassing the Delaware River Basin. A second notebook ./Extensive_vs_intensive_variables.ipynb demonstrates how to use the weights to interpolate values from HUC-12 to HUC-8 polygons, for both extensive and intensive variables.
Open Source Python Tools#
Data#
pynhd pynhd provides access to several hydro-linked datasets including those used here: WaterData and NLDI. We use the NLDI to get the basin geometry upstream of USGS gage Delaware River ad Del Mem Bridge at Wilmington De (01482100). Using the geometry of that basin we can extract a set up HUC12 and HUC08 basins for demonstration purposes.
Maintenance Schedule#
This notebook is part of the gdptools demo’s and will be updated with new versions of gdptools.
Description#
A common workflow in geospatial hydrology is to interpolate geospatial values from one set of polygons to another. For example, watershed characteristics associated with HUC12’s could be interpolated to HUC08’s by using an area-weighted statistic. This notebook demonstrates a function of gdptools for calculating the weights or cross-walk for calculating that interpolation. for an example of how to use the weights to interpolate values from HUC-12 to HUC-8 polygons, see the notebook ./Extensive_vs_intensive_variables.ipynb.
Getting Started#
Directions for creating an environment to run this notebook.
Requirements:#
Conda-based package manager such as miniconda or mambaforge.
Create conda/mamba environment.#
Download environment-examples.yml
To create the conda environment follow the steps below.
conda env create -f environment-examples.yml
conda activate gdptools-examples
jupyter lab
import warnings
import hvplot.pandas
import pandas as pd
from bokeh.io import export_svgs
from pynhd import NLDI, WaterData
from pygeohydro import watershed
from gdptools import WeightGenP2P
warnings.filterwarnings("ignore")
Generate example data using pynhd functions#
wbd = watershed.WBD("huc4")
delaware_basin = wbd.byids(field="huc4", fids="0204")
huc12_basins = WaterData('wbd12').bygeom(delaware_basin.iloc[0].geometry)
huc12_basins = huc12_basins[huc12_basins['huc12'].str.startswith(('020401', '020402'))]
huc08_basins = WaterData('wbd08').bygeom(delaware_basin.iloc[0].geometry)
huc08_basins = huc08_basins[huc08_basins['huc8'].str.startswith(('0204'))]
Plot basins#
from holoviews.element.tiles import EsriTerrain
drb_12 = huc12_basins.hvplot(
geo=True, coastline='50m', alpha=0.2, c='r', frame_width=300,
xlabel="longitude", ylabel="latitude",
title="Delaware River HUC12 basins", xlim=(-78.0, -73.0), aspect='equal'
)
drb_08 = huc08_basins.hvplot(
geo=True, coastline='50m', alpha=0.2, c='r', frame_width=300,
xlabel="longitude", ylabel="latitude",
title="Delaware River HUC08 basins", xlim=(-78.0, -73.0), aspect='equal'
)
EsriTerrain() * drb_12 + EsriTerrain() * drb_08