/// <summary> /// Fast way to get data from the response Open Street Map Overpass API. /// </summary> /// <param name="response">Response from Overpass API</param> /// <param name="nodes">Dictionary of nodes</param> /// <param name="ways">List of ways</param> /// <param name="relations">List of relations</param> public static void ParseOSMResponseFast(string response, out Dictionary <string, OnlineMapsOSMNode> nodes, out Dictionary <string, OnlineMapsOSMWay> ways, out List <OnlineMapsOSMRelation> relations) { int i = 0; OSMXMLNode rootNode = new OSMXMLNode(response, ref i); if (rootNode.childs == null) { nodes = new Dictionary <string, OnlineMapsOSMNode>(); ways = new Dictionary <string, OnlineMapsOSMWay>(); relations = new List <OnlineMapsOSMRelation>(); return; } int countNodes = 0; int countWays = 0; int countRelations = 0; for (int j = 0; j < rootNode.childs.Count; j++) { OSMXMLNode node = rootNode.childs[j]; if (node.name == "node") { countNodes++; } else if (node.name == "way") { countWays++; } else if (node.name == "relation") { countRelations++; } } nodes = new Dictionary <string, OnlineMapsOSMNode>(countNodes); ways = new Dictionary <string, OnlineMapsOSMWay>(countWays); relations = new List <OnlineMapsOSMRelation>(countRelations); for (int j = 0; j < rootNode.childs.Count; j++) { OSMXMLNode node = rootNode.childs[j]; if (node.name == "node") { nodes.Add(node.GetAttribute("id"), new OnlineMapsOSMNode(node)); } else if (node.name == "way") { OnlineMapsOSMWay way = new OnlineMapsOSMWay(node); if (!ways.ContainsKey(way.id)) { ways.Add(way.id, way); } } else if (node.name == "relation") { relations.Add(new OnlineMapsOSMRelation(node)); } } }
private void ParseChild(string s, ref int i) { OSMXMLNode child = new OSMXMLNode(s, ref i); if (childs == null) { childs = new List <OSMXMLNode>(); } childs.Add(child); }