Compare commits
2 Commits
2ba8bca590
...
207df8dcd7
Author | SHA1 | Date | |
---|---|---|---|
207df8dcd7 | |||
d769cfda64 |
36
OSM_Graph/Enums/HighwayType.cs
Normal file
36
OSM_Graph/Enums/HighwayType.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
|
namespace OSM_Graph.Enums;
|
||||||
|
|
||||||
|
public enum HighwayType
|
||||||
|
{
|
||||||
|
NONE,
|
||||||
|
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,
|
||||||
|
cycleway,
|
||||||
|
construction
|
||||||
|
}
|
6
OSM_Graph/Enums/WayDirection.cs
Normal file
6
OSM_Graph/Enums/WayDirection.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
namespace OSM_Graph.Enums;
|
||||||
|
|
||||||
|
public enum WayDirection
|
||||||
|
{
|
||||||
|
Forwards, Backwards, Both
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using OSM_Graph.Enums;
|
||||||
|
|
||||||
namespace OSM_Graph;
|
namespace OSM_Graph;
|
||||||
|
|
||||||
@ -7,6 +8,41 @@ public class Way(ulong id, Dictionary<string, string> tags, List<ulong> nodeIds)
|
|||||||
{
|
{
|
||||||
public readonly ulong ID = id;
|
public readonly ulong ID = id;
|
||||||
public readonly List<ulong> NodeIds = nodeIds;
|
public readonly List<ulong> NodeIds = nodeIds;
|
||||||
|
|
||||||
|
public WayDirection GetDirection()
|
||||||
|
{
|
||||||
|
if (Tags.TryGetValue("oneway", out string? onewayStr))
|
||||||
|
return onewayStr switch
|
||||||
|
{
|
||||||
|
"yes" => WayDirection.Forwards,
|
||||||
|
"1" => WayDirection.Forwards,
|
||||||
|
"no" => WayDirection.Both,
|
||||||
|
"-1" => WayDirection.Backwards,
|
||||||
|
_ => WayDirection.Both
|
||||||
|
};
|
||||||
|
HighwayType[] impliedTypes = [HighwayType.motorway, HighwayType.motorway_link];
|
||||||
|
if (impliedTypes.Contains(GetHighwayType()))
|
||||||
|
return WayDirection.Forwards;
|
||||||
|
return WayDirection.Both;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HighwayType GetHighwayType()
|
||||||
|
{
|
||||||
|
if (!Tags.TryGetValue("highway", out string? highwayTypeStr))
|
||||||
|
return HighwayType.NONE;
|
||||||
|
if (!Enum.TryParse(highwayTypeStr, out HighwayType highwayType))
|
||||||
|
return HighwayType.NONE;
|
||||||
|
return highwayType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte GetMaxSpeed()
|
||||||
|
{
|
||||||
|
if (!Tags.TryGetValue("maxspeed", out string? maxSpeedStr))
|
||||||
|
return 0;
|
||||||
|
if (!byte.TryParse(maxSpeedStr, out byte speed))
|
||||||
|
return 0;
|
||||||
|
return speed;
|
||||||
|
}
|
||||||
|
|
||||||
public string Serialize()
|
public string Serialize()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user