Trails by kind: the extract keeps hiking, foot, bicycle, mtb and ski routes, each with a kind (educational told apart by educational=yes, the green diagonal marking or the name); versioned so the next offline build redoes old files; the overlay picks kinds (hiking and educational by default), the elevation profile shows the ones for the activity
CI / check (push) Successful in 21s
CI / deploy (push) Successful in 18s

This commit is contained in:
randy committed 2026-11-27 14:40:46 +01:00
1 parent 4bcd85f269
commit b32f7d3bd3
7 files changed
+92 -15

No files matched your search

+28 -3
View File
@@ -37,6 +37,22 @@ module Maptool
class ExtractError < StandardError; end
ROUTE_TAGS = %w[name description ref colour network operator].freeze
# The OSM route types kept, each as a `kind` the map and the elevation
# profile filter by (an educational trail is a hiking route too, told
# apart below).
KINDS = { "hiking" => "hiking", "foot" => "hiking", "bicycle" => "bicycle", "mtb" => "bicycle", "ski" => "ski" }.freeze
# Bumped when the extract's shape changes, so PmtilesBuilder redoes a
# country's file even though its .osm.pbf hasn't changed.
VERSION = 2
# ponytail: OSM has no single educational-trail tag in practice; the
# name in the languages here, `educational=yes`, or the SK/CZ marking
# (a green diagonal stripe, osmc:symbol "…green_diagonal").
EDUCATIONAL = /náučn|naučn|lehrpfad|themenweg|dydaktycz|edukacyj|przyrodnicz|tanösvény|nature trail|sentiero natura|sendero (de )?interpretaci/i
# Current extract format? (see VERSION; the version is the first key).
def self.current?(path)
File.open(path) { |f| f.read(32) }.to_s.start_with?(%({"version":#{VERSION},))
end
def self.osmium_bin
ENV.fetch("OSMIUM_BIN", "osmium")
@@ -51,7 +67,7 @@ module Maptool
def self.extract(pbf_path)
Dir.mktmpdir("maptool-hiking-trails") do |dir|
filtered = File.join(dir, "hiking.osm.pbf")
run!(osmium_bin, "tags-filter", pbf_path, "r/route=hiking", "-o", filtered)
run!(osmium_bin, "tags-filter", pbf_path, "r/route=#{KINDS.keys.join(',')}", "-o", filtered)
located = File.join(dir, "hiking-located.osm.pbf")
run!(osmium_bin, "add-locations-to-ways", filtered, "-o", located)
@@ -81,12 +97,12 @@ module Maptool
ways[head[1..].to_i] = way_coordinates(fields)
when "r"
tags = tags_field(fields)
relations << { id: head[1..].to_i, tags: tags, members: members_field(fields) } if tags["route"] == "hiking"
relations << { id: head[1..].to_i, tags: tags, members: members_field(fields) } if KINDS.key?(tags["route"])
end
end
features = relations.filter_map { |relation| relation_feature(relation, ways) }
{ "type" => "FeatureCollection", "features" => features }
{ "version" => VERSION, "type" => "FeatureCollection", "features" => features }
end
def self.relation_feature(relation, ways)
@@ -109,6 +125,7 @@ module Maptool
"name" => tags["name"] || tags["description"],
"distance_meters" => distance.round(1),
"oneway_lines" => oneway.empty? ? nil : oneway,
"kind" => kind(tags),
}
ROUTE_TAGS.each { |key| properties[key] ||= tags[key] }
@@ -124,6 +141,14 @@ module Maptool
end
private_class_method :relation_feature
def self.kind(tags)
kind = KINDS.fetch(tags["route"], "hiking")
educational = tags["educational"] == "yes" || tags["osmc:symbol"].to_s.include?("green_diagonal") ||
[tags["name"], tags["description"]].any? { |t| t.to_s.match?(EDUCATIONAL) }
kind == "hiking" && educational ? "educational" : kind
end
private_class_method :kind
def self.round_coordinates(lines)
lines.map { |coords| coords.map { |lon, lat| [lon.round(5), lat.round(5)] } }
end
+1 -1
View File
@@ -394,7 +394,7 @@ module Maptool
FileUtils.mkdir_p(hiking_trails_dir(data_dir))
sources.each do |source|
out_path = hiking_trails_country_path(data_dir, source["code"])
next if File.exist?(out_path) && File.mtime(out_path) >= File.mtime(source["path"])
next if File.exist?(out_path) && File.mtime(out_path) >= File.mtime(source["path"]) && HikingTrails.current?(out_path)
tmp_path = "#{out_path}.tmp"
begin