OSMServer/OSMDatastructure/Connection.cs

144 lines
4.9 KiB
C#
Raw Normal View History

namespace OSMDatastructure
2023-02-02 22:30:53 +01:00
{
public class Connection
{
public ulong endNodeId { get; }
public Coordinates endNodeCoordinates { get; }
2023-02-02 22:30:53 +01:00
private readonly Dictionary<tagType, object> _tags = new();
2023-02-02 22:30:53 +01:00
2023-02-03 00:02:04 +01:00
public enum tagType : byte
2023-02-02 22:30:53 +01:00
{
highway, oneway, footway, sidewalk, cycleway, busway, forward, maxspeed, name, surface, lanes, access, tracktype
2023-02-02 22:30:53 +01:00
}
public Connection(ulong endNodeId, Coordinates endNodeCoordinates)
2023-02-02 22:30:53 +01:00
{
this.endNodeId = endNodeId;
this.endNodeCoordinates = endNodeCoordinates;
2023-02-02 22:30:53 +01:00
}
public Connection(ulong endNodeId, Coordinates endNodeCoordinates, Dictionary<string, string> tags)
2023-02-02 22:30:53 +01:00
{
this.endNodeId = endNodeId;
this.endNodeCoordinates = endNodeCoordinates;
2023-02-02 22:30:53 +01:00
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))
{
2023-02-03 00:02:04 +01:00
this._tags.Add(tagType.oneway, (byte)1);
2023-02-02 22:30:53 +01:00
}
else if (value.Equals("no", StringComparison.CurrentCultureIgnoreCase))
{
2023-02-03 00:02:04 +01:00
this._tags.Add(tagType.oneway, (byte)0);
2023-02-02 22:30:53 +01:00
}
else if (value.Equals("reversible", StringComparison.CurrentCultureIgnoreCase))
{
2023-02-03 00:02:04 +01:00
this._tags.Add(tagType.oneway, (byte)1);
this._tags.Add(tagType.forward, (byte)0);
2023-02-02 22:30:53 +01:00
}
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":
//TODO
2023-02-02 22:30:53 +01:00
break;
case "maxspeed":
this._tags.Add(tagType.maxspeed, Convert.ToByte(value));
break;
case "name":
//TODO
break;
case "surface":
//TODO
break;
case "lanes":
//TODO
break;
case "access":
//TODO
break;
case "tracktype":
//TODO
break;
2023-02-02 22:30:53 +01:00
default:
2023-02-03 00:02:04 +01:00
Console.WriteLine("Unknown Tag: {0} Value: {1}", key, value);
break;
}
}
public void AddTag(byte tag, byte value)
{
switch ((tagType)tag)
{
case tagType.highway:
this._tags.Add(tagType.highway, (highwayType)value);
break;
case tagType.footway:
this._tags.Add(tagType.footway, (footwayType)value);
break;
case tagType.oneway:
this._tags.Add(tagType.oneway, value);
break;
case tagType.sidewalk:
this._tags.Add(tagType.sidewalk, (sidewalkSide)value);
break;
case tagType.cycleway:
this._tags.Add(tagType.cycleway, (cyclewayType)value);
break;
case tagType.busway:
//TODO
2023-02-03 00:02:04 +01:00
break;
case tagType.maxspeed:
this._tags.Add(tagType.maxspeed, value);
2023-02-02 22:30:53 +01:00
break;
}
}
private void ImportTags(Dictionary<string, string> tags)
{
foreach (KeyValuePair<string, string> 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;
}
}
2023-02-03 00:02:04 +01:00
public Dictionary<tagType, object> GetTags()
{
return this._tags;
2023-02-02 22:30:53 +01:00
}
}
}