Fixed "highway" tag to key instead of value
Memory usage decrease
This commit is contained in:
parent
b6ca87ea72
commit
87944997db
@ -50,26 +50,27 @@ namespace OSMImporter
|
|||||||
Dictionary<ulong, Node?> retSet = new Dictionary<ulong, Node?>();
|
Dictionary<ulong, Node?> retSet = new Dictionary<ulong, Node?>();
|
||||||
while (xmlReader.ReadToFollowing("way"))
|
while (xmlReader.ReadToFollowing("way"))
|
||||||
{
|
{
|
||||||
byte[] byteArray = Encoding.ASCII.GetBytes(xmlReader.ReadOuterXml());
|
XmlReader wayReader = xmlReader.ReadSubtree();
|
||||||
MemoryStream wayStream = new MemoryStream(byteArray);
|
|
||||||
XmlReader wayReader = XmlReader.Create(wayStream);
|
|
||||||
bool addNodes = false;
|
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;
|
addNodes = true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
wayReader.Close();
|
||||||
|
|
||||||
if (addNodes)
|
if (addNodes)
|
||||||
{
|
{
|
||||||
wayStream.Position = 0;
|
foreach (string nodeId in nodeIds)
|
||||||
wayReader = XmlReader.Create(wayStream);
|
|
||||||
while (wayReader.ReadToFollowing("nd"))
|
|
||||||
{
|
{
|
||||||
retSet.TryAdd(Convert.ToUInt64(wayReader.GetAttribute("ref")!), null);
|
retSet.TryAdd(Convert.ToUInt64(nodeId), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,31 +100,29 @@ namespace OSMImporter
|
|||||||
{
|
{
|
||||||
while (xmlReader.ReadToFollowing("way"))
|
while (xmlReader.ReadToFollowing("way"))
|
||||||
{
|
{
|
||||||
byte[] byteArray = Encoding.ASCII.GetBytes(xmlReader.ReadOuterXml());
|
XmlReader wayReader = xmlReader.ReadSubtree();
|
||||||
MemoryStream wayStream = new MemoryStream(byteArray);
|
HashSet<ulong> nodesInWay = new ();
|
||||||
XmlReader wayReader = XmlReader.Create(wayStream);
|
Dictionary<string, string> tags = new ();
|
||||||
Dictionary<string, string> tags = new Dictionary<string, string>();
|
|
||||||
|
|
||||||
bool addNodes = false;
|
bool addNodes = false;
|
||||||
while (wayReader.ReadToFollowing("tag"))
|
while (wayReader.Read())
|
||||||
{
|
{
|
||||||
if (wayReader.GetAttribute("v")!.Equals("highway"))
|
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;
|
addNodes = true;
|
||||||
}
|
}
|
||||||
tags.Add(wayReader.GetAttribute("k")!, value: wayReader.GetAttribute("v")!);
|
tags.Add(wayReader.GetAttribute("k")!, value: wayReader.GetAttribute("v")!);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
wayReader.Close();
|
||||||
|
|
||||||
if (addNodes)
|
if (addNodes)
|
||||||
{
|
{
|
||||||
HashSet<ulong> nodesInWay = new HashSet<ulong>();
|
|
||||||
wayStream.Position = 0;
|
|
||||||
wayReader = XmlReader.Create(wayStream);
|
|
||||||
while (wayReader.ReadToFollowing("nd"))
|
|
||||||
{
|
|
||||||
nodesInWay.Add(Convert.ToUInt64(wayReader.GetAttribute("ref")));
|
|
||||||
}
|
|
||||||
ConnectNodesOfWay(nodes, nodesInWay.ToArray(), tags);
|
ConnectNodesOfWay(nodes, nodesInWay.ToArray(), tags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user