2023-02-03 23:35:22 +01:00
|
|
|
using OSMDatastructure;
|
2023-03-14 17:00:59 +01:00
|
|
|
using OSMDatastructure.Graph;
|
2023-02-03 23:35:22 +01:00
|
|
|
|
|
|
|
namespace OSMImporter
|
|
|
|
{
|
|
|
|
public class RegionManager
|
|
|
|
{
|
|
|
|
private string workingDirectory { get; }
|
2023-03-31 21:56:27 +02:00
|
|
|
private readonly Dictionary<ulong, Region> _regions = new();
|
2023-02-03 23:35:22 +01:00
|
|
|
|
|
|
|
public RegionManager(string workingDirectory)
|
|
|
|
{
|
|
|
|
this.workingDirectory = workingDirectory;
|
|
|
|
}
|
2023-04-01 14:43:05 +02:00
|
|
|
|
|
|
|
public Region? GetRegion(Coordinates coordinates)
|
|
|
|
{
|
|
|
|
return GetRegion(Coordinates.GetRegionHashCode(coordinates));
|
|
|
|
}
|
|
|
|
|
|
|
|
public Region? GetRegion(ulong id)
|
|
|
|
{
|
|
|
|
if(_regions.TryGetValue(id, out Region? value))
|
|
|
|
return value;
|
2023-02-03 23:35:22 +01:00
|
|
|
else
|
|
|
|
{
|
2023-04-01 14:43:05 +02:00
|
|
|
Region? loadedRegion = LoadRegion(id);
|
|
|
|
if(loadedRegion is not null)
|
|
|
|
_regions.Add(loadedRegion!.regionHash, value: loadedRegion);
|
2023-02-03 23:35:22 +01:00
|
|
|
return loadedRegion;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Region[] GetAllRegions()
|
|
|
|
{
|
|
|
|
return this._regions.Values.ToArray();
|
|
|
|
}
|
2023-04-01 14:43:05 +02:00
|
|
|
|
|
|
|
private Region? LoadRegion(Coordinates coordinates)
|
|
|
|
{
|
|
|
|
return LoadRegion(Coordinates.GetRegionHashCode(coordinates));
|
|
|
|
}
|
|
|
|
|
|
|
|
private Region? LoadRegion(ulong id)
|
2023-02-03 23:35:22 +01:00
|
|
|
{
|
2023-04-01 18:08:48 +02:00
|
|
|
Console.WriteLine($"Load Region {id}");
|
2023-04-01 14:43:05 +02:00
|
|
|
return Region.FromId(workingDirectory, id);
|
2023-02-03 23:35:22 +01:00
|
|
|
}
|
2023-02-05 20:02:22 +01:00
|
|
|
|
2023-02-06 17:32:55 +01:00
|
|
|
public OsmNode? GetNode(Coordinates coordinates)
|
2023-02-05 20:02:22 +01:00
|
|
|
{
|
2023-04-01 14:43:05 +02:00
|
|
|
Region? regionWithNode = GetRegion(coordinates);
|
|
|
|
if (regionWithNode is not null)
|
|
|
|
return regionWithNode.GetNode(coordinates);
|
|
|
|
else return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public OsmNode? GetNode(ulong nodeId, ulong regionId)
|
|
|
|
{
|
|
|
|
Region? r = GetRegion(regionId);
|
|
|
|
return r?.GetNode(nodeId);
|
2023-02-05 20:02:22 +01:00
|
|
|
}
|
2023-02-03 23:35:22 +01:00
|
|
|
}
|
|
|
|
}
|