Compare commits
2 Commits
ae65cc9e1b
...
c1d8f5e879
Author | SHA1 | Date | |
---|---|---|---|
c1d8f5e879 | |||
b898bb3f2d |
@ -12,7 +12,7 @@ public class Converter(float regionSize, string? exportFolderPath = null, ILogge
|
|||||||
{
|
{
|
||||||
internal readonly float RegionSize = regionSize;
|
internal readonly float RegionSize = regionSize;
|
||||||
|
|
||||||
internal readonly string ExportFolderPath = exportFolderPath ?? Path.Join(Environment.CurrentDirectory, regionSize.ToString(CultureInfo.InvariantCulture));
|
internal readonly string ExportFolderPath = Path.Join(exportFolderPath ?? Environment.CurrentDirectory, regionSize.ToString(CultureInfo.InvariantCulture));
|
||||||
internal const string NodesMapRegionFileName = "nodes.map";
|
internal const string NodesMapRegionFileName = "nodes.map";
|
||||||
internal const string WayMapRegionFileName = "ways.map";
|
internal const string WayMapRegionFileName = "ways.map";
|
||||||
internal const string NodesRegionDirectory = "nodes";
|
internal const string NodesRegionDirectory = "nodes";
|
||||||
@ -168,6 +168,8 @@ public class Converter(float regionSize, string? exportFolderPath = null, ILogge
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
DateTime print = DateTime.Now;
|
DateTime print = DateTime.Now;
|
||||||
DateTime start = DateTime.Now;
|
DateTime start = DateTime.Now;
|
||||||
|
List<ulong> wayIds = new();
|
||||||
|
List<ulong> nodeIds = new();
|
||||||
foreach (string path in wayRegionsPaths)
|
foreach (string path in wayRegionsPaths)
|
||||||
{
|
{
|
||||||
if (DateTime.Now - print > TimeSpan.FromSeconds(2))
|
if (DateTime.Now - print > TimeSpan.FromSeconds(2))
|
||||||
@ -179,8 +181,7 @@ public class Converter(float regionSize, string? exportFolderPath = null, ILogge
|
|||||||
print = DateTime.Now;
|
print = DateTime.Now;
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
List<ulong> nodeIds = new();
|
|
||||||
File.Copy(path, $"{path}.bak", true);
|
File.Copy(path, $"{path}.bak", true);
|
||||||
StreamReader waysStreamReader = new(path, Encoding.UTF8, false, DefaultReadOptions);
|
StreamReader waysStreamReader = new(path, Encoding.UTF8, false, DefaultReadOptions);
|
||||||
StreamWriter waysStreamWriter = new($"{path}.new", Encoding.UTF8, DefaultWriteOptions);
|
StreamWriter waysStreamWriter = new($"{path}.new", Encoding.UTF8, DefaultWriteOptions);
|
||||||
@ -196,6 +197,7 @@ public class Converter(float regionSize, string? exportFolderPath = null, ILogge
|
|||||||
if (w.Tags.ContainsKey("highway"))
|
if (w.Tags.ContainsKey("highway"))
|
||||||
{
|
{
|
||||||
waysStreamWriter.WriteLine(line);
|
waysStreamWriter.WriteLine(line);
|
||||||
|
wayIds.Add(w.ID);
|
||||||
nodeIds.AddRange(w.NodeIds);
|
nodeIds.AddRange(w.NodeIds);
|
||||||
hasWritten = true;
|
hasWritten = true;
|
||||||
}else
|
}else
|
||||||
@ -239,11 +241,56 @@ public class Converter(float regionSize, string? exportFolderPath = null, ILogge
|
|||||||
File.Move($"{nodesPath}.new", nodesPath, true);
|
File.Move($"{nodesPath}.new", nodesPath, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger?.LogInformation("Cleaning node/way-maps");
|
||||||
|
string wayMapFile = Path.Join(ExportFolderPath, WayMapRegionFileName);
|
||||||
|
string wayMapBak = $"{wayMapFile}.bak";
|
||||||
|
File.Copy(wayMapFile, wayMapBak, true);
|
||||||
|
string newWayMapFile = $"{wayMapFile}.new";
|
||||||
|
using (StreamReader wayMapSr = new (wayMapFile, Encoding.ASCII, false, DefaultReadOptions))
|
||||||
|
{
|
||||||
|
using (StreamWriter wayMapSw = new(newWayMapFile, Encoding.ASCII, DefaultWriteOptions))
|
||||||
|
{
|
||||||
|
while (!wayMapSr.EndOfStream)
|
||||||
|
{
|
||||||
|
string? line = wayMapSr.ReadLine();
|
||||||
|
if(line is null)
|
||||||
|
continue;
|
||||||
|
ulong id = ulong.Parse(line.Split('-')[0]);
|
||||||
|
if(wayIds.Contains(id))
|
||||||
|
wayMapSw.WriteLine(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
File.Move(newWayMapFile, wayMapFile, true);
|
||||||
|
|
||||||
|
string nodeMapFile = Path.Join(ExportFolderPath, NodesMapRegionFileName);
|
||||||
|
string nodeMapBak = $"{nodeMapFile}.bak";
|
||||||
|
File.Copy(nodeMapFile, nodeMapBak, true);
|
||||||
|
string newNodeMapFile = $"{nodeMapFile}.new";
|
||||||
|
using (StreamReader nodeMapSr = new (nodeMapFile, Encoding.ASCII, false, DefaultReadOptions))
|
||||||
|
{
|
||||||
|
using (StreamWriter nodeMapSw = new(newNodeMapFile, Encoding.ASCII, DefaultWriteOptions))
|
||||||
|
{
|
||||||
|
while (!nodeMapSr.EndOfStream)
|
||||||
|
{
|
||||||
|
string? line = nodeMapSr.ReadLine();
|
||||||
|
if(line is null)
|
||||||
|
continue;
|
||||||
|
ulong id = ulong.Parse(line.Split('-')[0]);
|
||||||
|
if(nodeIds.Contains(id))
|
||||||
|
nodeMapSw.WriteLine(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
File.Move(newNodeMapFile, nodeMapFile, true);
|
||||||
|
|
||||||
logger?.LogInformation("Removing .bak files...");
|
logger?.LogInformation("Removing .bak files...");
|
||||||
foreach (string bakFile in Directory.GetFiles(Path.Join(ExportFolderPath, WaysRegionDirectory), "*.bak")
|
foreach (string bakFile in Directory.GetFiles(Path.Join(ExportFolderPath, WaysRegionDirectory), "*.bak")
|
||||||
.Concat(Directory.GetFiles(Path.Join(ExportFolderPath, NodesRegionDirectory), "*.bak")))
|
.Concat(Directory.GetFiles(Path.Join(ExportFolderPath, NodesRegionDirectory), "*.bak")))
|
||||||
File.Delete(bakFile);
|
File.Delete(bakFile);
|
||||||
|
File.Delete(nodeMapBak);
|
||||||
|
File.Delete(wayMapBak);
|
||||||
}
|
}
|
||||||
|
|
||||||
private StreamWriter GetOrCreateRegionStreamWriter(long regionId, ref Dictionary<long, StreamWriter> srDict, RegionType regionType)
|
private StreamWriter GetOrCreateRegionStreamWriter(long regionId, ref Dictionary<long, StreamWriter> srDict, RegionType regionType)
|
||||||
|
@ -9,7 +9,7 @@ public class RegionLoader(float regionSize, string? importFolderPath = null, ILo
|
|||||||
{
|
{
|
||||||
internal readonly float RegionSize = regionSize;
|
internal readonly float RegionSize = regionSize;
|
||||||
|
|
||||||
internal readonly string ImportFolderPath = importFolderPath ?? Path.Join(Environment.CurrentDirectory, regionSize.ToString(CultureInfo.InvariantCulture));
|
internal readonly string ImportFolderPath = Path.Join(importFolderPath ?? Environment.CurrentDirectory, regionSize.ToString(CultureInfo.InvariantCulture));
|
||||||
private const string NodesMapRegionFileName = "nodes.map";
|
private const string NodesMapRegionFileName = "nodes.map";
|
||||||
private const string WayMapRegionFileName = "ways.map";
|
private const string WayMapRegionFileName = "ways.map";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user