From e57912c58987f6e797554466ba775a90f8ac54f7 Mon Sep 17 00:00:00 2001 From: C9Glax <13404778+C9Glax@users.noreply.github.com> Date: Wed, 8 Feb 2023 18:49:21 +0100 Subject: [PATCH] OSMEdge.cs: + GetWeight() + override toString() fixed maxSpeedValue 255 -> returns now empty --- OSMDatastructure/OSMEdge.cs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/OSMDatastructure/OSMEdge.cs b/OSMDatastructure/OSMEdge.cs index ebc5da8..6a6377b 100644 --- a/OSMDatastructure/OSMEdge.cs +++ b/OSMDatastructure/OSMEdge.cs @@ -133,8 +133,12 @@ public class OsmEdge } case "maxspeed": try - { - return new KeyValuePair(tagType.maxspeed, Convert.ToByte(value)); + { + byte speed = Convert.ToByte(value); + if(speed == 255) + return new KeyValuePair(tagType.EMPTY, 0); + else + return new KeyValuePair(tagType.maxspeed, speed); } catch (Exception) { @@ -193,4 +197,30 @@ public class OsmEdge { return this.tags.ContainsKey(tagType.forward) && (bool)this.tags[tagType.forward]; } + + public double GetWeight(OsmNode parentNode, speedType vehicle) + { + double distance = Utils.DistanceBetween(parentNode, neighborCoordinates); + byte? speedByte = GetMaxSpeed(vehicle); + if (speedByte != null && speedByte > 0) + { + double speed = Convert.ToDouble(speedByte); + return distance / (speed * 1000 / 360); + } + else + { + return double.MaxValue; + } + } + + public override string ToString() + { + string tagsString = ""; + foreach (KeyValuePair tag in tags) + { + tagsString += string.Format("\n\t{0}: {1}", tag.Key, tag.Value); + } + + return string.Format("EDGE neighborCoordinates: {0} {1}", neighborCoordinates.ToString(), tagsString); + } } \ No newline at end of file