Added more logging,

Fixed map loading
This commit is contained in:
C9Glax 2022-05-11 22:18:13 +02:00
parent 97d3cc8af9
commit 559e26891e

View File

@ -40,6 +40,8 @@ namespace OpenStreetMap_Importer
} }
XmlReader reader = XmlReader.Create(mapData, readerSettings); XmlReader reader = XmlReader.Create(mapData, readerSettings);
reader.MoveToContent(); reader.MoveToContent();
logger?.Log(LogLevel.INFO, "Importing ways and counting nodes...");
while (reader.Read()) while (reader.Read())
{ {
if (reader.Name == "way" && reader.IsStartElement()) if (reader.Name == "way" && reader.IsStartElement())
@ -103,13 +105,19 @@ namespace OpenStreetMap_Importer
} }
} }
logger?.Log(LogLevel.DEBUG, "Ways: {0} Nodes: {1}", ways.Count, nodes.Count); logger?.Log(LogLevel.DEBUG, "Loaded Ways: {0} Required Nodes: {1}", ways.Count, count.Count);
reader.Close(); reader.Close();
if (File.Exists(filePath)) GC.Collect();
if (!File.Exists(filePath))
{
mapData = new MemoryStream(OSM_Data.map);
logger?.Log(LogLevel.INFO, "Filepath '{0}' does not exist. Using standard file.", filePath);
}
else
{ {
mapData.Close();
mapData = new FileStream(filePath, FileMode.Open, FileAccess.Read); mapData = new FileStream(filePath, FileMode.Open, FileAccess.Read);
logger?.Log(LogLevel.INFO, "Using file '{0}'", filePath);
} }
reader = XmlReader.Create(mapData, readerSettings); reader = XmlReader.Create(mapData, readerSettings);
reader.MoveToContent(); reader.MoveToContent();
@ -118,6 +126,7 @@ namespace OpenStreetMap_Importer
* Second iteration * Second iteration
* Import nodes that are needed by the "ways" * Import nodes that are needed by the "ways"
*/ */
logger?.Log(LogLevel.INFO, "Importing nodes...");
while (reader.Read()) while (reader.Read())
{ {
if (reader.Name == "node") if (reader.Name == "node")
@ -134,13 +143,11 @@ namespace OpenStreetMap_Importer
} }
} }
} }
logger?.Log(LogLevel.INFO, "Import finished. Calculating distances.");
/* /*
* Add connections between nodes (only junctions, e.g. nodes are referenced more than once) * Add connections between nodes (only junctions, e.g. nodes are referenced more than once)
* Remove non-junction nodes * Remove non-junction nodes
*/ */
logger?.Log(LogLevel.INFO, "Calculating Edges and distances...");
ulong edges = 0; ulong edges = 0;
foreach(Way way in ways) foreach(Way way in ways)
{ {
@ -212,10 +219,9 @@ namespace OpenStreetMap_Importer
} }
} }
reader.Close(); reader.Close();
GC.Collect();
logger?.Log(LogLevel.DEBUG, "Loaded Edges: {0}", edges);
logger?.Log(LogLevel.DEBUG, "Edges: {0}", edges);
return nodes.Where(node => count[node.Key] > 1).ToDictionary(node => node.Key, node => node.Value); return nodes.Where(node => count[node.Key] > 1).ToDictionary(node => node.Key, node => node.Value);
} }