diff --git a/lib/maptool/hiking_trails.rb b/lib/maptool/hiking_trails.rb index efbecd5..ae3cbf6 100644 --- a/lib/maptool/hiking_trails.rb +++ b/lib/maptool/hiking_trails.rb @@ -7,18 +7,26 @@ module Maptool # Prototype: extracts route=hiking relations (name/colour/network/operator, # full member-way geometry) straight out of a Geofabrik .osm.pbf — the same # file PmtilesBuilder already downloads per country for offline.pmtiles, so - # this needs no separate download or third-party service. Two osmium + # this needs no separate download or third-party service. Three osmium # subprocess steps do the heavy lifting (osmium is already a server # dependency, see PmtilesBuilder/docs/development.adoc): # # 1. `osmium tags-filter FILE r/route=hiking -o hiking.osm.pbf` — pulls # out just the hiking relations *and* (by default, no -R) every way/ # node they reference, so the output is small and self-contained. - # 2. `osmium cat hiking.osm.pbf -f opl,locations_on_ways=true,add_metadata=false` + # 2. `osmium add-locations-to-ways` — a plain Geofabrik PBF's ways only + # carry bare node *references* (ids), not coordinates; this resolves + # each way's node ids against the node objects in the same file and + # rewrites the way with real coordinates attached. Verified against a + # real extract (Macedonia) that skipping this step silently produces + # ways with empty x/y (`n123xy`, no numbers) in the OPL output below — + # not an error, just wrong output, so easy to miss without checking. + # 3. `osmium cat hiking.osm.pbf -f opl,locations_on_ways=true,add_metadata=false` # — OPL is a plain-text, one-object-per-line format (see - # https://osmcode.org/opl-file-format/); locations_on_ways embeds each - # way's node coordinates directly in its own line, so no separate - # node-id -> [lon,lat] table needs building, just two passes over text. + # https://osmcode.org/opl-file-format/); locations_on_ways (now that + # step 2 actually populated them) embeds each way's node coordinates + # directly in its own line, so no separate node-id -> [lon,lat] table + # needs building, just two passes over text. # # No general OSM tool stitches a route relation's member ways into one # line for you (routes are a semantic grouping, not a geometry type) — @@ -45,8 +53,11 @@ module Maptool filtered = File.join(dir, "hiking.osm.pbf") run!(osmium_bin, "tags-filter", pbf_path, "r/route=hiking", "-o", filtered) + located = File.join(dir, "hiking-located.osm.pbf") + run!(osmium_bin, "add-locations-to-ways", filtered, "-o", located) + opl_path = File.join(dir, "hiking.opl") - run!(osmium_bin, "cat", filtered, "-f", "opl,locations_on_ways=true,add_metadata=false", "-o", opl_path) + run!(osmium_bin, "cat", located, "-f", "opl,locations_on_ways=true,add_metadata=false", "-o", opl_path) parse_opl(File.read(opl_path)) end