From 2c18162398d5b1475bceee8686f23fef67407591 Mon Sep 17 00:00:00 2001 From: C9Glax <13404778+C9Glax@users.noreply.github.com> Date: Sun, 5 Feb 2023 20:45:53 +0100 Subject: [PATCH] tags adding TryAdd instead of Add --- OSMDatastructure/Connection.cs | 52 ++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/OSMDatastructure/Connection.cs b/OSMDatastructure/Connection.cs index 717db11..d497e05 100644 --- a/OSMDatastructure/Connection.cs +++ b/OSMDatastructure/Connection.cs @@ -32,40 +32,47 @@ namespace OSMDatastructure { case "highway": if(Enum.TryParse(value, out highwayType hwType)) - this._tags.Add(key: tagType.highway, hwType); + this._tags.TryAdd(key: tagType.highway, hwType); break; case "footway": if(Enum.TryParse(value, out footwayType fwType)) - this._tags.Add(tagType.footway, fwType); + this._tags.TryAdd(tagType.footway, fwType); break; case "oneway": if (value.Equals("yes", StringComparison.CurrentCultureIgnoreCase)) { - this._tags.Add(tagType.oneway, (byte)1); + this._tags.TryAdd(tagType.oneway, (byte)1); } else if (value.Equals("no", StringComparison.CurrentCultureIgnoreCase)) { - this._tags.Add(tagType.oneway, (byte)0); + this._tags.TryAdd(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); + 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.Add(tagType.footway, swType); + this._tags.TryAdd(tagType.footway, swType); break; case "cycleway": if(Enum.TryParse(value, out cyclewayType cwType)) - this._tags.Add(tagType.footway, cwType); + this._tags.TryAdd(tagType.footway, cwType); break; case "busway": //TODO break; case "maxspeed": - this._tags.Add(tagType.maxspeed, Convert.ToByte(value)); + 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 @@ -93,25 +100,40 @@ namespace OSMDatastructure switch ((tagType)tag) { case tagType.highway: - this._tags.Add(tagType.highway, (highwayType)value); + this._tags.TryAdd(tagType.highway, (highwayType)value); break; case tagType.footway: - this._tags.Add(tagType.footway, (footwayType)value); + this._tags.TryAdd(tagType.footway, (footwayType)value); break; case tagType.oneway: - this._tags.Add(tagType.oneway, value); + this._tags.TryAdd(tagType.oneway, value); break; case tagType.sidewalk: - this._tags.Add(tagType.sidewalk, (sidewalkSide)value); + this._tags.TryAdd(tagType.sidewalk, (sidewalkSide)value); break; case tagType.cycleway: - this._tags.Add(tagType.cycleway, (cyclewayType)value); + this._tags.TryAdd(tagType.cycleway, (cyclewayType)value); break; case tagType.busway: //TODO break; case tagType.maxspeed: - this._tags.Add(tagType.maxspeed, value); + 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; } }