Fixing one-way issue
This commit is contained in:
parent
5289020d44
commit
14533c150f
@ -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)
|
switch (key)
|
||||||
{
|
{
|
||||||
case "highway":
|
case "highway":
|
||||||
try
|
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)
|
catch (ArgumentException)
|
||||||
{
|
{
|
||||||
return new Tag(TagType.highway, WayType.unclassified);
|
ret.Add(new Tag(TagType.highway, WayType.unclassified));
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case "maxspeed":
|
case "maxspeed":
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
byte speed = Convert.ToByte(value);
|
byte speed = Convert.ToByte(value);
|
||||||
if (speed == 255)
|
if (speed != 255)
|
||||||
return new Tag(TagType.highway, false);
|
ret.Add(new Tag(TagType.maxspeed, speed));
|
||||||
else
|
break;
|
||||||
return new Tag(TagType.maxspeed, speed);
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
//Console.WriteLine(e);
|
ret.Add(new Tag(TagType.maxspeed, byte.MinValue));
|
||||||
//Console.WriteLine("Continuing...");
|
|
||||||
return new Tag(TagType.maxspeed, byte.MaxValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
case "oneway":
|
case "oneway":
|
||||||
switch (value)
|
switch (value)
|
||||||
{
|
{
|
||||||
case "yes":
|
case "yes":
|
||||||
return new Tag(TagType.oneway, true);
|
ret.Add(new Tag(TagType.oneway, true));
|
||||||
|
break;
|
||||||
case "-1":
|
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":
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
@ -93,7 +103,7 @@ public class Tag
|
|||||||
|
|
||||||
public enum TagType : byte
|
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() {
|
public static readonly Dictionary<WayType, byte> defaultSpeedCar = new() {
|
||||||
@ -104,8 +114,8 @@ public class Tag
|
|||||||
{ WayType.primary, 65 },
|
{ WayType.primary, 65 },
|
||||||
{ WayType.secondary, 60 },
|
{ WayType.secondary, 60 },
|
||||||
{ WayType.tertiary, 50 },
|
{ WayType.tertiary, 50 },
|
||||||
{ WayType.unclassified, 15 },
|
{ WayType.unclassified, 30 },
|
||||||
{ WayType.residential, 10 },
|
{ WayType.residential, 15 },
|
||||||
{ WayType.motorway_link, 60 },
|
{ WayType.motorway_link, 60 },
|
||||||
{ WayType.trunk_link, 50 },
|
{ WayType.trunk_link, 50 },
|
||||||
{ WayType.primary_link, 50 },
|
{ WayType.primary_link, 50 },
|
||||||
|
@ -25,9 +25,9 @@ public class TagManager
|
|||||||
|
|
||||||
public void AddTag(ulong wayId, string key, string value)
|
public void AddTag(ulong wayId, string key, string value)
|
||||||
{
|
{
|
||||||
Tag? tag = Tag.ConvertToTag(key, value);
|
HashSet<Tag> pTags = Tag.ConvertToTags(key, value);
|
||||||
if(tag is not null)
|
foreach (Tag pTag in pTags)
|
||||||
AddTag(wayId, tag);
|
AddTag(wayId, pTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddTag(ulong wayId, Tag tag)
|
public void AddTag(ulong wayId, Tag tag)
|
||||||
|
@ -129,9 +129,9 @@ public class RegionConverter
|
|||||||
currentTags.TryAdd(Tag.TagType.id, Convert.ToUInt64(wayReader.GetAttribute("id")!));
|
currentTags.TryAdd(Tag.TagType.id, Convert.ToUInt64(wayReader.GetAttribute("id")!));
|
||||||
if (wayReader.Name == "tag")
|
if (wayReader.Name == "tag")
|
||||||
{
|
{
|
||||||
Tag? wayTag = Tag.ConvertToTag(wayReader.GetAttribute("k")!, wayReader.GetAttribute("v")!);
|
HashSet<Tag> pTags = Tag.ConvertToTags(wayReader.GetAttribute("k")!, wayReader.GetAttribute("v")!);
|
||||||
if(wayTag is not null)
|
foreach (Tag pTag in pTags)
|
||||||
currentTags.TryAdd(wayTag.key, wayTag.value);
|
currentTags.TryAdd(pTag.key, pTag.value);
|
||||||
}
|
}
|
||||||
else if (wayReader.Name == "nd")
|
else if (wayReader.Name == "nd")
|
||||||
{
|
{
|
||||||
@ -146,30 +146,41 @@ public class RegionConverter
|
|||||||
{
|
{
|
||||||
ulong node1Id = currentNodeIds[i];
|
ulong node1Id = currentNodeIds[i];
|
||||||
ulong node2Id = currentNodeIds[i+1];
|
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.oneway) && (bool)currentTags[Tag.TagType.oneway])
|
||||||
{
|
{
|
||||||
if (currentTags.ContainsKey(Tag.TagType.forward) && !(bool)currentTags[Tag.TagType.forward])
|
if (currentTags.ContainsKey(Tag.TagType.forward) && !(bool)currentTags[Tag.TagType.forward])
|
||||||
{
|
{
|
||||||
OsmEdge n21e = new OsmEdge(currentTags[Tag.TagType.id], node2Id, node1Id, nodeRegions[node2Id]);
|
OsmEdge n21e = new OsmEdge(currentTags[Tag.TagType.id], node2Id, node1Id,
|
||||||
|
nodeRegions[node1Id]);
|
||||||
WriteWay(ref regionWaysFileStreams, nodeRegions[node2Id], n21e, outputPath);
|
WriteWay(ref regionWaysFileStreams, nodeRegions[node2Id], n21e, outputPath);
|
||||||
WriteTags(ref regionTagsFileStreams, ref writtenWayTagsInRegion, nodeRegions[node2Id], currentTags, 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
|
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);
|
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);
|
||||||
}
|
|
||||||
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]);
|
OsmEdge n21e = new OsmEdge(currentTags[Tag.TagType.id], node2Id, node1Id,
|
||||||
|
nodeRegions[node1Id]);
|
||||||
WriteWay(ref regionWaysFileStreams, nodeRegions[node2Id], n21e, outputPath);
|
WriteWay(ref regionWaysFileStreams, nodeRegions[node2Id], n21e, outputPath);
|
||||||
WriteTags(ref regionTagsFileStreams, ref writtenWayTagsInRegion, nodeRegions[node2Id], currentTags, outputPath);
|
WriteTags(ref regionTagsFileStreams, ref writtenWayTagsInRegion, nodeRegions[node2Id],
|
||||||
|
currentTags, outputPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user