Fixed "highway" tag to key instead of value

Memory usage decrease
This commit is contained in:
C9Glax 2023-02-05 20:44:23 +01:00
parent b6ca87ea72
commit 87944997db

View File

@ -50,26 +50,27 @@ namespace OSMImporter
Dictionary<ulong, Node?> retSet = new Dictionary<ulong, Node?>();
while (xmlReader.ReadToFollowing("way"))
{
byte[] byteArray = Encoding.ASCII.GetBytes(xmlReader.ReadOuterXml());
MemoryStream wayStream = new MemoryStream(byteArray);
XmlReader wayReader = XmlReader.Create(wayStream);
XmlReader wayReader = xmlReader.ReadSubtree();
bool addNodes = false;
while (wayReader.ReadToFollowing("tag") && !addNodes)
HashSet<string> nodeIds = new();
while (wayReader.Read())
{
if (wayReader.GetAttribute("v")!.Equals("highway"))
if (xmlReader.IsStartElement() && xmlReader.Name.Equals("nd"))
{
nodeIds.Add(wayReader.GetAttribute("ref")!);
}
else if (xmlReader.IsStartElement() && !addNodes && xmlReader.Name.Equals("tag") && xmlReader.GetAttribute("k")!.Equals("highway"))
{
addNodes = true;
break;
}
}
wayReader.Close();
if (addNodes)
{
wayStream.Position = 0;
wayReader = XmlReader.Create(wayStream);
while (wayReader.ReadToFollowing("nd"))
foreach (string nodeId in nodeIds)
{
retSet.TryAdd(Convert.ToUInt64(wayReader.GetAttribute("ref")!), null);
retSet.TryAdd(Convert.ToUInt64(nodeId), null);
}
}
}
@ -99,31 +100,29 @@ namespace OSMImporter
{
while (xmlReader.ReadToFollowing("way"))
{
byte[] byteArray = Encoding.ASCII.GetBytes(xmlReader.ReadOuterXml());
MemoryStream wayStream = new MemoryStream(byteArray);
XmlReader wayReader = XmlReader.Create(wayStream);
Dictionary<string, string> tags = new Dictionary<string, string>();
XmlReader wayReader = xmlReader.ReadSubtree();
HashSet<ulong> nodesInWay = new ();
Dictionary<string, string> tags = new ();
bool addNodes = false;
while (wayReader.ReadToFollowing("tag"))
while (wayReader.Read())
{
if (wayReader.GetAttribute("v")!.Equals("highway"))
{
addNodes = true;
}
tags.Add(wayReader.GetAttribute("k")!, value: wayReader.GetAttribute("v")!);
}
if (addNodes)
{
HashSet<ulong> nodesInWay = new HashSet<ulong>();
wayStream.Position = 0;
wayReader = XmlReader.Create(wayStream);
while (wayReader.ReadToFollowing("nd"))
if (wayReader.IsStartElement() && wayReader.Name.Equals("nd"))
{
nodesInWay.Add(Convert.ToUInt64(wayReader.GetAttribute("ref")));
}
else if (wayReader.IsStartElement() && wayReader.Name.Equals("tag"))
{
if (wayReader.GetAttribute("k")!.Equals("highway"))
{
addNodes = true;
}
tags.Add(wayReader.GetAttribute("k")!, value: wayReader.GetAttribute("v")!);
}
}
wayReader.Close();
if (addNodes)
{
ConnectNodesOfWay(nodes, nodesInWay.ToArray(), tags);
}
}