Fixing one-way issue

This commit is contained in:
2023-04-09 22:10:23 +02:00
parent 5289020d44
commit 14533c150f
3 changed files with 62 additions and 41 deletions

View File

@@ -41,49 +41,59 @@ public class Tag
}
}
public static Tag? ConvertToTag(string key, string value)
public static HashSet<Tag> ConvertToTags(string key, string value)
{
HashSet<Tag> ret = new HashSet<Tag>();
switch (key)
{
case "highway":
try
{
return new Tag(TagType.highway, (WayType)Enum.Parse(typeof(WayType), value, true));
ret.Add(new Tag(TagType.highway, (WayType)Enum.Parse(typeof(WayType), value, true)));
}
catch (ArgumentException)
{
return new Tag(TagType.highway, WayType.unclassified);
ret.Add(new Tag(TagType.highway, WayType.unclassified));
}
break;
case "maxspeed":
try
{
byte speed = Convert.ToByte(value);
if (speed == 255)
return new Tag(TagType.highway, false);
else
return new Tag(TagType.maxspeed, speed);
if (speed != 255)
ret.Add(new Tag(TagType.maxspeed, speed));
break;
}
catch (Exception)
{
//Console.WriteLine(e);
//Console.WriteLine("Continuing...");
return new Tag(TagType.maxspeed, byte.MaxValue);
ret.Add(new Tag(TagType.maxspeed, byte.MinValue));
}
break;
case "oneway":
switch (value)
{
case "yes":
return new Tag(TagType.oneway, true);
ret.Add(new Tag(TagType.oneway, true));
break;
case "-1":
return new Tag(TagType.forward, false);
ret.Add(new Tag(TagType.forward, false));
ret.Add(new Tag(TagType.oneway, true));
break;
case "no":
return new Tag(TagType.oneway, false);
ret.Add(new Tag(TagType.oneway, false));
break;
}
return null;
case "name":
ret.Add(new Tag(TagType.name, value));
break;
case "ref":
ret.Add(new Tag(TagType.tagref, value));
break;
}
return null;
return ret;
}
public override string ToString()
@@ -93,7 +103,7 @@ public class Tag
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, tagref
}
public static readonly Dictionary<WayType, byte> defaultSpeedCar = new() {
@@ -104,8 +114,8 @@ public class Tag
{ WayType.primary, 65 },
{ WayType.secondary, 60 },
{ WayType.tertiary, 50 },
{ WayType.unclassified, 15 },
{ WayType.residential, 10 },
{ WayType.unclassified, 30 },
{ WayType.residential, 15 },
{ WayType.motorway_link, 60 },
{ WayType.trunk_link, 50 },
{ WayType.primary_link, 50 },

View File

@@ -25,9 +25,9 @@ public class TagManager
public void AddTag(ulong wayId, string key, string value)
{
Tag? tag = Tag.ConvertToTag(key, value);
if(tag is not null)
AddTag(wayId, tag);
HashSet<Tag> pTags = Tag.ConvertToTags(key, value);
foreach (Tag pTag in pTags)
AddTag(wayId, pTag);
}
public void AddTag(ulong wayId, Tag tag)