namespace OSMDatastructure { public class Connection { public ulong endNodeId { get; } public Coordinates endNodeCoordinates { get; } private readonly Dictionary _tags = new(); public enum tagType : byte { highway, oneway, footway, sidewalk, cycleway, busway, forward, maxspeed, name, surface, lanes, access, tracktype } public Connection(ulong endNodeId, Coordinates endNodeCoordinates) { this.endNodeId = endNodeId; this.endNodeCoordinates = endNodeCoordinates; } public Connection(ulong endNodeId, Coordinates endNodeCoordinates, Dictionary tags) { this.endNodeId = endNodeId; this.endNodeCoordinates = endNodeCoordinates; ImportTags(tags); } public void AddTag(string key, string value) { switch (key) { case "highway": if(Enum.TryParse(value, out highwayType hwType)) this._tags.TryAdd(key: tagType.highway, hwType); break; case "footway": if(Enum.TryParse(value, out footwayType fwType)) this._tags.TryAdd(tagType.footway, fwType); break; case "oneway": if (value.Equals("yes", StringComparison.CurrentCultureIgnoreCase)) { this._tags.TryAdd(tagType.oneway, (byte)1); } else if (value.Equals("no", StringComparison.CurrentCultureIgnoreCase)) { this._tags.TryAdd(tagType.oneway, (byte)0); } else if (value.Equals("reversible", StringComparison.CurrentCultureIgnoreCase)) { this._tags.TryAdd(tagType.oneway, (byte)1); this._tags.TryAdd(tagType.forward, (byte)0); } break; case "sidewalk": if(Enum.TryParse(value, out sidewalkSide swType)) this._tags.TryAdd(tagType.footway, swType); break; case "cycleway": if(Enum.TryParse(value, out cyclewayType cwType)) this._tags.TryAdd(tagType.footway, cwType); break; case "busway": //TODO break; case "maxspeed": try { this._tags.TryAdd(tagType.maxspeed, Convert.ToByte(value)); } catch (FormatException e) { Console.WriteLine("maxspeed '{0}' is not a number", value); } break; case "name": //TODO break; case "surface": //TODO break; case "lanes": //TODO break; case "access": //TODO break; case "tracktype": //TODO break; default: Console.WriteLine("Unknown Tag: {0} Value: {1}", key, value); break; } } public void AddTag(byte tag, byte value) { switch ((tagType)tag) { case tagType.highway: this._tags.TryAdd(tagType.highway, (highwayType)value); break; case tagType.footway: this._tags.TryAdd(tagType.footway, (footwayType)value); break; case tagType.oneway: this._tags.TryAdd(tagType.oneway, value); break; case tagType.sidewalk: this._tags.TryAdd(tagType.sidewalk, (sidewalkSide)value); break; case tagType.cycleway: this._tags.TryAdd(tagType.cycleway, (cyclewayType)value); break; case tagType.busway: //TODO break; case tagType.maxspeed: this._tags.TryAdd(tagType.maxspeed, value); break; case tagType.name: //TODO break; case tagType.surface: //TODO break; case tagType.lanes: //TODO break; case tagType.access: //TODO break; case tagType.tracktype: //TODO break; } } private void ImportTags(Dictionary tags) { foreach (KeyValuePair tag in tags) { this.AddTag(tag.Key, tag.Value); } } public object? GetTag(string key) { if (Enum.TryParse(key, out tagType tag)) { return this._tags.ContainsKey(tag) ? this._tags[tag] : null; } else { return null; } } public Dictionary GetTags() { return this._tags; } } }