namespace OSMDatastructure; public class OsmEdge { public Coordinates neighborCoordinates { get; } public Dictionary tags { get; } public OsmEdge(float lat, float lon) { this.neighborCoordinates = new Coordinates(lat, lon); this.tags = new(); //TODO tags } public OsmEdge(Coordinates neighborCoordinates) { this.neighborCoordinates = neighborCoordinates; this.tags = new(); //TODO tags } public enum tagType : byte { highway, oneway, footway, sidewalk, cycleway, busway, forward, maxspeed, name, surface, lanes, access, tracktype, id } public static Dictionary speedcar = new() { { wayType.NONE, 0 }, { wayType.motorway, 110 }, { wayType.trunk, 100 }, { wayType.primary, 80 }, { wayType.secondary, 80 }, { wayType.tertiary, 70 }, { wayType.unclassified, 20 }, { wayType.residential, 10 }, { wayType.motorway_link, 50 }, {wayType.trunk_link, 50 }, {wayType.primary_link, 30 }, { wayType.secondary_link, 25 }, { wayType.tertiary_link, 25 }, { wayType.living_street, 10 }, { wayType.service, 0 }, { wayType.pedestrian, 0 }, { wayType.track, 0 }, { wayType.bus_guideway, 0 }, { wayType.escape, 0 }, { wayType.raceway, 0 }, { wayType.road, 25 }, { wayType.busway, 0 }, { wayType.footway, 0 }, { wayType.bridleway, 0 }, { wayType.steps, 0 }, { wayType.corridor, 0 }, { wayType.path, 0 }, { wayType.cycleway, 0 }, { wayType.construction, 0 } }; public static Dictionary speedped = new() { { wayType.NONE, 0 }, { wayType.motorway, 0 }, { wayType.trunk, 0 }, { wayType.primary, 0 }, { wayType.secondary, 0 }, { wayType.tertiary, 0 }, { wayType.unclassified, 1 }, { wayType.residential, 3 }, { wayType.motorway_link, 0 }, { wayType.trunk_link, 0 }, { wayType.primary_link, 0 }, { wayType.secondary_link, 0 }, { wayType.tertiary_link, 0 }, { wayType.living_street, 5 }, { wayType.service, 2 }, { wayType.pedestrian, 5 }, { wayType.track, 0 }, { wayType.bus_guideway, 0 }, { wayType.escape, 0 }, { wayType.raceway, 0 }, { wayType.road, 3 }, { wayType.busway, 0 }, { wayType.footway, 4 }, { wayType.bridleway, 1 }, { wayType.steps, 2 }, { wayType.corridor, 3 }, { wayType.path, 4 }, { wayType.cycleway, 2 }, { wayType.construction, 0 } }; public enum wayType { NONE, motorway, trunk, primary, secondary, tertiary, unclassified, residential, motorway_link, trunk_link, primary_link, secondary_link, tertiary_link, living_street, service, pedestrian, track, bus_guideway, escape, raceway, road, busway, footway, bridleway, steps, corridor, path, cycleway, construction } public enum speedType { pedestrian, car, road } public void AddTag(string key, string value) { switch (key) { case "highway": try { this.tags.Add(tagType.highway, (wayType)Enum.Parse(typeof(wayType), value, true)); } catch (ArgumentException) { //TODO } break; case "maxspeed": try { this.tags.Add(tagType.maxspeed, Convert.ToByte(value)); } catch (Exception) { //TODO } break; case "oneway": switch (value) { case "yes": this.tags.Add(tagType.oneway, true); break; case "-1": this.tags.Add(tagType.forward, false); break; case "no": this.tags.Add(tagType.oneway, false); break; } break; case "id": this.tags.Add(tagType.id, Convert.ToUInt64(value)); break; } } public ulong GetId() { return this.tags.ContainsKey(tagType.id) ? (ulong)this.tags[tagType.id] : 0; } public wayType GetHighwayType() { return this.tags.ContainsKey(tagType.highway) ? (wayType)this.tags[tagType.highway] : wayType.NONE; } public bool IsOneWay() { return this.tags.ContainsKey(tagType.oneway) && (bool)this.tags[tagType.oneway]; } public byte? GetMaxSpeed(speedType type) { if(type == speedType.road) { return this.tags.ContainsKey(tagType.maxspeed) ? (byte)this.tags[tagType.maxspeed] : null; } if(type == speedType.car) { return this.tags.ContainsKey(tagType.maxspeed) ? (byte)this.tags[tagType.maxspeed] : speedcar[this.GetHighwayType()]; } return speedped[this.GetHighwayType()]; } public bool IsForward() { return this.tags.ContainsKey(tagType.forward) && (bool)this.tags[tagType.forward]; } }