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.Add(key: tagType.highway, hwType); break; case "footway": if(Enum.TryParse(value, out footwayType fwType)) this._tags.Add(tagType.footway, fwType); break; case "oneway": if (value.Equals("yes", StringComparison.CurrentCultureIgnoreCase)) { this._tags.Add(tagType.oneway, (byte)1); } else if (value.Equals("no", StringComparison.CurrentCultureIgnoreCase)) { this._tags.Add(tagType.oneway, (byte)0); } else if (value.Equals("reversible", StringComparison.CurrentCultureIgnoreCase)) { this._tags.Add(tagType.oneway, (byte)1); this._tags.Add(tagType.forward, (byte)0); } break; case "sidewalk": if(Enum.TryParse(value, out sidewalkSide swType)) this._tags.Add(tagType.footway, swType); break; case "cycleway": if(Enum.TryParse(value, out cyclewayType cwType)) this._tags.Add(tagType.footway, cwType); break; case "busway": //TODO break; case "maxspeed": this._tags.Add(tagType.maxspeed, Convert.ToByte(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.Add(tagType.highway, (highwayType)value); break; case tagType.footway: this._tags.Add(tagType.footway, (footwayType)value); break; case tagType.oneway: this._tags.Add(tagType.oneway, value); break; case tagType.sidewalk: this._tags.Add(tagType.sidewalk, (sidewalkSide)value); break; case tagType.cycleway: this._tags.Add(tagType.cycleway, (cyclewayType)value); break; case tagType.busway: //TODO break; case tagType.maxspeed: this._tags.Add(tagType.maxspeed, value); 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; } } }