Moved and Renamed RegionStruct to RegionCollection.cs

This commit is contained in:
C9Glax 2023-02-05 19:09:17 +01:00
parent 10e99a9cd2
commit 627c1895fa
2 changed files with 31 additions and 28 deletions

View File

@ -0,0 +1,25 @@
using OSMDatastructure;
namespace OSMImporter;
internal class RegionCollection
{
private readonly Dictionary<ulong, Region> _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();
}
}

View File

@ -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<ulong, Node?> 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<ulong, Node?> nodes, XmlReader xmlReader, ref RegionStruct regionStruct)
private static void LoadNodesIntoDictionary(ref Dictionary<ulong, Node?> 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<ulong, Region> _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();
}
}
}