From c182818aff9dff8cfa3b3ad6801e6cb0131ff7dd Mon Sep 17 00:00:00 2001 From: C9Glax <13404778+C9Glax@users.noreply.github.com> Date: Wed, 8 Feb 2023 18:08:42 +0100 Subject: [PATCH] enum wayType now typeof byte prevented waytype.EMPTY in tags --- OSMDatastructure/OSMEdge.cs | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/OSMDatastructure/OSMEdge.cs b/OSMDatastructure/OSMEdge.cs index 6272cac..ebc5da8 100644 --- a/OSMDatastructure/OSMEdge.cs +++ b/OSMDatastructure/OSMEdge.cs @@ -3,7 +3,7 @@ namespace OSMDatastructure; public class OsmEdge { public Coordinates neighborCoordinates { get; } - public Dictionary tags { get; } + public readonly Dictionary tags = new(); public OsmEdge(float lat, float lon) { @@ -20,18 +20,28 @@ public class OsmEdge public OsmEdge(float lat, float lon, Dictionary tags) { this.neighborCoordinates = new Coordinates(lat, lon); - this.tags = tags; + //To prevent "EMPTY" tags + foreach (KeyValuePair tag in tags) + { + if(tag.Key != tagType.EMPTY) + this.tags.Add(tag.Key, tag.Value); + } } public OsmEdge(Coordinates neighborCoordinates, Dictionary tags) { this.neighborCoordinates = neighborCoordinates; - this.tags = tags; + //To prevent "EMPTY" tags + foreach (KeyValuePair tag in tags) + { + if(tag.Key != tagType.EMPTY) + this.tags.Add(tag.Key, tag.Value); + } } public enum tagType : byte { - highway, oneway, footway, sidewalk, cycleway, busway, forward, maxspeed, name, surface, lanes, access, tracktype, id + highway, oneway, footway, sidewalk, cycleway, busway, forward, maxspeed, name, surface, lanes, access, tracktype, id, EMPTY } public static Dictionary speedcar = new() { @@ -44,8 +54,8 @@ public class OsmEdge { wayType.unclassified, 20 }, { wayType.residential, 10 }, { wayType.motorway_link, 50 }, - {wayType.trunk_link, 50 }, - {wayType.primary_link, 30 }, + { wayType.trunk_link, 50 }, + { wayType.primary_link, 30 }, { wayType.secondary_link, 25 }, { wayType.tertiary_link, 25 }, { wayType.living_street, 10 }, @@ -97,14 +107,15 @@ public class OsmEdge { 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 wayType : byte { 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) { KeyValuePair tag = ConvertToTag(key, value); - this.tags.Add(tag.Key, tag.Value); + if(tag.Key != tagType.EMPTY) + this.tags.Add(tag.Key, tag.Value); } public static KeyValuePair ConvertToTag(string key, string value) @@ -125,8 +136,10 @@ public class OsmEdge { return new KeyValuePair(tagType.maxspeed, Convert.ToByte(value)); } - catch (FormatException) + catch (Exception) { + //Console.WriteLine(e); + //Console.WriteLine("Continuing..."); return new KeyValuePair(tagType.maxspeed, byte.MaxValue); } case "oneway": @@ -143,8 +156,7 @@ public class OsmEdge case "id": return new KeyValuePair(tagType.id, Convert.ToUInt64(value)); } - - throw new Exception();//TODO + return new KeyValuePair(tagType.EMPTY, 0); } public ulong GetId()