< Summary

Class:Itinero.IO.Osm.OsmEdgeTypeMap
Assembly:Itinero.IO.Osm
File(s):/home/runner/work/routing2/routing2/src/Itinero.IO.Osm/OsmEdgeTypeMap.cs
Covered lines:0
Uncovered lines:75
Coverable lines:75
Total lines:135
Line coverage:0% (0 of 75)
Covered branches:0
Total branches:6
Branch coverage:0% (0 of 6)
Tag:251_23667616543

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.cctor()100%10%
.ctor()100%10%
Map(...)100%10%
IsRelevant(...)0%60%
Set(...)100%10%

File(s)

/home/runner/work/routing2/routing2/src/Itinero.IO.Osm/OsmEdgeTypeMap.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Collections.Immutable;
 4using System.Linq;
 5using Itinero.Indexes;
 6
 7namespace Itinero.IO.Osm;
 8
 9/// <summary>
 10/// An edge type map that keeps only OSM tags relevant for routing.
 11/// Both key AND value are validated — only known routing-relevant key-value pairs are kept.
 12/// This ensures edges with different routing characteristics get different edgeTypeIds,
 13/// while irrelevant tags are stripped to maximize deduplication.
 14/// </summary>
 15public class OsmEdgeTypeMap : AttributeSetMap
 16{
 17    private static readonly ImmutableDictionary<string, ImmutableHashSet<string>> RoutingTags;
 18
 19    static OsmEdgeTypeMap()
 020    {
 021        var tags = new Dictionary<string, ImmutableHashSet<string>>();
 22
 23        // access
 024        tags["access"] = Set("customers", "delivery", "designated", "destination", "dismount",
 025            "no", "permissive", "permit", "private", "service");
 026        tags["bicycle"] = Set("designated", "dismount", "no", "official", "permissive",
 027            "permit", "private", "use_sidepath", "yes");
 028        tags["foot"] = Set("designated", "no", "official", "permissive", "permit",
 029            "private", "use_sidepath", "yes");
 030        tags["hgv"] = Set("no", "permissive", "permit", "private", "yes");
 031        tags["motor_vehicle"] = Set("customers", "destination", "no", "permissive",
 032            "permit", "private", "yes");
 033        tags["motorcar"] = Set("customers", "destination", "no", "permissive",
 034            "permit", "private", "yes");
 035        tags["emergency"] = Set("yes");
 036        tags["motorroad"] = Set("yes");
 037        tags["area"] = Set("yes");
 38
 39        // road classification — wildcard, accept any value
 040        tags["highway"] = ImmutableHashSet<string>.Empty;
 041        tags["route"] = ImmutableHashSet<string>.Empty;
 42
 043        tags["service"] = Set("alley", "bus", "driveway", "parking_aisle");
 044        tags["tracktype"] = Set("grade1", "grade2", "grade3", "grade4", "grade5");
 045        tags["railway"] = Set("abandoned");
 46
 47        // direction
 048        tags["oneway"] = Set("-1", "1", "no", "yes");
 049        tags["oneway:bicycle"] = Set("-1", "1", "no", "yes");
 050        tags["oneway:foot"] = Set("yes");
 051        tags["junction"] = Set("roundabout");
 52
 53        // speed — wildcard, validated as integer
 054        tags["maxspeed"] = ImmutableHashSet<string>.Empty;
 55
 56        // surface
 057        tags["surface"] = Set("asphalt", "cobblestone", "compacted", "concrete",
 058            "concrete:lanes", "concrete:plates", "dirt", "earth", "fine_gravel",
 059            "grass", "grass_paver", "gravel", "ground", "metal", "mud", "paved",
 060            "paving_stones", "pebblestone", "sand", "sett", "snow",
 061            "unhewn_cobblestone", "unpaved", "wood", "woodchips");
 062        tags["smoothness"] = Set("bad", "excellent", "good", "intermediate", "very_good");
 063        tags["sidewalk:surface"] = Set("asphalt", "concrete", "paving_stones", "sett");
 64
 65        // cycling
 066        tags["cycleway"] = Set("lane", "opposite", "opposite_lane", "opposite_share_busway",
 067            "opposite_track", "right", "share_busway", "shared", "shared_lane",
 068            "track", "yes");
 069        tags["cycleway:left"] = Set("lane", "opposite", "opposite_lane", "opposite_track",
 070            "share_busway", "shared", "shared_lane", "track", "yes");
 071        tags["cycleway:right"] = Set("lane", "share_busway", "shared", "shared_lane",
 072            "track", "yes");
 073        tags["cycleway:left:oneway"] = Set("no");
 074        tags["cycleway:right:oneway"] = Set("no");
 075        tags["cyclestreet"] = Set("yes");
 076        tags["cycle_highway"] = ImmutableHashSet<string>.Empty;
 077        tags["bicycle:class"] = Set("-1", "-2", "-3", "0", "1", "2", "3");
 078        tags["ramp:bicycle"] = Set("yes");
 079        tags["towpath"] = Set("yes");
 080        tags["designation"] = Set("towpath");
 81
 82        // barriers
 083        tags["barrier"] = Set("bollard", "sump_buster");
 84
 85        // incline
 086        tags["incline"] = Set("-10%", "-20%", "-30%", "0", "0%", "10%", "20%", "30%",
 087            "down", "up");
 88
 89        // other routing-relevant — wildcards
 090        tags["type"] = ImmutableHashSet<string>.Empty;
 091        tags["network:type"] = ImmutableHashSet<string>.Empty;
 092        tags["operator"] = ImmutableHashSet<string>.Empty;
 093        tags["state"] = ImmutableHashSet<string>.Empty;
 94
 095        RoutingTags = tags.ToImmutableDictionary();
 096    }
 97
 98    /// <summary>
 99    /// Creates a new OSM edge type map with the default set of routing-relevant tags.
 100    /// </summary>
 101    public OsmEdgeTypeMap()
 0102        : base(new Guid("45d22274-cb26-490c-9685-aab0ef7d7e9c"))
 0103    {
 0104    }
 105
 106    /// <inheritdoc/>
 107    public override IEnumerable<(string key, string value)> Map(
 108        IEnumerable<(string key, string value)> attributes)
 0109    {
 0110        return attributes.Where(a => IsRelevant(a.key, a.value));
 0111    }
 112
 113    /// <summary>
 114    /// Returns true if the key-value pair is relevant for routing.
 115    /// </summary>
 116    private static bool IsRelevant(string key, string value)
 0117    {
 0118        if (!RoutingTags.TryGetValue(key, out var allowedValues)) return false;
 119
 120        // if allowed values are specified, check membership.
 0121        if (allowedValues.Count > 0) return allowedValues.Contains(value);
 122
 123        // wildcard keys — custom validation per key.
 0124        return key switch
 0125        {
 0126            "maxspeed" => int.TryParse(value, out _),
 0127            _ => true
 0128        };
 0129    }
 130
 131    private static ImmutableHashSet<string> Set(params string[] values)
 0132    {
 0133        return values.ToImmutableHashSet();
 0134    }
 135}