Moved RegionManager inside of Importer as RegionStruct,
Moved Regionsize var to Region
This commit is contained in:
@ -8,7 +8,6 @@ namespace OSMImporter
|
||||
public static class Importer
|
||||
{
|
||||
|
||||
public const float regionSize = 0.01f;
|
||||
private static readonly XmlReaderSettings readerSettings = new()
|
||||
{
|
||||
IgnoreWhitespace = true,
|
||||
@ -30,10 +29,10 @@ namespace OSMImporter
|
||||
Dictionary<ulong, Node?> nodes = ReturnNodeIdDictionary(XmlReader.Create(xmlFileStream, readerSettings));
|
||||
|
||||
xmlFileStream.Position = 0;
|
||||
RegionManager regionManager = new RegionManager();
|
||||
RegionStruct regionStruct = new RegionStruct();
|
||||
|
||||
Console.WriteLine("Reading nodes...");
|
||||
LoadNodesIntoDictionary(ref nodes, XmlReader.Create(xmlFileStream, readerSettings), ref regionManager);
|
||||
LoadNodesIntoDictionary(ref nodes, XmlReader.Create(xmlFileStream, readerSettings), ref regionStruct);
|
||||
|
||||
xmlFileStream.Position = 0;
|
||||
|
||||
@ -42,7 +41,7 @@ namespace OSMImporter
|
||||
|
||||
Console.WriteLine("Writing...");
|
||||
|
||||
foreach(Region region in regionManager.GetAllRegions())
|
||||
foreach(Region region in regionStruct.GetAllRegions())
|
||||
WriteRegion(region, outputFolderPath);
|
||||
}
|
||||
|
||||
@ -79,7 +78,7 @@ namespace OSMImporter
|
||||
return retSet;
|
||||
}
|
||||
|
||||
private static void LoadNodesIntoDictionary(ref Dictionary<ulong, Node?> nodes, XmlReader xmlReader, ref RegionManager regionManager)
|
||||
private static void LoadNodesIntoDictionary(ref Dictionary<ulong, Node?> nodes, XmlReader xmlReader, ref RegionStruct regionStruct)
|
||||
{
|
||||
while (xmlReader.ReadToFollowing("node"))
|
||||
{
|
||||
@ -90,7 +89,7 @@ namespace OSMImporter
|
||||
float lon = Convert.ToSingle(xmlReader.GetAttribute("lon")!, coordinateFormat);
|
||||
Node newNode = new Node(lat, lon);
|
||||
nodes[id] = newNode;
|
||||
regionManager.GetRegion(newNode).AddNode(id, newNode);
|
||||
regionStruct.GetRegion(newNode).AddNode(id, newNode);
|
||||
}
|
||||
}
|
||||
xmlReader.Close();
|
||||
@ -182,4 +181,26 @@ 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
using OSMDatastructure;
|
||||
|
||||
namespace OSMImporter
|
||||
{
|
||||
public class RegionManager
|
||||
{
|
||||
private readonly Dictionary<ulong, Region> _regions;
|
||||
|
||||
public RegionManager()
|
||||
{
|
||||
this._regions = new Dictionary<ulong, Region>();
|
||||
}
|
||||
|
||||
public Region GetRegion(Coordinates coordinates)
|
||||
{
|
||||
if(this._regions.ContainsKey(coordinates.GetRegionHash(Importer.regionSize)))
|
||||
return this._regions[coordinates.GetRegionHash(Importer.regionSize)];
|
||||
else
|
||||
{
|
||||
Region newRegion = new Region(coordinates, Importer.regionSize);
|
||||
this._regions.Add(newRegion.regionHash, value: newRegion);
|
||||
return newRegion;
|
||||
}
|
||||
}
|
||||
|
||||
public Region[] GetAllRegions()
|
||||
{
|
||||
return this._regions.Values.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user