using System; using System.Collections.Generic; namespace HeuristicLab.Problems.RoutePlanning.Osm { #region Highway Types // see: https://wiki.openstreetmap.org/wiki/Key:highway public enum HighwayType { null_type, motorway, motorway_link, trunk, trunk_link, primary, primary_link, secondary, secondary_link, tertiary, tertiary_link, living_street, pedestrian, residential, unclassified, service, track, bus_guideway, raceway, road, path, footway, cycleway, bridleway, steps } #endregion public class Way : OsmBase { private List nodes; public Way() { nodes = new List(); } public Way(long id) : base(id) { nodes = new List(); } public List Nodes { get { return nodes; } } public HighwayType HighwayTag { get { if (!base.Tags.ContainsKey(TagConstants.HighwayTagKey)) { return HighwayType.null_type; } if (Enum.IsDefined(typeof(HighwayType), base.Tags[TagConstants.HighwayTagKey])) { HighwayType ht = (HighwayType)Enum.Parse( typeof(HighwayType), base.Tags[TagConstants.HighwayTagKey], true); return ht; } else { return HighwayType.null_type; } } } public bool OneWay { get { if (base.Tags.ContainsKey(TagConstants.OneWayTag)) { string value = base.Tags[TagConstants.OneWayTag]; return value.Equals(TagConstants.YesValue); } else { return false; } } } public bool CanBeTraversed(Node source, Node target) { // check if way can be traveld by a specific vehicle (car, public transport, pedestiran, bicycle) // if (!CanBeTraversed(Vehicle)) return false if (OneWay) { // if vehicle == pedestrian or bicylce -> return true int sourceIndex = Nodes.IndexOf(source); int targetIndex = Nodes.IndexOf(target); // order of the nodes determines the driving direction return (sourceIndex < targetIndex); } return true; } //public bool CanBeTraversed(Vehicle) {} public int GetMaxSpeed() { int speed = 0; //TODO: HighwayType highwayType = HighwayTag; switch (highwayType) { case HighwayType.bridleway: case HighwayType.bus_guideway: case HighwayType.raceway: case HighwayType.cycleway: case HighwayType.footway: case HighwayType.steps: case HighwayType.null_type: speed = 1; break; case HighwayType.path: case HighwayType.service: case HighwayType.pedestrian: case HighwayType.living_street: speed = 15; break; case HighwayType.road: case HighwayType.track: speed = 30; break; case HighwayType.tertiary: case HighwayType.tertiary_link: case HighwayType.secondary: case HighwayType.secondary_link: speed = 80; break; case HighwayType.unclassified: case HighwayType.residential: speed = 50; break; case HighwayType.trunk: case HighwayType.trunk_link: case HighwayType.primary: case HighwayType.primary_link: speed = 100; break; case HighwayType.motorway: case HighwayType.motorway_link: speed = 130; break; default: speed = 1; break; } return speed; } } }