Added constructor with tags import

This commit is contained in:
C9Glax 2023-02-07 23:52:57 +01:00
parent 0a9d5cfdfb
commit 4057554c7d

View File

@ -9,14 +9,24 @@ public class OsmEdge
{
this.neighborCoordinates = new Coordinates(lat, lon);
this.tags = new();
//TODO tags
}
public OsmEdge(Coordinates neighborCoordinates)
{
this.neighborCoordinates = neighborCoordinates;
this.tags = new();
//TODO tags
}
public OsmEdge(float lat, float lon, Dictionary<tagType, object> tags)
{
this.neighborCoordinates = new Coordinates(lat, lon);
this.tags = tags;
}
public OsmEdge(Coordinates neighborCoordinates, Dictionary<tagType, object> tags)
{
this.neighborCoordinates = neighborCoordinates;
this.tags = tags;
}
public enum tagType : byte
@ -92,47 +102,49 @@ public class OsmEdge
public enum speedType { pedestrian, car, road }
public void AddTag(string key, string value)
{
KeyValuePair<tagType, object> tag = ConvertToTag(key, value);
this.tags.Add(tag.Key, tag.Value);
}
public static KeyValuePair<tagType, object> ConvertToTag(string key, string value)
{
switch (key)
{
case "highway":
try
{
this.tags.Add(tagType.highway, (wayType)Enum.Parse(typeof(wayType), value, true));
return new KeyValuePair<tagType, object>(tagType.highway, (wayType)Enum.Parse(typeof(wayType), value, true));
}
catch (ArgumentException)
{
//TODO
{
return new KeyValuePair<tagType, object>(tagType.highway, wayType.unclassified);
}
break;
case "maxspeed":
try
{
this.tags.Add(tagType.maxspeed, Convert.ToByte(value));
return new KeyValuePair<tagType, object>(tagType.maxspeed, Convert.ToByte(value));
}
catch (Exception)
catch (FormatException)
{
//TODO
return new KeyValuePair<tagType, object>(tagType.maxspeed, byte.MaxValue);
}
break;
case "oneway":
switch (value)
{
case "yes":
this.tags.Add(tagType.oneway, true);
break;
return new KeyValuePair<tagType, object>(tagType.oneway, true);
case "-1":
this.tags.Add(tagType.forward, false);
break;
return new KeyValuePair<tagType, object>(tagType.forward, false);
case "no":
this.tags.Add(tagType.oneway, false);
break;
return new KeyValuePair<tagType, object>(tagType.oneway, false);
}
break;
case "id":
this.tags.Add(tagType.id, Convert.ToUInt64(value));
break;
return new KeyValuePair<tagType, object>(tagType.id, Convert.ToUInt64(value));
}
throw new Exception();//TODO
}
public ulong GetId()