An illustrative river-basin commission is drafting the annex of transboundary rivers for a regional water agreement. The last draft listed any river whose line touched a second country, which put a river that spends three kilometres in a neighbour on the same page as the Danube. The commission wants a list built from measured lengths: how many countries hold a meaningful stretch of each river, and how dominated the river is by its largest holder, so that the annex can distinguish a river that is shared from one that merely crosses a line.
Write a script that produces the transboundary rivers index.
The datasets are mounted where the script runs:
/data/rivers.geojson — 461 river and lake centrelines, MultiLineStrings/data/countries.geojson — 241 countries and dependenciesgeopandas, shapely, pyproj, pandas and numpy are available.
Stage 1 — Cut and measure. For every river and every country it intersects, the geodesic length (pyproj.Geod, WGS 84) of the river inside that country, in km.
Stage 2 — Per river. total_km — the river's length inside all countries; n_countries — how many countries hold at least 5 km of it; dominant_share — the largest single country's length divided by total_km, 3 decimals.
Stage 3 — The index. Assign to a variable named `result` a GeoDataFrame of the rivers with n_countries ≥ 2, carrying the river geometry and river_id, name, n_countries, dominant_share, total_km, ordered by dominant_share ascending — the most evenly shared first. Do not write a file — the runner reads result.
/data/rivers.geojson — EPSG:4326; the geometry is in geometry (MultiLineString).
| column | type | meaning |
|---|---|---|
river_id | string | River identifier, RV- and four digits |
name | string | Name as labelled |
name_en | string | English name |
featurecla | string | River | Lake Centerline |
scalerank | integer | Prominence, lower is more prominent |
/data/countries.geojson — EPSG:4326; the geometry is in geometry (Polygon / MultiPolygon).
| column | type | meaning |
|---|---|---|
country_id | string | CO- plus the ISO 3166-1 alpha-3 code |
name | string | Short name |
name_long | string | Long name |
iso_a3 | string | ISO 3166-1 alpha-3; -99 where Natural Earth assigns none |
iso_a2 | string | ISO 3166-1 alpha-2; -99 where Natural Earth assigns none |
continent | string | Continent |
subregion | string | UN subregion |
pop_est | number | Population estimate (persons) |
pop_year | integer | Year of the estimate |
gdp_md | number | GDP, millions of US dollars (USD m) |
gdp_year | integer | Year of the GDP figure |
economy | string | Natural Earth economy class |
income_group | string | World Bank income group |
Run executes the script in your browser and shows you its output and a preview. Submit executes it again on the server and grades what result holds.
These are where the teaching is. Read them twice.
Modelled on UNECE, The Second Assessment of Transboundary Rivers, Lakes and Groundwaters (2011, https://unece.org/second-assessment-transboundary-rivers-lakes-and-groundwaters), which inventories shared waters. This exercise uses generalised Natural Earth centrelines and an illustrative five-kilometre screening convention; its holder shares are teaching measures, not UNECE figures.
Files: /data/rivers.geojson, /data/countries.geojson · assign result
7 scored, 0 informational
Cuts rivers at borders with an intersection
13%Measures length geodesically
13%How many rivers are shared by two or more countries
27%Carries river_id, name, n_countries, dominant_share and total_km
7%The most countries any one river runs through
13%Total river kilometres in the shared set
13%The smallest dominant share in the index
13%