101 lines
3.4 KiB
C#
101 lines
3.4 KiB
C#
|
namespace OSMImporter
|
||
|
{
|
||
|
public class Connection
|
||
|
{
|
||
|
public ulong endNodeId { get; }
|
||
|
|
||
|
private readonly Dictionary<tagType, object> _tags = new Dictionary<tagType, object>();
|
||
|
|
||
|
public enum tagType
|
||
|
{
|
||
|
highway, oneway, footway, sidewalk, cycleway, busway, forward, maxspeed, unknown
|
||
|
}
|
||
|
|
||
|
public Connection(ulong endNodeId)
|
||
|
{
|
||
|
this.endNodeId = endNodeId;
|
||
|
}
|
||
|
|
||
|
public Connection(ulong endNodeId, Dictionary<string, string> tags)
|
||
|
{
|
||
|
this.endNodeId = endNodeId;
|
||
|
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))
|
||
|
{
|
||
|
this._tags.Add(tagType.oneway, true);
|
||
|
}
|
||
|
else if (value.Equals("no", StringComparison.CurrentCultureIgnoreCase))
|
||
|
{
|
||
|
this._tags.Add(tagType.oneway, false);
|
||
|
}
|
||
|
else if (value.Equals("reversible", StringComparison.CurrentCultureIgnoreCase))
|
||
|
{
|
||
|
this._tags.Add(tagType.oneway, true);
|
||
|
this._tags.Add(tagType.forward, false);
|
||
|
}
|
||
|
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":
|
||
|
if(Enum.TryParse(value, out buswayType bwType))
|
||
|
this._tags.Add(tagType.footway, bwType);
|
||
|
break;
|
||
|
case "maxspeed":
|
||
|
this._tags.Add(tagType.maxspeed, Convert.ToByte(value));
|
||
|
break;
|
||
|
default:
|
||
|
this._tags.Add(tagType.unknown, value);
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public byte[] ToByte() //TODO Current Size sizeof(ulong)
|
||
|
{
|
||
|
//TODO Tags
|
||
|
byte[] ret = new byte[sizeof(ulong)];
|
||
|
Buffer.BlockCopy(new []{ this.endNodeId }, 0, ret, 0, ret.Length );
|
||
|
return ret;
|
||
|
}
|
||
|
}
|
||
|
}
|