From 102499891c46e8c091be13bb507ee4a3f9760b92 Mon Sep 17 00:00:00 2001 From: glax Date: Sat, 1 Apr 2023 01:00:10 +0200 Subject: [PATCH] Moved id to tag storage --- Server/RegionConverter.cs | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/Server/RegionConverter.cs b/Server/RegionConverter.cs index 8e08d5a..2148529 100644 --- a/Server/RegionConverter.cs +++ b/Server/RegionConverter.cs @@ -67,12 +67,8 @@ public class RegionConverter } else if (xmlReader.Name == "nd") { - try - { - ulong id = Convert.ToUInt64(xmlReader.GetAttribute("ref")!); - currentIds.Add(id); - } - catch (FormatException) { }; + ulong id = Convert.ToUInt64(xmlReader.GetAttribute("ref")!); + currentIds.Add(id); } } wayReader.Close(); @@ -110,42 +106,31 @@ public class RegionConverter private static void ImportWays(XmlReader xmlReader, Dictionary nodeRegions, string outputPath) { - BinaryFormatter bFormatter = new BinaryFormatter(); - bool currentWayIsHighway; - ulong currentWayId = 0; List currentNodeIds = new(); Dictionary currentTags = new(); Dictionary regionWaysFileStreams = new(); Dictionary regionTagsFileStreams = new(); while (xmlReader.ReadToFollowing("way")) { - ulong wayId = Convert.ToUInt64(xmlReader.GetAttribute("id")!); - currentWayIsHighway = false; currentNodeIds.Clear(); currentTags.Clear(); XmlReader wayReader = xmlReader.ReadSubtree(); while (wayReader.Read()) { - currentWayId = Convert.ToUInt64(wayReader.GetAttribute("id")!); + currentTags.TryAdd(Tag.TagType.id, Convert.ToUInt64(wayReader.GetAttribute("id")!)); if (wayReader.Name == "tag") { Tag wayTag = Tag.ConvertToTag(wayReader.GetAttribute("k")!, wayReader.GetAttribute("v")!); currentTags.TryAdd(wayTag.key, wayTag.value); - if(wayTag.key == Tag.TagType.highway) - currentWayIsHighway = true; } else if (wayReader.Name == "nd") { - try - { - ulong nodeId = Convert.ToUInt64(wayReader.GetAttribute("ref")); - currentNodeIds.Add(nodeId); - } - catch (FormatException) { }; + ulong nodeId = Convert.ToUInt64(wayReader.GetAttribute("ref")); + currentNodeIds.Add(nodeId); } } wayReader.Close(); - if (currentWayIsHighway) + if (currentTags.ContainsKey(Tag.TagType.highway)) { 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]) { - 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); WriteTag(ref regionTagsFileStreams, nodeRegions[node2Id], currentTags, outputPath); } 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); WriteTag(ref regionTagsFileStreams, nodeRegions[node1Id], currentTags, outputPath); } } 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); 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); WriteTag(ref regionTagsFileStreams, nodeRegions[node2Id], currentTags, outputPath); }