예제 #1
0
 private void LoadOsmNodes(XmlNodeList xmlNodeList)
 {
     foreach (XmlNode n in xmlNodeList)
     {
         ulong ID = XmlAttributeParser.GetAttribute <ulong>("id", n.Attributes);
         preloadNodes[ID] = n;
     }
 }
예제 #2
0
        public void buildNodeID()
        {
            ulong ID = XmlAttributeParser
                       .GetAttribute <ulong>("id", nodeData.Attributes);

            node.setID(ID);
            node.setGameObjectName($"Node_{node.getID()}");
        }
예제 #3
0
 public static void ParseNodeAttributes(XmlNode node, XmlAttributeParser parser, string attributeName = null)
 {
     if (node != null)
     {
         foreach (XmlAttribute attr in node.Attributes)
         {
             if (attributeName == null || attributeName.ToLower() == attr.Name.ToLower())
             {
                 parser(attr.Name, attr.Value);
             }
         }
     }
 }
예제 #4
0
        private void LoadOsmWayTags(XmlNode way)
        {
            ulong       wayID   = XmlAttributeParser.GetAttribute <ulong>("id", way.Attributes);
            XmlNodeList wayTags = way.SelectNodes("tag");

            graphData.metadata.AddItem(wayID, new Meta.Metadata());

            var wayMetadata = graphData.metadata.GetItem(wayID);

            foreach (XmlNode t in wayTags)
            {
                string key   = XmlAttributeParser.GetAttribute <string>("k", t.Attributes);
                string value = XmlAttributeParser.GetAttribute <string>("v", t.Attributes);

                Metatag tag = new Metatag(key, value);

                wayMetadata.addMetatag(tag);
            }
        }
예제 #5
0
        private void GetOsmBoundsCentre(XmlNode node)
        {
            var MaxLat = XmlAttributeParser
                         .GetAttribute <float>("maxlat", node.Attributes);
            var MinLat = XmlAttributeParser
                         .GetAttribute <float>("minlat", node.Attributes);
            var MinLon = XmlAttributeParser
                         .GetAttribute <float>("minlon", node.Attributes);
            var MaxLon = XmlAttributeParser
                         .GetAttribute <float>("maxlon", node.Attributes);

            // Create the centre location of OSM data
            float x = (float)((MercatorProjection
                               .lonToX(MaxLon) + MercatorProjection.lonToX(MinLon)) / 2);
            float z = (float)((MercatorProjection
                               .latToY(MaxLat) + MercatorProjection.latToY(MinLat)) / 2);

            BoundsCentre = new Vector3(x, 0, z);
        }
