Skip to content

Commit

Permalink
Merge branch 'main' into JesseWeinstein-loading_effect
Browse files Browse the repository at this point in the history
  • Loading branch information
amandasaurus committed Mar 17, 2024
2 parents 3fc0a21 + 11b2425 commit c34dd59
Show file tree
Hide file tree
Showing 24 changed files with 1,416 additions and 567 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
*.gpkg.zst.torrent
*.osm.pbf
*.pmtiles
*.pmtiles2
*.pmtiles-journal
/add-incomplete-ways.osc
/docs/data/*
/incomplete_ways.txt
/tmp.*.geojson
/tmp.*.pmtiles.tmp
/waterwaymap.org_loops_stats.csv.zst
/tilekiln/
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/docs/alpine-3.12.3.js
/docs/maplibre-gl-2.4.0.css
/docs/maplibre-gl-2.4.0.js
/docs/pmtiles-2.7.1.js
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 2024-01-30

• upload the ends file as a gzip'ed geojson
51 changes: 31 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ planet-waterway.osm.pbf:
-a udp://tracker.torrent.eu.org:451 \
-a udp://tracker-udp.gbitt.info:80/announce,http://tracker.gbitt.info/announce,https://tracker.gbitt.info/announce \
-a http://retracker.local/announce \
-w "https://pub-02bff1796dd84d2d842f219d10ae945d.r2.dev/2023-04-01/$<" \
-w "https://data.waterwaymap.org/$<" \
-c "WaterwayMap.org data export. licensed under https://opendatacommons.org/licenses/odbl/ by OpenStreetMap contributors" \
-o $@ > /dev/null

Expand Down Expand Up @@ -81,7 +81,7 @@ planet-waterway-boatable.geojsons: planet-waterway.osm.pbf
mv tmp.$@ $@

planet-waterway-canoeable.geojsons: planet-waterway.osm.pbf
osm-lump-ways -i $< -o tmp.$@ --min-length-m 100 --save-as-linestrings -f canoe∈yes,portage
osm-lump-ways -i $< -o tmp.$@ --min-length-m 100 --save-as-linestrings -f canoe∈yes,portage,permissive,designated,destination,customers,permit
mv tmp.$@ $@

planet-waterway-all.geojsons: planet-waterway.osm.pbf
Expand All @@ -94,11 +94,11 @@ planet-waterway-or-naturalwater.geojsons: planet-waterway.osm.pbf


planet-waterway-water.geojsons: planet-waterway.osm.pbf
osm-lump-ways -i $< -o tmp.$@ --min-length-m 100 --save-as-linestrings -f waterway -f waterway∉dam,weir,lock_gate,sluice_gate,security_lock,fairway,dock,boatyard,fuel,riverbank,pond,check_dam,turning_point,water_point,spillway,safe_water
osm-lump-ways -i $< -o tmp.$@ --min-length-m 100 --save-as-linestrings -f waterway -f waterway∉dam,weir,lock_gate,sluice_gate,security_lock,fairway,dock,boatyard,fuel,riverbank,pond,check_dam,turning_point,water_point,safe_water
mv tmp.$@ $@

planet-waterway-nonartifical.geojsons: planet-waterway.osm.pbf
osm-lump-ways -i $< -o tmp.$@ --min-length-m 100 --save-as-linestrings -f waterway -f waterway∉dam,weir,lock_gate,sluice_gate,security_lock,fairway,dock,boatyard,fuel,riverbank,pond,check_dam,turning_point,water_point,spillway,safe_water -f waterwaycanal,ditch
osm-lump-ways -i $< -o tmp.$@ --min-length-m 100 --save-as-linestrings -F "waterwaydam,weir,lock_gate,sluice_gate,security_lock,fairway,dock,boatyard,fuel,riverbank,pond,check_dam,turning_point,water_point,safe_water→F; waterway∈ditch,drain,tidal_channel→F; waterway=canal∧lock∈yes,disused→T; waterway=spillway∧area=yes→F; waterway=canal∧usage=spillway→T; waterway=canal∧usage∈headrace,tailrace→T; waterway=canal→F; waterway→T; F"
mv tmp.$@ $@

planet-waterway-rivers-etc.geojsons: planet-waterway.osm.pbf
Expand All @@ -109,26 +109,29 @@ planet-waterway-missing-wiki.geojsons: planet-waterway.osm.pbf
osm-lump-ways -i $< -o tmp.$@ --min-length-m 100 --save-as-linestrings -f waterway -f name -f ∄wikipedia -f ∄wikidata -g name
mv tmp.$@ $@

planet-cycles.geojsons planet-upstreams.geojsons planet-ends.geojsons: planet-waterway.osm.pbf
rm -fv tmp.planet-{cycles,upstreams,ends}.geojsons
./osm-lump-ways-down -i ./planet-waterway.osm.pbf -o tmp.planet-%s.geojsons -f waterway -f waterway∉dam,weir,lock_gate,sluice_gate,security_lock,fairway,dock,boatyard,fuel,riverbank,pond,check_dam,turning_point,water_point,spillway,safe_water,derelict_canal,offshore_field,boat_lift -f waterway∉canal,ditch,drain -f waterwayput_in,link --openmetrics ./docs/data/waterwaymap.org_loops_metrics.prom --csv-stats-file ./docs/data/waterwaymap.org_loops_stats.csv
mv tmp.planet-cycles.geojsons planet-cycles.geojsons
planet-loops.geojsons planet-upstreams.geojsons planet-ends.geojsons: planet-waterway.osm.pbf
rm -fv tmp.planet-{loops,upstreams,ends}.geojsons
osm-lump-ways-down -i ./planet-waterway.osm.pbf -o tmp.planet-%s.geojsons -F "waterwaydam,weir,lock_gate,sluice_gate,security_lock,fairway,dock,boatyard,fuel,riverbank,pond,check_dam,turning_point,water_point,safe_water,derelict_canal,offshore_field,boat_lift,depth_line,floating_barrier,floodgate→F; waterwayditch,drain,tidal_channel→F; waterwayput_in,link→F; waterway=canal∧lock∈yes,disused→T; waterway=spillway∧area=yes→F; waterway=canal∧usage=spillway→T; waterway=canal∧usage∈headrace,tailrace→T; waterway=canal→F; waterway→T; F" --openmetrics ./docs/data/waterwaymap.org_loops_metrics.prom --csv-stats-file ./docs/data/waterwaymap.org_loops_stats.csv
mv tmp.planet-loops.geojsons planet-loops.geojsons
mv tmp.planet-upstreams.geojsons planet-upstreams.geojsons || true
mv tmp.planet-ends.geojsons planet-ends.geojsons || true

planet-cycles.pmtiles: planet-cycles.geojsons
planet-loops.pmtiles: planet-loops.geojsons
rm -fv tmp.$@
timeout 8h tippecanoe \
-n "OSM Waterway Loops" \
-N "Generated on $(shell date -I) from OSM data with $(shell osm-lump-ways --version) and argument" \
-A "© OpenStreetMap. Open Data under ODbL. https://osm.org/copyright" \
-zg \
--no-feature-limit \
--simplification=8 \
-r1 \
--cluster-densest-as-needed \
-y root_nid \
--no-feature-limit \
--no-tile-size-limit \
--accumulate-attribute num_nodes:sum \
--accumulate-attribute length_m:sum \
-y root_nid -y num_nodes -y length_m \
-l loops \
--gamma 2 \
--no-progress-indicator \
-o tmp.$@ $<
mv tmp.$@ $@
Expand All @@ -140,13 +143,14 @@ planet-upstreams.pmtiles: planet-upstreams.geojsons
-N "Generated on $(shell date -I) from OSM data with $(shell osm-lump-ways --version) and argument" \
-A "© OpenStreetMap. Open Data under ODbL. https://osm.org/copyright" \
-zg \
--no-feature-limit \
--simplification=8 \
--cluster-densest-as-needed \
-r1 \
--cluster-distance 1 \
--accumulate-attribute from_upstream_m:max \
-y from_upstream_m \
-l upstreams \
--gamma 2 \
--no-progress-indicator \
-o tmp.$@ $<
mv tmp.$@ $@

Expand All @@ -156,13 +160,20 @@ planet-ends.pmtiles: planet-ends.geojsons
-n "OSM Waterway Endpoints" \
-N "Generated on $(shell date -I) from OSM data with $(shell osm-lump-ways --version) and argument" \
-A "© OpenStreetMap. Open Data under ODbL. https://osm.org/copyright" \
-zg \
-r1 \
-z 10 \
--feature-filter '{ "*": [">=", "upstream_m", 2000 ] }' \
--no-feature-limit \
--simplification=8 \
--cluster-densest-as-needed \
-y from_upstream_m \
-l upstream_m \
--gamma 2 \
--order-descending-by upstream_m \
-r1 \
--cluster-distance 5 \
--accumulate-attribute upstream_m:sum \
-y upstream_m -y nid \
-l ends \
--no-progress-indicator \
-o tmp.$@ $<
mv tmp.$@ $@

planet-ends.geojsons.gz: planet-ends.geojsons
rm -fv $@
gzip -k -9 $<
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,45 @@ See the [website](https://waterwaymap.org).

![map of europe with all the river basins higlighted](https://waterwaymap.org/screenshot.png)

[News & Updates on the OSM Town Mapstodon](https://en.osm.town/@amapanda/tagged/WaterwayMapOrg).

## See also

* [Fedi/Mastodon post](https://en.osm.town/@amapanda/110118513232919061)
* [OSM Discourse Community Forum](https://community.openstreetmap.org/t/osm-river-basins-website-to-show-how-are-rivers-in-osm-connected/102655)
* [OSM Changesets that have used this tool](https://resultmaps.neis-one.org/osm-changesets?comment=RiverMapping)
* [OSM Community Forum](https://community.openstreetmap.org/t/osm-river-basins-website-to-show-how-are-rivers-in-osm-connected/102655)
* [OSM Changesets that have used this tool](https://resultmaps.neis-one.org/osm-changesets?comment=WaterwayMapOrg) (older [`#RiverMapping` tag](https://resultmaps.neis-one.org/osm-changesets?comment=RiverMapping)).
* [Changesets on OSMCha](https://osmcha.org/?filters=%7B%22metadata%22%3A%5B%7B%22label%22%3A%22hashtags%3D%23RiverMapping%22%2C%22value%22%3A%22hashtags%3D%23RiverMapping%22%7D%5D%7D)
* [Hacker News](https://news.ycombinator.com/item?id=37321292)
* Hacker News: [#1 (2023-08-30) (as “OSM River Basins”)](https://news.ycombinator.com/item?id=37321292), [#2 (2024-01-24)](https://news.ycombinator.com/item?id=39110434)

### OSM Tagging Discussions from this tool

* [Should river lines be mapped through lakes, estuaries, gulfs, and other large water bodies?](https://community.openstreetmap.org/t/should-river-lines-be-mapped-through-lakes-estuaries-gulfs-and-other-large-water-bodies/104438) _(Oct. 2023)_
* [Properly mapping dry washes](https://community.openstreetmap.org/t/properly-mapping-dry-washes/108437) _(Jan. 2024)_

## Loops

Loops in waterways are detected and shown on: [`WaterwayMap.org/loops/`](https://waterwaymap.org/loops/).

* [Fedi/Masto post](https://en.osm.town/@amapanda/111658136395447174)
* [OSM Forum announcement](https://community.openstreetmap.org/t/the-wonders-of-early-medieval-fore-abbey-and-osm-river-topology-today-i-e-waterwaymap-org-is-going-around-in-circles/107497)
* [OSM Ccommunity Forum announcement](https://community.openstreetmap.org/t/the-wonders-of-early-medieval-fore-abbey-and-osm-river-topology-today-i-e-waterwaymap-org-is-going-around-in-circles/107497)

### Statistics

[`@watmildon@en.osm.town`](https://en.osm.town/@watmildon) has made a mastodon account summarizing stats: [`@OSMWaterwayLoopStats@en.osm.town`](https://en.osm.town/@OSMWaterwayLoopStats) [feed](https://en.osm.town/@OSMWaterwayLoopStats.rss)

## End Points

Points at which waterways end are shown on: [`WaterwayMap.org/ends/`](https://waterwaymap.org/ends/).

* [Fedi/Masto post](https://en.osm.town/@amapanda/111844170704856219)
* [OSM Ccommunity Forum announcement](https://community.openstreetmap.org/t/the-end-of-waterway-map/108632)


## Related Projects

* [JOSM Waterway Style](https://josm.openstreetmap.de/wiki/Styles/Waterways)

## Copyright

Copyright MIT or Apache-2.0, 2017→2021 Amanda McCann <amanda@technomancy.org>
Copyright MIT or Apache-2.0, 2017→2024 Amanda McCann <amanda@technomancy.org>

59 changes: 59 additions & 0 deletions dl_missing_refs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
# Makes an OSM PBF file referntially complete, by downloading nodes from
# OSM.org API that are referenced from ways in the input file.
#
# The `dl_updates_from_osm.sh` script does repeated `pyosmium-up-to-date` on a
# filtered OSM file, applying OSM diffs, and afterwards filtering out unwanted
# ways. OSM Diffs do not contain the referred objects. When a way is changed,
# to add a `waterway` tag, that new way version will be in the diff, and for
# the first time in the filtered OSM file. However the diff will not have
# included the ways in that way. An OSM file, updated this way, will not be
# referrantially complete. Some tools (e.g. `osm2pgsql`) will silently accept
# (& ignore) these incomplete objects. `osm-lump-ways` will fail to process,
# and report an error.
#
# A simple solution is to keep the who 75 GiB planet file around, run
# `pyosmium-up-to-date` on that, and filter afterwards. That will always be
# referentially complete. However `pyosmium-up-to-date` must rewrite the planet
# file, and takes about 45 minutes. Filtering this new file, takes longer too.
# IME it is quicker to do pyosmium-up-to-date on a filtered file and run this
# programme after.
#
# If the OSM diff service returned some form of “augmented diffs”¹, or the OSM
# data model was changed to add the node position to ways directly (as Jochen
# Topf has suggested²), then this would't be needed.
#
# ¹ <https://wiki.openstreetmap.org/wiki/Overpass_API/Augmented_Diffs>
# ² <https://media.jochentopf.com/media/2022-08-15-study-evolution-of-the-osm-data-model.pdf>
#
set -o errexit -o nounset
cd "$(dirname "$0")"

FILENAME="${1:?Arg 1 must be filename}"

osmium check-refs "$FILENAME" || true

osmium check-refs --no-progress --show-ids "$FILENAME" |& grep -Po "(?<= in w)\d+$" | uniq | sort -n | uniq > incomplete_ways.txt
if [ "$(wc -l incomplete_ways.txt | cut -f1 -d" ")" -gt 0 ] ; then
echo "There are $(wc -l incomplete_ways.txt|cut -f1 -d" ") incomplete ways, which we need to download"
cat incomplete_ways.txt | while read -r WID ; do
curl -s -o "way_${WID}.osm.xml" "https://api.openstreetmap.org/api/0.6/way/${WID}/full"
done
find . -maxdepth 1 -mindepth 1 -type f -name 'way_*.osm.xml' -empty -print -delete
osmium cat --overwrite -o incomplete_ways.osm.pbf way_*.osm.xml
rm way_*.osm.xml
rm -rf incomplete_ways2.osm.pbf
osmium sort -o incomplete_ways2.osm.pbf incomplete_ways.osm.pbf
mv incomplete_ways2.osm.pbf incomplete_ways.osm.pbf
echo "" > empty.opl
rm -rf add-incomplete-ways.osc
osmium derive-changes empty.opl incomplete_ways.osm.pbf -o add-incomplete-ways.osc
rm -f empty.opl incomplete_ways.osm.pbf

rm -rf new.osm.pbf
osmium apply-changes -o new.osm.pbf "$FILENAME" add-incomplete-ways.osc
mv -v new.osm.pbf "$FILENAME"
rm -fv add-incomplete-ways.osc
osmium check-refs "$FILENAME" || true
fi
rm -f incomplete_ways.txt
23 changes: 1 addition & 22 deletions dl_updates_from_osm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,6 @@ pyosmium-up-to-date -v --ignore-osmosis-headers --server https://planet.openstre
osmium tags-filter --overwrite --output-header osmosis_replication_base_url=https://planet.openstreetmap.org/replication/minute/ --remove-tags planet-waterway.osm.pbf -o "$TMP" $TAG_FILTER && mv "$TMP" planet-waterway.osm.pbf
osmium check-refs planet-waterway.osm.pbf || true

osmium check-refs --no-progress --show-ids planet-waterway.osm.pbf |& grep -Po "(?<= in w)\d+$" | uniq | sort -n | uniq > incomplete_ways.txt
if [ "$(wc -l incomplete_ways.txt | cut -f1 -d" ")" -gt 0 ] ; then
echo "There are $(wc -l incomplete_ways.txt|cut -f1 -d" ") incomplete ways, which we need to download"
cat incomplete_ways.txt | while read -r WID ; do
curl -s -o "way_${WID}.osm.xml" "https://api.openstreetmap.org/api/0.6/way/${WID}/full"
done
osmium cat --overwrite -o incomplete_ways.osm.pbf way_*.osm.xml
rm way_*.osm.xml
rm -rf incomplete_ways2.osm.pbf
osmium sort -o incomplete_ways2.osm.pbf incomplete_ways.osm.pbf
mv incomplete_ways2.osm.pbf incomplete_ways.osm.pbf
echo "" > empty.opl
rm -rf add-incomplete-ways.osc
osmium derive-changes empty.opl incomplete_ways.osm.pbf -o add-incomplete-ways.osc
rm -f empty.opl incomplete_ways.osm.pbf
./dl_missing_refs.sh planet-waterway.osm.pbf

rm -rf new.osm.pbf
osmium apply-changes --output-header osmosis_replication_base_url=https://planet.openstreetmap.org/replication/minute/ --output-header="osmium_replication_timestamp=$LAST_TIMESTAMP" --output-header="timestamp=${LAST_TIMESTAMP}" -o new.osm.pbf planet-waterway.osm.pbf add-incomplete-ways.osc
mv -v new.osm.pbf planet-waterway.osm.pbf
rm -fv add-incomplete-ways.osc
osmium check-refs planet-waterway.osm.pbf || true
fi
rm -f incomplete_ways.txt
echo "Took $SECONDS sec ( $(units "${SECONDS}sec" time) ) to download data updates from osm.org"
Loading

0 comments on commit c34dd59

Please sign in to comment.