Fixing one-way issue

This commit is contained in:
glax 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)

View File

@ -129,9 +129,9 @@ public class RegionConverter
currentTags.TryAdd(Tag.TagType.id, Convert.ToUInt64(wayReader.GetAttribute("id")!));
if (wayReader.Name == "tag")
{
Tag? wayTag = Tag.ConvertToTag(wayReader.GetAttribute("k")!, wayReader.GetAttribute("v")!);
if(wayTag is not null)
currentTags.TryAdd(wayTag.key, wayTag.value);
HashSet<Tag> pTags = Tag.ConvertToTags(wayReader.GetAttribute("k")!, wayReader.GetAttribute("v")!);
foreach (Tag pTag in pTags)
currentTags.TryAdd(pTag.key, pTag.value);
}
else if (wayReader.Name == "nd")
{
@ -146,31 +146,42 @@ public class RegionConverter
{
ulong node1Id = currentNodeIds[i];
ulong node2Id = currentNodeIds[i+1];
if (currentTags.ContainsKey(Tag.TagType.oneway) && (bool)currentTags[Tag.TagType.oneway] && nodeRegions.ContainsKey(node1Id) && nodeRegions.ContainsKey(node2Id))
if (nodeRegions.ContainsKey(node1Id) && nodeRegions.ContainsKey(node2Id))
{
if (currentTags.ContainsKey(Tag.TagType.forward) && !(bool)currentTags[Tag.TagType.forward])
if (currentTags.ContainsKey(Tag.TagType.oneway) && (bool)currentTags[Tag.TagType.oneway])
{
OsmEdge n21e = new OsmEdge(currentTags[Tag.TagType.id], node2Id, node1Id, nodeRegions[node2Id]);
WriteWay(ref regionWaysFileStreams, nodeRegions[node2Id], n21e, outputPath);
WriteTags(ref regionTagsFileStreams, ref writtenWayTagsInRegion, nodeRegions[node2Id], currentTags, outputPath);
if (currentTags.ContainsKey(Tag.TagType.forward) && !(bool)currentTags[Tag.TagType.forward])
{
OsmEdge n21e = new OsmEdge(currentTags[Tag.TagType.id], node2Id, node1Id,
nodeRegions[node1Id]);
WriteWay(ref regionWaysFileStreams, nodeRegions[node2Id], n21e, outputPath);
WriteTags(ref regionTagsFileStreams, ref writtenWayTagsInRegion, nodeRegions[node2Id],
currentTags, outputPath);
}
else if (currentTags.ContainsKey(Tag.TagType.forward) && (bool)currentTags[Tag.TagType.forward])
{
OsmEdge n12e = new OsmEdge(currentTags[Tag.TagType.id], node1Id, node2Id,
nodeRegions[node2Id]);
WriteWay(ref regionWaysFileStreams, nodeRegions[node1Id], n12e, outputPath);
WriteTags(ref regionTagsFileStreams, ref writtenWayTagsInRegion, nodeRegions[node1Id],
currentTags, outputPath);
}
}
else
{
OsmEdge n12e = new OsmEdge(currentTags[Tag.TagType.id], node1Id, node2Id, nodeRegions[node2Id]);
OsmEdge n12e = new OsmEdge(currentTags[Tag.TagType.id], node1Id, node2Id,
nodeRegions[node2Id]);
WriteWay(ref regionWaysFileStreams, nodeRegions[node1Id], n12e, outputPath);
WriteTags(ref regionTagsFileStreams, ref writtenWayTagsInRegion, nodeRegions[node1Id], currentTags, outputPath);
WriteTags(ref regionTagsFileStreams, ref writtenWayTagsInRegion, nodeRegions[node1Id],
currentTags, outputPath);
OsmEdge n21e = new OsmEdge(currentTags[Tag.TagType.id], node2Id, node1Id,
nodeRegions[node1Id]);
WriteWay(ref regionWaysFileStreams, nodeRegions[node2Id], n21e, outputPath);
WriteTags(ref regionTagsFileStreams, ref writtenWayTagsInRegion, nodeRegions[node2Id],
currentTags, outputPath);
}
}
else if(nodeRegions.ContainsKey(node1Id) && nodeRegions.ContainsKey(node2Id))
{
OsmEdge n12e = new OsmEdge(currentTags[Tag.TagType.id], node1Id, node2Id, nodeRegions[node2Id]);
WriteWay(ref regionWaysFileStreams, nodeRegions[node1Id], n12e, outputPath);
WriteTags(ref regionTagsFileStreams, ref writtenWayTagsInRegion, nodeRegions[node1Id], currentTags, outputPath);
OsmEdge n21e = new OsmEdge(currentTags[Tag.TagType.id], node2Id, node1Id, nodeRegions[node2Id]);
WriteWay(ref regionWaysFileStreams, nodeRegions[node2Id], n21e, outputPath);
WriteTags(ref regionTagsFileStreams, ref writtenWayTagsInRegion, nodeRegions[node2Id], currentTags, outputPath);
}
}
}
}