Compare commits
No commits in common. "c1d8f5e879f49b094bd33cb254bed3070924af13" and "ae65cc9e1bc428af8b18424281c588171d6f19e4" have entirely different histories.
c1d8f5e879
...
ae65cc9e1b
@ -12,7 +12,7 @@ public class Converter(float regionSize, string? exportFolderPath = null, ILogge
|
||||
{
|
||||
internal readonly float RegionSize = regionSize;
|
||||
|
||||
internal readonly string ExportFolderPath = Path.Join(exportFolderPath ?? Environment.CurrentDirectory, regionSize.ToString(CultureInfo.InvariantCulture));
|
||||
internal readonly string ExportFolderPath = exportFolderPath ?? Path.Join(Environment.CurrentDirectory, regionSize.ToString(CultureInfo.InvariantCulture));
|
||||
internal const string NodesMapRegionFileName = "nodes.map";
|
||||
internal const string WayMapRegionFileName = "ways.map";
|
||||
internal const string NodesRegionDirectory = "nodes";
|
||||
@ -168,8 +168,6 @@ public class Converter(float regionSize, string? exportFolderPath = null, ILogge
|
||||
int count = 0;
|
||||
DateTime print = DateTime.Now;
|
||||
DateTime start = DateTime.Now;
|
||||
List<ulong> wayIds = new();
|
||||
List<ulong> nodeIds = new();
|
||||
foreach (string path in wayRegionsPaths)
|
||||
{
|
||||
if (DateTime.Now - print > TimeSpan.FromSeconds(2))
|
||||
@ -182,6 +180,7 @@ public class Converter(float regionSize, string? exportFolderPath = null, ILogge
|
||||
}
|
||||
count++;
|
||||
|
||||
List<ulong> nodeIds = new();
|
||||
File.Copy(path, $"{path}.bak", true);
|
||||
StreamReader waysStreamReader = new(path, Encoding.UTF8, false, DefaultReadOptions);
|
||||
StreamWriter waysStreamWriter = new($"{path}.new", Encoding.UTF8, DefaultWriteOptions);
|
||||
@ -197,7 +196,6 @@ public class Converter(float regionSize, string? exportFolderPath = null, ILogge
|
||||
if (w.Tags.ContainsKey("highway"))
|
||||
{
|
||||
waysStreamWriter.WriteLine(line);
|
||||
wayIds.Add(w.ID);
|
||||
nodeIds.AddRange(w.NodeIds);
|
||||
hasWritten = true;
|
||||
}else
|
||||
@ -242,55 +240,10 @@ public class Converter(float regionSize, string? exportFolderPath = null, ILogge
|
||||
}
|
||||
}
|
||||
|
||||
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...");
|
||||
foreach (string bakFile in Directory.GetFiles(Path.Join(ExportFolderPath, WaysRegionDirectory), "*.bak")
|
||||
.Concat(Directory.GetFiles(Path.Join(ExportFolderPath, NodesRegionDirectory), "*.bak")))
|
||||
File.Delete(bakFile);
|
||||
File.Delete(nodeMapBak);
|
||||
File.Delete(wayMapBak);
|
||||
}
|
||||
|
||||
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 string ImportFolderPath = Path.Join(importFolderPath ?? Environment.CurrentDirectory, regionSize.ToString(CultureInfo.InvariantCulture));
|
||||
internal readonly string ImportFolderPath = importFolderPath ?? Path.Join(Environment.CurrentDirectory, regionSize.ToString(CultureInfo.InvariantCulture));
|
||||
private const string NodesMapRegionFileName = "nodes.map";
|
||||
private const string WayMapRegionFileName = "ways.map";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user