OSMEdge.cs:

+ GetWeight()
+ override toString()
  fixed maxSpeedValue 255 -> returns now empty
This commit is contained in:
C9Glax 2023-02-08 18:49:21 +01:00
parent aceecee07e
commit e57912c589

View File

@ -133,8 +133,12 @@ public class OsmEdge
} }
case "maxspeed": case "maxspeed":
try try
{ {
return new KeyValuePair<tagType, object>(tagType.maxspeed, Convert.ToByte(value)); byte speed = Convert.ToByte(value);
if(speed == 255)
return new KeyValuePair<tagType, object>(tagType.EMPTY, 0);
else
return new KeyValuePair<tagType, object>(tagType.maxspeed, speed);
} }
catch (Exception) catch (Exception)
{ {
@ -193,4 +197,30 @@ public class OsmEdge
{ {
return this.tags.ContainsKey(tagType.forward) && (bool)this.tags[tagType.forward]; 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<tagType, object> tag in tags)
{
tagsString += string.Format("\n\t{0}: {1}", tag.Key, tag.Value);
}
return string.Format("EDGE neighborCoordinates: {0} {1}", neighborCoordinates.ToString(), tagsString);
}
} }