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