Add 19 trails and 20 tracks, record stated permission, and remove the C&O Canal Towpath
Mirror to forge / mirror (push) Canceled after 0s
Validate / validate (push) Canceled after 0s
Validate / site (push) Canceled after 0s
Validate / deploy (push) Canceled after 0s

A deeper, region-by-region search of the web added 14 official trails and
4 routes. The Hoosier Heritage Trail was added at its association's request
(issue 2) with the association's own track, shared by written permission.

- New licence value `stated-permission`, with the quoted words, who gave
  them, when and where as fields of the record, shown on the trail page
  and carried in the GPX description.
- Tracks from OpenStreetMap or the Forest Service's open trail data for
  eleven of the new trails and seven existing ones. `tools/osm_track.py`
  can join several relations and leave ways out by name.
- The C&O Canal Towpath is removed: the rule leaves out canal towpaths.
- The Grand Enchantment Trail is recorded as a route by its author, with
  no track.
- Corrections to the Finger Lakes, Ozark Highlands, Eastern Continental
  and Knobstone records, checked against the pages they cite.
- Site: the list pages' own units switch is gone in favour of the header
  one; the map switch and a swapped length range stay in step with the
  page.
- CHANGELOG.md brought up to date from the site's opening to today.

204 trails: 147 official trails and 57 routes; 126 have a track.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-16 12:22:56 -07:00
1 parent c11a72a7dd
commit d34a9617cd
127 files changed
+2612 -358

No files matched your search

