enum wayType now typeof byte

prevented waytype.EMPTY in tags
This commit is contained in:
C9Glax 2023-02-08 18:08:42 +01:00
parent 5f4e2bb5f0
commit c182818aff

View File

@ -3,7 +3,7 @@ namespace OSMDatastructure;
public class OsmEdge
{
public Coordinates neighborCoordinates { get; }
public Dictionary<tagType, object> tags { get; }
public readonly Dictionary<tagType, object> tags = new();
public OsmEdge(float lat, float lon)
{
@ -20,18 +20,28 @@ public class OsmEdge
public OsmEdge(float lat, float lon, Dictionary<tagType, object> tags)
{
this.neighborCoordinates = new Coordinates(lat, lon);
this.tags = tags;
//To prevent "EMPTY" tags
foreach (KeyValuePair<tagType, object> tag in tags)
{
if(tag.Key != tagType.EMPTY)
this.tags.Add(tag.Key, tag.Value);
}
}
public OsmEdge(Coordinates neighborCoordinates, Dictionary<tagType, object> tags)
{
this.neighborCoordinates = neighborCoordinates;
this.tags = tags;
//To prevent "EMPTY" tags
foreach (KeyValuePair<tagType, object> tag in tags)
{
if(tag.Key != tagType.EMPTY)
this.tags.Add(tag.Key, tag.Value);
}
}
public enum tagType : byte
{
highway, oneway, footway, sidewalk, cycleway, busway, forward, maxspeed, name, surface, lanes, access, tracktype, id
highway, oneway, footway, sidewalk, cycleway, busway, forward, maxspeed, name, surface, lanes, access, tracktype, id, EMPTY
}
public static Dictionary<wayType, byte> speedcar = new() {
@ -44,8 +54,8 @@ public class OsmEdge
{ wayType.unclassified, 20 },
{ wayType.residential, 10 },
{ wayType.motorway_link, 50 },
{wayType.trunk_link, 50 },
{wayType.primary_link, 30 },
{ wayType.trunk_link, 50 },
{ wayType.primary_link, 30 },
{ wayType.secondary_link, 25 },
{ wayType.tertiary_link, 25 },
{ wayType.living_street, 10 },
@ -97,14 +107,15 @@ public class OsmEdge
{ wayType.cycleway, 2 },
{ wayType.construction, 0 }
};
public enum wayType { 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 }
public enum wayType : byte { 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 }
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);
if(tag.Key != tagType.EMPTY)
this.tags.Add(tag.Key, tag.Value);
}
public static KeyValuePair<tagType, object> ConvertToTag(string key, string value)
@ -125,8 +136,10 @@ public class OsmEdge
{
return new KeyValuePair<tagType, object>(tagType.maxspeed, Convert.ToByte(value));
}
catch (FormatException)
catch (Exception)
{
//Console.WriteLine(e);
//Console.WriteLine("Continuing...");
return new KeyValuePair<tagType, object>(tagType.maxspeed, byte.MaxValue);
}
case "oneway":
@ -143,8 +156,7 @@ public class OsmEdge
case "id":
return new KeyValuePair<tagType, object>(tagType.id, Convert.ToUInt64(value));
}
throw new Exception();//TODO
return new KeyValuePair<tagType, object>(tagType.EMPTY, 0);
}
public ulong GetId()