From 4057554c7d9a8fd13619c59fe59c1b009b38f9da Mon Sep 17 00:00:00 2001 From: C9Glax <13404778+C9Glax@users.noreply.github.com> Date: Tue, 7 Feb 2023 23:52:57 +0100 Subject: [PATCH] Added constructor with tags import --- OSMDatastructure/OSMEdge.cs | 48 +++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/OSMDatastructure/OSMEdge.cs b/OSMDatastructure/OSMEdge.cs index 8d048b5..6272cac 100644 --- a/OSMDatastructure/OSMEdge.cs +++ b/OSMDatastructure/OSMEdge.cs @@ -9,14 +9,24 @@ public class OsmEdge { this.neighborCoordinates = new Coordinates(lat, lon); this.tags = new(); - //TODO tags } public OsmEdge(Coordinates neighborCoordinates) { this.neighborCoordinates = neighborCoordinates; this.tags = new(); - //TODO tags + } + + public OsmEdge(float lat, float lon, Dictionary tags) + { + this.neighborCoordinates = new Coordinates(lat, lon); + this.tags = tags; + } + + public OsmEdge(Coordinates neighborCoordinates, Dictionary tags) + { + this.neighborCoordinates = neighborCoordinates; + this.tags = tags; } public enum tagType : byte @@ -92,47 +102,49 @@ public class OsmEdge 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); + } + + public static KeyValuePair ConvertToTag(string key, string value) { switch (key) { case "highway": try { - this.tags.Add(tagType.highway, (wayType)Enum.Parse(typeof(wayType), value, true)); + return new KeyValuePair(tagType.highway, (wayType)Enum.Parse(typeof(wayType), value, true)); } catch (ArgumentException) - { - //TODO + { + return new KeyValuePair(tagType.highway, wayType.unclassified); } - break; case "maxspeed": try { - this.tags.Add(tagType.maxspeed, Convert.ToByte(value)); + return new KeyValuePair(tagType.maxspeed, Convert.ToByte(value)); } - catch (Exception) + catch (FormatException) { - //TODO + return new KeyValuePair(tagType.maxspeed, byte.MaxValue); } - break; case "oneway": switch (value) { case "yes": - this.tags.Add(tagType.oneway, true); - break; + return new KeyValuePair(tagType.oneway, true); case "-1": - this.tags.Add(tagType.forward, false); - break; + return new KeyValuePair(tagType.forward, false); case "no": - this.tags.Add(tagType.oneway, false); - break; + return new KeyValuePair(tagType.oneway, false); } break; case "id": - this.tags.Add(tagType.id, Convert.ToUInt64(value)); - break; + return new KeyValuePair(tagType.id, Convert.ToUInt64(value)); } + + throw new Exception();//TODO } public ulong GetId()