예제 #6
0
        public void buildNodePositionWithOffset(Vector3 offset)
        {
            float Latitude = XmlAttributeParser
                             .GetAttribute <float>("lat", nodeData.Attributes);
            float Longitude = XmlAttributeParser
                              .GetAttribute <float>("lon", nodeData.Attributes);

            // Debug.Log(Latitude + " " + Longitude);

            float X = (float)MercatorProjection
                      .lonToX(Longitude) - offset.x;
            float Z = (float)MercatorProjection
                      .latToY(Latitude) - offset.z;
            float Y = 0;

            node.setNodePosition(new Vector3(X, Y, Z));

            // Debug.Log(new Vector3(X, Y, Z));
        }
    private void ParseXmlFile(StreamReader reader)
    {
        // N.B we use XPath rather than XMLDocument because we want line info for error reporting
        using (XmlReader xmlReader = XmlReader.Create(reader))
        {
            XPathDocument  controlDoc = new XPathDocument(xmlReader);
            XPathNavigator xpathNav   = controlDoc.CreateNavigator();

            string targetHeader           = string.Empty;
            string targetSource           = string.Empty;
            string srcIncludePath         = string.Empty;
            string declarationIncludePath = string.Empty;

            var cppNode = xpathNav.SelectSingleNode("/CPP");
            if (cppNode != null)
            {
                targetHeader           = XmlAttributeParser.ToString(cppNode, "TargetHeader");
                targetSource           = XmlAttributeParser.ToString(cppNode, "TargetSource");
                srcIncludePath         = XmlAttributeParser.ToString(cppNode, "SrcInclude");
                declarationIncludePath = XmlAttributeParser.ToString(cppNode, "DeclarationsInclude");
            }
            else
            {
                throw new XmlException("Expecting section /CPP");
            }

            string xpathQuery = "/CPP/Component";

            XPathExpression   xpathExpr         = xpathNav.Compile(xpathQuery);
            XPathNodeIterator componentIterator = xpathNav.Select(xpathExpr);

            componentGenerator.Prepare(targetHeader, targetSource, srcIncludePath, declarationIncludePath);

            while (componentIterator.MoveNext())
            {
                var n = componentIterator.Current;
                if (n != null)
                {
                    try
                    {
                        ComponentDefinition def;
                        def.ComponentInterface = XmlAttributeParser.ToString(n, "Interface");

                        Console.WriteLine("Generating code for component '{0}' in '{1}' and '{2}'", def.ComponentInterface, targetHeader, targetSource);

                        componentGenerator.GenerateCode(def);
                    }
                    catch (Exception ex)
                    {
                        IXmlLineInfo lineInfo = (IXmlLineInfo)n;
                        if (lineInfo != null)
                        {
                            throw new XmlException("Error building component", ex, lineInfo.LineNumber, lineInfo.LinePosition);
                        }
                        else
                        {
                            throw new XmlException("Error building component", ex);
                        }
                    }
                }
            }
        }
    }
예제 #8
0
        private void BuildNodesFromWay(XmlNode way)
        {
            XmlNodeList referencedNodes = way.SelectNodes("nd");

            ulong wayID = XmlAttributeParser.GetAttribute <ulong>("id", way.Attributes);

            Transform nodeAttachParent = GameObject.Find("Nodes").transform;

            if (graphData.metadata.ContainsID(wayID))
            {
                var wayMetadata = graphData.metadata.GetItem(wayID);

                if (wayMetadata.containsMetatagPair(key: "boundary", value: "postal_code") ||
                    wayMetadata.containsMetatagKey("frequency"))
                {
                    // Skip uninteresting osm data
                    return;
                }

                for (int i = 0; i < referencedNodes.Count; i++)
                {
                    ulong nodeID = XmlAttributeParser
                                   .GetAttribute <ulong>("ref", referencedNodes[i].Attributes);

                    if (wayMetadata.containsComponentWithID(nodeID))
                    {
                        // In certain cases a single node may appear twice
                        // in a single osm way (forming a loop)

                        NodeComponent existingNode = graphData.nodes.GetItem(nodeID);
                        wayMetadata.addComponent(existingNode);
                    }
                    else if (graphData.nodes.ContainsID(nodeID))
                    {
                        // Often single node may be present in multiple
                        // osm ways, if node with certain ID is already created,
                        // again only add the reference

                        NodeComponent existingNode = graphData.nodes.GetItem(nodeID);
                        wayMetadata.addComponent(existingNode);
                    }
                    else
                    {
                        /* BUILD NEW NODE */
                        XmlNode nodeData = preloadNodes[nodeID];

                        nodeBuilder.reset();
                        nodeBuilder.passNodeData(nodeData);
                        nodeBuilder.buildNodeID();
                        nodeBuilder.buildNodePositionWithOffset(BoundsCentre);
                        nodeBuilder.processMetadata(wayID);

                        NodeComponent newNode = nodeBuilder.getNode();
                        graphData.nodes.AddItem(newNode.getID(), newNode);
                        wayMetadata.addComponent(newNode);

                        newNode.gameObject.transform.parent = nodeAttachParent;
                    }
                }
            }
            else
            {
                throw new NamedException($"Way with {wayID} ID was not instantantiated.");
            }
        }