From 627c1895fa6b2751801340fde4c7bb153c147f3f Mon Sep 17 00:00:00 2001 From: C9Glax <13404778+C9Glax@users.noreply.github.com> Date: Sun, 5 Feb 2023 19:09:17 +0100 Subject: [PATCH] Moved and Renamed RegionStruct to RegionCollection.cs --- OSMSplitter/RegionCollection.cs | 25 +++++++++++++++ OSMSplitter/{Importer.cs => XMLImporter.cs} | 34 ++++----------------- 2 files changed, 31 insertions(+), 28 deletions(-) create mode 100644 OSMSplitter/RegionCollection.cs rename OSMSplitter/{Importer.cs => XMLImporter.cs} (87%) diff --git a/OSMSplitter/RegionCollection.cs b/OSMSplitter/RegionCollection.cs new file mode 100644 index 0000000..700f1c7 --- /dev/null +++ b/OSMSplitter/RegionCollection.cs @@ -0,0 +1,25 @@ +using OSMDatastructure; + +namespace OSMImporter; + +internal class RegionCollection +{ + private readonly Dictionary _regions = new(); + + public Region GetRegion(Coordinates coordinates) + { + if(this._regions.ContainsKey(coordinates.GetRegionHash())) + return this._regions[coordinates.GetRegionHash()]; + else + { + Region newRegion = new Region(coordinates); + this._regions.Add(newRegion.regionHash, value: newRegion); + return newRegion; + } + } + + public Region[] GetAllRegions() + { + return this._regions.Values.ToArray(); + } +} \ No newline at end of file diff --git a/OSMSplitter/Importer.cs b/OSMSplitter/XMLImporter.cs similarity index 87% rename from OSMSplitter/Importer.cs rename to OSMSplitter/XMLImporter.cs index 04973eb..9d6eed0 100644 --- a/OSMSplitter/Importer.cs +++ b/OSMSplitter/XMLImporter.cs @@ -5,7 +5,7 @@ using OSMDatastructure; namespace OSMImporter { - public static class Importer + public static class XmlImporter { private static readonly XmlReaderSettings readerSettings = new() @@ -29,10 +29,10 @@ namespace OSMImporter Dictionary nodes = ReturnNodeIdDictionary(XmlReader.Create(xmlFileStream, readerSettings)); xmlFileStream.Position = 0; - RegionStruct regionStruct = new RegionStruct(); + RegionCollection regionCollection = new RegionCollection(); Console.WriteLine("Reading nodes..."); - LoadNodesIntoDictionary(ref nodes, XmlReader.Create(xmlFileStream, readerSettings), ref regionStruct); + LoadNodesIntoDictionary(ref nodes, XmlReader.Create(xmlFileStream, readerSettings), ref regionCollection); xmlFileStream.Position = 0; @@ -41,7 +41,7 @@ namespace OSMImporter Console.WriteLine("Writing..."); - foreach(Region region in regionStruct.GetAllRegions()) + foreach(Region region in regionCollection.GetAllRegions()) WriteRegion(region, outputFolderPath); } @@ -78,7 +78,7 @@ namespace OSMImporter return retSet; } - private static void LoadNodesIntoDictionary(ref Dictionary nodes, XmlReader xmlReader, ref RegionStruct regionStruct) + private static void LoadNodesIntoDictionary(ref Dictionary nodes, XmlReader xmlReader, ref RegionCollection regionCollection) { while (xmlReader.ReadToFollowing("node")) { @@ -89,7 +89,7 @@ namespace OSMImporter float lon = Convert.ToSingle(xmlReader.GetAttribute("lon")!, coordinateFormat); Node newNode = new Node(lat, lon); nodes[id] = newNode; - regionStruct.GetRegion(newNode).AddNode(id, newNode); + regionCollection.GetRegion(newNode).AddNode(id, newNode); } } xmlReader.Close(); @@ -181,26 +181,4 @@ namespace OSMImporter fileStream.Close(); } } - - internal class RegionStruct - { - private readonly Dictionary _regions = new(); - - public Region GetRegion(Coordinates coordinates) - { - if(this._regions.ContainsKey(coordinates.GetRegionHash())) - return this._regions[coordinates.GetRegionHash()]; - else - { - Region newRegion = new Region(coordinates); - this._regions.Add(newRegion.regionHash, value: newRegion); - return newRegion; - } - } - - public Region[] GetAllRegions() - { - return this._regions.Values.ToArray(); - } - } } \ No newline at end of file