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.neighborCoordinates = new Coordinates(lat, lon);
this.tags = new(); this.tags = new();
//TODO tags
} }
public OsmEdge(Coordinates neighborCoordinates) public OsmEdge(Coordinates neighborCoordinates)
{ {
this.neighborCoordinates = neighborCoordinates; this.neighborCoordinates = neighborCoordinates;
this.tags = new(); 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 public enum tagType : byte
@ -92,47 +102,49 @@ public class OsmEdge
public enum speedType { pedestrian, car, road } public enum speedType { pedestrian, car, road }
public void AddTag(string key, string value) 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) switch (key)
{ {
case "highway": case "highway":
try 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) catch (ArgumentException)
{ {
//TODO return new KeyValuePair<tagType, object>(tagType.highway, wayType.unclassified);
} }
break;
case "maxspeed": case "maxspeed":
try 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": case "oneway":
switch (value) switch (value)
{ {
case "yes": case "yes":
this.tags.Add(tagType.oneway, true); return new KeyValuePair<tagType, object>(tagType.oneway, true);
break;
case "-1": case "-1":
this.tags.Add(tagType.forward, false); return new KeyValuePair<tagType, object>(tagType.forward, false);
break;
case "no": case "no":
this.tags.Add(tagType.oneway, false); return new KeyValuePair<tagType, object>(tagType.oneway, false);
break;
} }
break; break;
case "id": case "id":
this.tags.Add(tagType.id, Convert.ToUInt64(value)); return new KeyValuePair<tagType, object>(tagType.id, Convert.ToUInt64(value));
break;
} }
throw new Exception();//TODO
} }
public ulong GetId() public ulong GetId()