diff --git a/OSMDatastructure/Region.cs b/OSMDatastructure/Region.cs index 20cd59a..d5b7f52 100644 --- a/OSMDatastructure/Region.cs +++ b/OSMDatastructure/Region.cs @@ -59,16 +59,4 @@ public class Region else return null; } - public static Region? FromFile(string filePath) - { - if (File.Exists(filePath)) - return JsonSerializer.Deserialize(new FileStream(filePath, FileMode.Open), serializerOptions)!; - else return null; - } - - public static Region? FromId(string path, ulong regionId) - { - string filePath = Path.Join(path, $"{regionId}.region"); - return FromFile(filePath); - } } \ No newline at end of file diff --git a/Pathfinding/RegionManager.cs b/Pathfinding/RegionManager.cs index 4d43c8b..e40caf4 100644 --- a/Pathfinding/RegionManager.cs +++ b/Pathfinding/RegionManager.cs @@ -1,3 +1,4 @@ +using System.Text.Json; using OSMDatastructure; using OSMDatastructure.Graph; @@ -24,7 +25,7 @@ namespace OSMImporter return value; else { - Region? loadedRegion = LoadRegion(id); + Region? loadedRegion = RegionFromId(id); if(loadedRegion is not null) _regions.Add(loadedRegion!.regionHash, value: loadedRegion); return loadedRegion; @@ -36,17 +37,6 @@ namespace OSMImporter return this._regions.Values.ToArray(); } - private Region? LoadRegion(Coordinates coordinates) - { - return LoadRegion(Coordinates.GetRegionHashCode(coordinates)); - } - - private Region? LoadRegion(ulong id) - { - Console.WriteLine($"Load Region {id}"); - return Region.FromId(workingDirectory, id); - } - public OsmNode? GetNode(Coordinates coordinates) { Region? regionWithNode = GetRegion(coordinates); @@ -60,5 +50,23 @@ namespace OSMImporter Region? r = GetRegion(regionId); return r?.GetNode(nodeId); } + + private Region? RegionFromFile(string filePath) + { + Region? retRegion = null; + if (File.Exists(filePath)) + { + FileStream regionFile = new FileStream(filePath, FileMode.Open); + retRegion = JsonSerializer.Deserialize(regionFile, Region.serializerOptions)!; + regionFile.Dispose(); + } + return retRegion; + } + + private Region? RegionFromId(ulong regionId) + { + string filePath = Path.Join(workingDirectory, $"{regionId}.region"); + return RegionFromFile(filePath); + } } } \ No newline at end of file