+92 -12
View File
@@ -14,6 +14,20 @@ Python standard library only. Run from anywhere:
python3 tools/osm_track.py RELATION_ID --id TRAIL_ID --dry print figures only
python3 tools/osm_track.py RELATION_ID --id TRAIL_ID --out DIR write to DIR/TRAIL_ID
python3 tools/osm_track.py RELATION_ID --id TRAIL_ID --force replace existing files
python3 tools/osm_track.py REL1 REL2 ... --id TRAIL_ID join several relations
python3 tools/osm_track.py RELATION_ID --id TRAIL_ID --exclude-name "Castle Pass Trail"
leave out ways with that name
Several relations (a trail mapped as separate section relations) are read one
after another and joined into one track: main ways in the order of the
relations, a way kept once at its first place, a way main in any relation
kept as main. A single relation gives exactly the files it always did.
--exclude-name NAME (repeatable) leaves out every way whose name tag is NAME
(whole name, upper or lower case alike), from main and alternates alike. It is
for a relation that also holds ways of other, differently named trails. The
run prints each name left out and how many ways, and release.txt says so.
Without it nothing is left out and the output is exactly what it was.
The trail directory (and its trail.toml) must exist first. It prints what the
record's [verification] and [osm] sections need: ways in main and in
@@ -178,13 +192,14 @@ def fetch(relation_id, opener=urllib.request.urlopen, sleep=time.sleep,
# ---------------------------------------------------------------- parsing
def parse(doc, relation_id, warn=None):
def parse(doc, relation_id, warn=None, exclude_names=()):
"""Turn an Overpass JSON response into the track.
Returns a dict: version, timestamp, main and side (lists of way dicts with
osm_id, name, highway, coords), roles (a Counter-like dict of
"type:role" -> count). Raises TrackError for a relation that is not a
route, or that has no way members.
route, or that has no way members. A way whose name is in exclude_names is
left out and listed under "excluded" (osm_id, name); no key changes without it.
"""
warn = warn or (lambda m: print("warning: " + m, file=sys.stderr))
nodes, ways, rels = {}, {}, {}
@@ -204,6 +219,8 @@ def parse(doc, relation_id, warn=None):
if rtype not in ("route", "superroute"):
raise TrackError(f"relation {relation_id} is type={rtype!r}, not type=route")
skip = {n.strip().casefold() for n in exclude_names}
excluded = []
roles, main, side = {}, [], []
seen_main, seen_side = set(), set()
@@ -245,6 +262,9 @@ def parse(doc, relation_id, warn=None):
warn(f"way {wid} has fewer than 2 points; skipped")
continue
tags = way.get("tags") or {}
if skip and (tags.get("name") or "").strip().casefold() in skip:
excluded.append((str(wid), tags["name"]))
continue
rec = {"osm_id": str(wid), "coords": coords}
if tags.get("name"):
rec["name"] = tags["name"]
@@ -273,7 +293,8 @@ def parse(doc, relation_id, warn=None):
raise TrackError(f"relation {relation_id} has no usable ways")
return {"version": root.get("version"), "timestamp": root.get("timestamp"),
"main": main, "side": side, "roles": roles,
"name": (root.get("tags") or {}).get("name", "")}
"name": (root.get("tags") or {}).get("name", ""),
"excluded": excluded}
# ---------------------------------------------------------------- output
@@ -292,14 +313,50 @@ def geojson_text(ways):
return HEADER + ",".join(feats) + "]}\n"
def release_text(trail_id, relation_id, date):
return (f"{trail_id}\n\n"
f"Source: https://www.openstreetmap.org/relation/{relation_id}\n"
def release_text(trail_id, relation_id, date, left_out=None):
if isinstance(relation_id, (list, tuple)) and len(relation_id) == 1:
relation_id = relation_id[0]
if isinstance(relation_id, (list, tuple)):
src = "".join(f"Source: https://www.openstreetmap.org/relation/{r}\n"
for r in relation_id)
else:
src = f"Source: https://www.openstreetmap.org/relation/{relation_id}\n"
text = (f"{trail_id}\n\n"
f"{src}"
"Licence: ODbL-1.0 (see trail.toml and SOURCES.md in this repository)\n"
"Attribution: OpenStreetMap contributors (ODbL)\n"
f"Source read: {date}\n"
"Published copy: coordinates rounded to 6 decimal places and written as "
"compact JSON. Geometry is otherwise as served.\n")
"compact JSON. Geometry is otherwise as served")
if left_out:
text += (", except that ways named " + ", ".join(f"{n}" for n in left_out)
+ " were left out because they belong to other trails")
return text + ".\n"
def merge_tracks(tracks):
"""Join the tracks of several relations into one (see the header)."""
if len(tracks) == 1:
return tracks[0]
main, side, roles = [], [], {}
seen_main, seen_side = set(), set()
for t in tracks:
for w in t["main"]:
if w["osm_id"] not in seen_main:
seen_main.add(w["osm_id"])
main.append(w)
for w in t["side"]:
if w["osm_id"] not in seen_side:
seen_side.add(w["osm_id"])
side.append(w)
for k, v in t["roles"].items():
roles[k] = roles.get(k, 0) + v
side = [w for w in side if w["osm_id"] not in seen_main]
return {"excluded": [e for t in tracks for e in t.get("excluded", [])],
"version": [t["version"] for t in tracks],
"timestamp": [t["timestamp"] for t in tracks],
"main": main, "side": side, "roles": roles,
"name": " + ".join(t["name"] for t in tracks)}
def figures(track):
@@ -322,12 +379,32 @@ def run(args, fetcher=fetch, today=None, out=print):
if have:
raise TrackError(f"{', '.join(have)} already in {tdir}: use --force to "
"replace")
track = parse(fetcher(args.relation), args.relation)
rels = (list(args.relation) if isinstance(args.relation, (list, tuple))
else [args.relation])
skip = list(getattr(args, "exclude_name", None) or [])
parsed = []
for rel in rels:
t = parse(fetcher(rel), rel, exclude_names=skip)
if len(rels) > 1:
f1 = figures(t)
out(f"relation {rel} {t['name']!r}: version {t['version']}, "
f"{f1['main_ways']} main ways, {f1['measured_km']:.1f} km")
parsed.append(t)
track = merge_tracks(parsed)
fig = figures(track)
for key in sorted(track["roles"]):
out(f"role {key}: {track['roles'][key]}")
out(f"relation {args.relation} {track['name']!r}: version {track['version']}, "
f"timestamp {track['timestamp']}")
if len(rels) == 1:
out(f"relation {rels[0]} {track['name']!r}: version {track['version']}, "
f"timestamp {track['timestamp']}")
else:
out(f"joined {len(rels)} relations: {rels}")
left_out = []
for name in skip:
n = sum(1 for _, nm in track.get("excluded", []) if nm.strip().casefold() == name.strip().casefold())
out(f"left out: {n} way{'s' if n != 1 else ''} named {name!r}")
if n:
left_out.append(name)
out(f"main ways: {fig['main_ways']}")
out(f"alternate ways: {fig['alternate_ways']}")
out(f"measured_km: {fig['measured_km']:.1f}")
@@ -336,7 +413,7 @@ def run(args, fetcher=fetch, today=None, out=print):
out("dry run: nothing written")
return track
date = (today or datetime.date.today()).isoformat()
files = {"release.txt": release_text(args.id, args.relation, date)}
files = {"release.txt": release_text(args.id, rels, date, left_out)}
if track["main"]:
files["line.geojson"] = geojson_text(track["main"])
else:
@@ -354,10 +431,13 @@ def run(args, fetcher=fetch, today=None, out=print):
def main(argv=None):
ap = argparse.ArgumentParser(description="Fetch a trail's track from an OSM route relation.")
ap.add_argument("relation", type=int, help="OSM relation id")
ap.add_argument("relation", type=int, nargs="+",
help="OSM relation id (several: joined into one track)")
ap.add_argument("--id", required=True, help="trail id (the directory name)")
ap.add_argument("--out", default=ROOT, help="directory holding the trail directories "
"(default: the repository root)")
ap.add_argument("--exclude-name", action="append", default=[], metavar="NAME",
help="leave out ways with this name tag (repeatable)")
ap.add_argument("--dry", action="store_true", help="print the figures, write nothing")
ap.add_argument("--force", action="store_true", help="replace existing files")
args = ap.parse_args(argv)
+95
View File
@@ -242,6 +242,101 @@ class RunTests(unittest.TestCase):
self.assertNotIn("alternates.geojson", os.listdir(os.path.join(tmp, "t")))
class MultiRelationTests(unittest.TestCase):
def test_release_text_lists_each_relation(self):
one = T.release_text("x", 5, "2026-01-02")
self.assertEqual(one, T.release_text("x", [5], "2026-01-02"))
two = T.release_text("x", [5, 6], "2026-01-02")
self.assertIn("Source: https://www.openstreetmap.org/relation/5\n"
"Source: https://www.openstreetmap.org/relation/6\n", two)
def test_two_relations_joined_once_per_way(self):
import datetime
calls = []
def fetch(r):
calls.append(r)
return response()
with tempfile.TemporaryDirectory() as tmp:
os.mkdir(os.path.join(tmp, "t"))
ns = argparse.Namespace(relation=[1, 1], id="t", out=tmp, dry=False,
force=False)
T.run(ns, fetcher=fetch, out=lambda m: None,
today=datetime.date(2026, 1, 2))
self.assertEqual(calls, [1, 1])
single = T.parse(response(), 1)
with open(os.path.join(tmp, "t", "line.geojson"), encoding="utf-8") as f:
self.assertEqual(f.read(), T.geojson_text(single["main"]))
with open(os.path.join(tmp, "t", "release.txt"), encoding="utf-8") as f:
self.assertEqual(f.read().count("Source: "), 2)
def test_merge_main_wins_over_side(self):
a = {"version": 1, "timestamp": "x", "name": "a", "roles": {"way:(empty)": 1},
"main": [{"osm_id": "1", "coords": [[0, 0], [1, 1]]}], "side": []}
b = {"version": 2, "timestamp": "y", "name": "b", "roles": {"way:(empty)": 1},
"main": [{"osm_id": "2", "coords": [[1, 1], [2, 2]]}],
"side": [{"osm_id": "1", "coords": [[0, 0], [1, 1]]},
{"osm_id": "3", "coords": [[5, 5], [6, 6]]}]}
m = T.merge_tracks([a, b])
self.assertEqual([w["osm_id"] for w in m["main"]], ["1", "2"])
self.assertEqual([w["osm_id"] for w in m["side"]], ["3"])
self.assertEqual(m["roles"]["way:(empty)"], 2)
class ExcludeNameTests(unittest.TestCase):
"""--exclude-name leaves out ways of other trails and changes nothing else."""
def test_no_option_gives_the_same_track(self):
plain = T.parse(response(), 1)
self.assertEqual(plain["excluded"], [])
again = T.parse(response(), 1, exclude_names=())
self.assertEqual(T.geojson_text(plain["main"]), T.geojson_text(again["main"]))
self.assertEqual(T.geojson_text(plain["side"]), T.geojson_text(again["side"]))
def test_named_way_is_left_out_of_main(self):
t = T.parse(response(), 1, exclude_names=["main"]) # way 10 is named "Main"
self.assertEqual(t["excluded"], [("10", "Main")])
self.assertNotIn("10", [w["osm_id"] for w in t["main"]])
plain = T.parse(response(), 1)
self.assertEqual([w["osm_id"] for w in t["main"]],
[w["osm_id"] for w in plain["main"] if w["osm_id"] != "10"])
self.assertEqual(t["side"], plain["side"])
def test_unnamed_ways_and_other_names_stay(self):
t = T.parse(response(), 1, exclude_names=["Some Other Trail"])
self.assertEqual(t["excluded"], [])
self.assertEqual(t["main"], T.parse(response(), 1)["main"])
def test_release_text_says_what_was_left_out(self):
text = T.release_text("x", 5, "2026-01-02", ["Castle Pass Trail", "Three Fools Creek Trail"])
self.assertIn("except that ways named Castle Pass Trail, Three Fools Creek Trail were left out", text)
self.assertEqual(T.release_text("x", 5, "2026-01-02", []), T.release_text("x", 5, "2026-01-02"))
def test_run_writes_without_the_ways_and_says_so(self):
import datetime
msgs = []
with tempfile.TemporaryDirectory() as tmp:
os.mkdir(os.path.join(tmp, "t"))
ns = argparse.Namespace(relation=[1], id="t", out=tmp, dry=False, force=False,
exclude_name=["Main"])
T.run(ns, fetcher=lambda r: response(), out=msgs.append, today=datetime.date(2026, 1, 2))
with open(os.path.join(tmp, "t", "line.geojson"), encoding="utf-8") as f:
self.assertNotIn('"osm_id":"10"', f.read())
with open(os.path.join(tmp, "t", "release.txt"), encoding="utf-8") as f:
self.assertIn("ways named Main were left out", f.read())
self.assertIn("left out: 1 way named 'Main'", msgs)
def test_command_line_takes_the_option_more_than_once(self):
calls = []
real = T.run
try:
T.run = lambda args, **kw: calls.append(args)
T.main(["5", "--id", "t", "--exclude-name", "A", "--exclude-name", "B"])
finally:
T.run = real
self.assertEqual(calls[0].exclude_name, ["A", "B"])
class FetchTests(unittest.TestCase):
def test_next_endpoint_before_any_wait(self):
calls, sleeps = [], []
+106
View File
@@ -0,0 +1,106 @@
"""Tests for the stated-permission licence in tools/validate.py.
Run from the repository root:
python3 -m unittest discover tools/tests
"""
import os
import sys
import unittest
sys.dont_write_bytecode = True
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import validate as V # noqa: E402
GOOD = {
"licence": "stated-permission",
"licence_text": "The association's president answered the form on the issue tracker.",
"permission_quote": "It's completely public and free to share.",
"permission_by": "the association's president",
"permission_date": "2026-11-16",
"permission_url": "https://github.com/example/repo/issues/2",
}
def check(src):
errors = []
V.check_stated_permission("t", src, errors)
return errors
def without(field, **more):
src = {k: v for k, v in GOOD.items() if k != field}
src.update(more)
return src
class StatedPermissionTest(unittest.TestCase):
def test_value_is_allowed_and_carries_a_track(self):
self.assertIn("stated-permission", V.ALLOWED_LICENCES)
self.assertIn("stated-permission", V.DATA_LICENCES)
def test_complete_statement_passes(self):
self.assertEqual(check(dict(GOOD)), [])
def test_each_of_the_four_fields_is_required(self):
for field in V.PERMISSION_FIELDS:
errors = check(without(field))
self.assertEqual(len(errors), 1, field)
self.assertIn(field, errors[0])
def test_empty_quote_or_role_fails(self):
self.assertEqual(len(check(without("permission_quote", permission_quote=" "))), 1)
self.assertEqual(len(check(without("permission_by", permission_by=""))), 1)
def test_date_must_be_a_real_iso_date(self):
for bad in ("16 November 2026", "2026-11-1", "2026-13-40", 20261116):
self.assertEqual(len(check(without("permission_date", permission_date=bad))), 1, bad)
def test_address_must_be_http_or_https(self):
for bad in ("github.com/example/repo/issues/2", "ftp://example.org/x", "https://", "see the issue"):
self.assertEqual(len(check(without("permission_url", permission_url=bad))), 1, bad)
self.assertEqual(check(without("permission_url", permission_url="http://example.org/x")), [])
def test_missing_licence_text_fails(self):
self.assertEqual(len(check(without("licence_text"))), 1)
def test_other_licences_may_not_carry_the_fields(self):
errors = check({"licence": "ODbL-1.0", "licence_text": "ODbL",
"permission_quote": "Yes", "permission_by": "x"})
self.assertEqual(len(errors), 2)
self.assertIn("stated-permission licence only", errors[0])
def test_other_licences_without_the_fields_pass(self):
self.assertEqual(check({"licence": "ODbL-1.0", "licence_text": "no address"}), [])
def test_the_hoosier_record_passes(self):
import tomllib
path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
"hoosier-heritage-trail", "trail.toml")
with open(path, "rb") as f:
src = tomllib.load(f)["source"]
self.assertEqual(src["licence"], "stated-permission")
self.assertEqual(check(src), [])
class LonlatWithoutPlaceNameTest(unittest.TestCase):
def run_check(self, line_file):
errors = []
rec = {"length_km": 259, "source": {"line_file": line_file},
"hike": {"summary": "S.", "official_url": "https://x.example/",
"start_lonlat": [-85.863, 38.462], "end_lonlat": [-86.477, 39.323],
"checked": "2026-11-16"}}
V.check_hike("t", rec, errors)
return [e for e in errors if "lonlat" in e]
def test_track_ends_need_no_place_name(self):
self.assertEqual(self.run_check("line.geojson"), [])
def test_record_without_track_still_needs_the_place_name(self):
errors = self.run_check("")
self.assertEqual(len(errors), 2)
self.assertIn("hike.start is not", errors[0])
if __name__ == "__main__":
unittest.main()
+39 -7
View File
@@ -19,10 +19,10 @@ import re
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MAX_BYTES = 50 * 1024 * 1024
ALLOWED_LICENCES = {
"us-gov-public-domain", "CC-BY-4.0", "CC-BY", "ODbL-1.0",
"us-gov-public-domain", "CC-BY-4.0", "CC-BY", "ODbL-1.0", "stated-permission",
"CC-BY-NC-ND-4.0", "none-stated", "restricted", "unknown",
}
DATA_LICENCES = {"us-gov-public-domain", "CC-BY-4.0", "CC-BY", "ODbL-1.0"}
DATA_LICENCES = {"us-gov-public-domain", "CC-BY-4.0", "CC-BY", "ODbL-1.0", "stated-permission"}
LINE_POLICIES = {"open", "sold", "withheld", "unclear"}
NO_LINE_POLICIES = {"sold", "withheld", "unclear"}
DATE_RE = re.compile(r"^\d{4}-\d{2}-\d{2}$")
@@ -103,6 +103,38 @@ def check_geometry(geom, where, errors):
return length
PERMISSION_FIELDS = ("permission_quote", "permission_by", "permission_date", "permission_url")
def check_stated_permission(tid, src, errors):
"""A track shared by stated permission quotes the statement, says who made it, when and where.
The four permission_* fields are required for that licence and refused for every other one."""
if src.get("licence") != "stated-permission":
for field in PERMISSION_FIELDS:
if field in src:
errors.append(f"{tid}: source.{field} belongs to the stated-permission licence only")
return
text = src.get("licence_text")
if not isinstance(text, str) or not text.strip():
errors.append(f"{tid}: licence stated-permission needs a non-empty source.licence_text")
for field in ("permission_quote", "permission_by"):
value = src.get(field)
if not isinstance(value, str) or not value.strip():
errors.append(f"{tid}: licence stated-permission needs a non-empty source.{field}")
date = src.get("permission_date")
if not isinstance(date, str) or not DATE_RE.match(date):
errors.append(f"{tid}: licence stated-permission needs source.permission_date as YYYY-MM-DD")
else:
try:
datetime.date.fromisoformat(date)
except ValueError:
errors.append(f"{tid}: source.permission_date {date!r} is not a real date")
url = src.get("permission_url")
if not isinstance(url, str) or not re.match(r"^https?://[^\s/]+\S*$", url):
errors.append(f"{tid}: licence stated-permission needs source.permission_url as an http(s) address")
def check_hike(tid, rec, errors):
"""Check the optional [hike] table and its [[hike.source]] tables."""
hike = rec.get("hike")
@@ -164,12 +196,11 @@ def check_hike(tid, rec, errors):
end_points = {}
for name, place in (("start_lonlat", "start"), ("end_lonlat", "end")):
if name in hike:
if place not in hike:
if place not in hike and not rec.get("source", {}).get("line_file"):
errors.append(f"{tid}: hike.{name} is present but hike.{place} is not")
else:
point = lonlat(name)
if point is not None:
end_points[name] = point
point = lonlat(name)
if point is not None:
end_points[name] = point
if len(end_points) == 2:
length = rec.get("length_km")
if isinstance(length, (int, float)) and not isinstance(length, bool) and length > 0:
@@ -452,6 +483,7 @@ def main():
errors.append(f"{tid}: missing required field source.{field}")
if src.get("licence") not in ALLOWED_LICENCES:
errors.append(f"{tid}: licence {src.get('licence')!r} is not in the allowed list")
check_stated_permission(tid, src, errors)
if not str(src.get("url", "")).startswith(("https://", "http://")):
errors.append(f"{tid}: source.url must be an http(s) URL")
if not DATE_RE.match(str(src.get("source_checked", ""))):