Moved id to tag storage
This commit is contained in:
parent
9ef1d4a978
commit
102499891c
@ -67,12 +67,8 @@ public class RegionConverter
|
|||||||
}
|
}
|
||||||
else if (xmlReader.Name == "nd")
|
else if (xmlReader.Name == "nd")
|
||||||
{
|
{
|
||||||
try
|
ulong id = Convert.ToUInt64(xmlReader.GetAttribute("ref")!);
|
||||||
{
|
currentIds.Add(id);
|
||||||
ulong id = Convert.ToUInt64(xmlReader.GetAttribute("ref")!);
|
|
||||||
currentIds.Add(id);
|
|
||||||
}
|
|
||||||
catch (FormatException) { };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wayReader.Close();
|
wayReader.Close();
|
||||||
@ -110,42 +106,31 @@ public class RegionConverter
|
|||||||
|
|
||||||
private static void ImportWays(XmlReader xmlReader, Dictionary<ulong, ulong> nodeRegions, string outputPath)
|
private static void ImportWays(XmlReader xmlReader, Dictionary<ulong, ulong> nodeRegions, string outputPath)
|
||||||
{
|
{
|
||||||
BinaryFormatter bFormatter = new BinaryFormatter();
|
|
||||||
bool currentWayIsHighway;
|
|
||||||
ulong currentWayId = 0;
|
|
||||||
List<ulong> currentNodeIds = new();
|
List<ulong> currentNodeIds = new();
|
||||||
Dictionary<Tag.TagType, dynamic> currentTags = new();
|
Dictionary<Tag.TagType, dynamic> currentTags = new();
|
||||||
Dictionary<ulong, FileStream> regionWaysFileStreams = new();
|
Dictionary<ulong, FileStream> regionWaysFileStreams = new();
|
||||||
Dictionary<ulong, FileStream> regionTagsFileStreams = new();
|
Dictionary<ulong, FileStream> regionTagsFileStreams = new();
|
||||||
while (xmlReader.ReadToFollowing("way"))
|
while (xmlReader.ReadToFollowing("way"))
|
||||||
{
|
{
|
||||||
ulong wayId = Convert.ToUInt64(xmlReader.GetAttribute("id")!);
|
|
||||||
currentWayIsHighway = false;
|
|
||||||
currentNodeIds.Clear();
|
currentNodeIds.Clear();
|
||||||
currentTags.Clear();
|
currentTags.Clear();
|
||||||
XmlReader wayReader = xmlReader.ReadSubtree();
|
XmlReader wayReader = xmlReader.ReadSubtree();
|
||||||
while (wayReader.Read())
|
while (wayReader.Read())
|
||||||
{
|
{
|
||||||
currentWayId = 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")!);
|
Tag wayTag = Tag.ConvertToTag(wayReader.GetAttribute("k")!, wayReader.GetAttribute("v")!);
|
||||||
currentTags.TryAdd(wayTag.key, wayTag.value);
|
currentTags.TryAdd(wayTag.key, wayTag.value);
|
||||||
if(wayTag.key == Tag.TagType.highway)
|
|
||||||
currentWayIsHighway = true;
|
|
||||||
}
|
}
|
||||||
else if (wayReader.Name == "nd")
|
else if (wayReader.Name == "nd")
|
||||||
{
|
{
|
||||||
try
|
ulong nodeId = Convert.ToUInt64(wayReader.GetAttribute("ref"));
|
||||||
{
|
currentNodeIds.Add(nodeId);
|
||||||
ulong nodeId = Convert.ToUInt64(wayReader.GetAttribute("ref"));
|
|
||||||
currentNodeIds.Add(nodeId);
|
|
||||||
}
|
|
||||||
catch (FormatException) { };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wayReader.Close();
|
wayReader.Close();
|
||||||
if (currentWayIsHighway)
|
if (currentTags.ContainsKey(Tag.TagType.highway))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < currentNodeIds.Count - 1; i++)
|
for (int i = 0; i < currentNodeIds.Count - 1; i++)
|
||||||
{
|
{
|
||||||
@ -155,24 +140,24 @@ public class RegionConverter
|
|||||||
{
|
{
|
||||||
if (currentTags.ContainsKey(Tag.TagType.forward) && !(bool)currentTags[Tag.TagType.forward])
|
if (currentTags.ContainsKey(Tag.TagType.forward) && !(bool)currentTags[Tag.TagType.forward])
|
||||||
{
|
{
|
||||||
OsmWay n21e = new OsmWay(currentWayId, node2Id, node1Id, nodeRegions[node2Id]);
|
OsmWay n21e = new OsmWay(currentTags[Tag.TagType.id], node2Id, node1Id, nodeRegions[node2Id]);
|
||||||
WriteWay(ref regionWaysFileStreams, nodeRegions[node2Id], n21e, outputPath);
|
WriteWay(ref regionWaysFileStreams, nodeRegions[node2Id], n21e, outputPath);
|
||||||
WriteTag(ref regionTagsFileStreams, nodeRegions[node2Id], currentTags, outputPath);
|
WriteTag(ref regionTagsFileStreams, nodeRegions[node2Id], currentTags, outputPath);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
OsmWay n12e = new OsmWay(currentWayId, node1Id, node2Id, nodeRegions[node2Id]);
|
OsmWay n12e = new OsmWay(currentTags[Tag.TagType.id], node1Id, node2Id, nodeRegions[node2Id]);
|
||||||
WriteWay(ref regionWaysFileStreams, nodeRegions[node1Id], n12e, outputPath);
|
WriteWay(ref regionWaysFileStreams, nodeRegions[node1Id], n12e, outputPath);
|
||||||
WriteTag(ref regionTagsFileStreams, nodeRegions[node1Id], currentTags, outputPath);
|
WriteTag(ref regionTagsFileStreams, nodeRegions[node1Id], currentTags, outputPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(nodeRegions.ContainsKey(node1Id) && nodeRegions.ContainsKey(node2Id))
|
else if(nodeRegions.ContainsKey(node1Id) && nodeRegions.ContainsKey(node2Id))
|
||||||
{
|
{
|
||||||
OsmWay n12e = new OsmWay(currentWayId, node1Id, node2Id, nodeRegions[node2Id]);
|
OsmWay n12e = new OsmWay(currentTags[Tag.TagType.id], node1Id, node2Id, nodeRegions[node2Id]);
|
||||||
WriteWay(ref regionWaysFileStreams, nodeRegions[node1Id], n12e, outputPath);
|
WriteWay(ref regionWaysFileStreams, nodeRegions[node1Id], n12e, outputPath);
|
||||||
WriteTag(ref regionTagsFileStreams, nodeRegions[node1Id], currentTags, outputPath);
|
WriteTag(ref regionTagsFileStreams, nodeRegions[node1Id], currentTags, outputPath);
|
||||||
|
|
||||||
OsmWay n21e = new OsmWay(currentWayId, node2Id, node1Id, nodeRegions[node2Id]);
|
OsmWay n21e = new OsmWay(currentTags[Tag.TagType.id], node2Id, node1Id, nodeRegions[node2Id]);
|
||||||
WriteWay(ref regionWaysFileStreams, nodeRegions[node2Id], n21e, outputPath);
|
WriteWay(ref regionWaysFileStreams, nodeRegions[node2Id], n21e, outputPath);
|
||||||
WriteTag(ref regionTagsFileStreams, nodeRegions[node2Id], currentTags, outputPath);
|
WriteTag(ref regionTagsFileStreams, nodeRegions[node2Id], currentTags, outputPath);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user