From 9ce3bc4a9d8cdaa177c3ef377f6512ac421d8367 Mon Sep 17 00:00:00 2001 From: C9Glax <13404778+C9Glax@users.noreply.github.com> Date: Thu, 2 Feb 2023 22:30:53 +0100 Subject: [PATCH] Added TagTypes --- OSMImporter/Connection.cs | 101 +++++++++++++++++++++++++++++++++++++ OSMImporter/highwayType.cs | 67 ++++++++++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 OSMImporter/Connection.cs create mode 100644 OSMImporter/highwayType.cs diff --git a/OSMImporter/Connection.cs b/OSMImporter/Connection.cs new file mode 100644 index 0000000..c9ab581 --- /dev/null +++ b/OSMImporter/Connection.cs @@ -0,0 +1,101 @@ +namespace OSMImporter +{ + public class Connection + { + public ulong endNodeId { get; } + + private readonly Dictionary _tags = new Dictionary(); + + public enum tagType + { + highway, oneway, footway, sidewalk, cycleway, busway, forward, maxspeed, unknown + } + + public Connection(ulong endNodeId) + { + this.endNodeId = endNodeId; + } + + public Connection(ulong endNodeId, Dictionary tags) + { + this.endNodeId = endNodeId; + 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, true); + } + else if (value.Equals("no", StringComparison.CurrentCultureIgnoreCase)) + { + this._tags.Add(tagType.oneway, false); + } + else if (value.Equals("reversible", StringComparison.CurrentCultureIgnoreCase)) + { + this._tags.Add(tagType.oneway, true); + this._tags.Add(tagType.forward, false); + } + 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": + if(Enum.TryParse(value, out buswayType bwType)) + this._tags.Add(tagType.footway, bwType); + break; + case "maxspeed": + this._tags.Add(tagType.maxspeed, Convert.ToByte(value)); + break; + default: + this._tags.Add(tagType.unknown, 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 byte[] ToByte() //TODO Current Size sizeof(ulong) + { + //TODO Tags + byte[] ret = new byte[sizeof(ulong)]; + Buffer.BlockCopy(new []{ this.endNodeId }, 0, ret, 0, ret.Length ); + return ret; + } + } +} \ No newline at end of file diff --git a/OSMImporter/highwayType.cs b/OSMImporter/highwayType.cs new file mode 100644 index 0000000..cd6a315 --- /dev/null +++ b/OSMImporter/highwayType.cs @@ -0,0 +1,67 @@ +namespace OSMImporter +{ + public enum highwayType + { + 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, + via_ferratsa, + cycleway, + proposed, + construction + } + + public enum footwayType + { + sidewalk, + crossing + } + + public enum cyclewayType + { + lane, + opposite, + opposite_lane, + track, + opposite_track, + share_busway, + opposite_share_busway, + shared_lane + } + + public enum sidewalkSide + { + both, + left, + right, + no + } + + public enum buswayType + { + lane + } +} \ No newline at end of file