Moved and Renamed RegionStruct to RegionCollection.cs
This commit is contained in:
parent
10e99a9cd2
commit
627c1895fa
25
OSMSplitter/RegionCollection.cs
Normal file
25
OSMSplitter/RegionCollection.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,7 @@ using OSMDatastructure;
|
|||||||
|
|
||||||
namespace OSMImporter
|
namespace OSMImporter
|
||||||
{
|
{
|
||||||
public static class Importer
|
public static class XmlImporter
|
||||||
{
|
{
|
||||||
|
|
||||||
private static readonly XmlReaderSettings readerSettings = new()
|
private static readonly XmlReaderSettings readerSettings = new()
|
||||||
@ -29,10 +29,10 @@ namespace OSMImporter
|
|||||||
Dictionary<ulong, Node?> nodes = ReturnNodeIdDictionary(XmlReader.Create(xmlFileStream, readerSettings));
|
Dictionary<ulong, Node?> nodes = ReturnNodeIdDictionary(XmlReader.Create(xmlFileStream, readerSettings));
|
||||||
|
|
||||||
xmlFileStream.Position = 0;
|
xmlFileStream.Position = 0;
|
||||||
RegionStruct regionStruct = new RegionStruct();
|
RegionCollection regionCollection = new RegionCollection();
|
||||||
|
|
||||||
Console.WriteLine("Reading nodes...");
|
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;
|
xmlFileStream.Position = 0;
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ namespace OSMImporter
|
|||||||
|
|
||||||
Console.WriteLine("Writing...");
|
Console.WriteLine("Writing...");
|
||||||
|
|
||||||
foreach(Region region in regionStruct.GetAllRegions())
|
foreach(Region region in regionCollection.GetAllRegions())
|
||||||
WriteRegion(region, outputFolderPath);
|
WriteRegion(region, outputFolderPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ namespace OSMImporter
|
|||||||
return retSet;
|
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"))
|
while (xmlReader.ReadToFollowing("node"))
|
||||||
{
|
{
|
||||||
@ -89,7 +89,7 @@ namespace OSMImporter
|
|||||||
float lon = Convert.ToSingle(xmlReader.GetAttribute("lon")!, coordinateFormat);
|
float lon = Convert.ToSingle(xmlReader.GetAttribute("lon")!, coordinateFormat);
|
||||||
Node newNode = new Node(lat, lon);
|
Node newNode = new Node(lat, lon);
|
||||||
nodes[id] = newNode;
|
nodes[id] = newNode;
|
||||||
regionStruct.GetRegion(newNode).AddNode(id, newNode);
|
regionCollection.GetRegion(newNode).AddNode(id, newNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xmlReader.Close();
|
xmlReader.Close();
|
||||||
@ -181,26 +181,4 @@ namespace OSMImporter
|
|||||||
fileStream.Close();
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user