示例#1
0
        /// <summary>
        /// Load the OpenMap data resource file.
        /// </summary>
        /// <param name="resourceFile">Path to the resource file. The file must exist.</param>
        public void Read(string resourceFile)
        {
            nodes    = new Dictionary <ulong, OsmNode>();
            ways     = new Dictionary <ulong, OsmWay>();
            busStops = new Dictionary <string, ulong>();
            nearestRoadNodesToBusStops = new Dictionary <ulong, ulong>();
            roadNodes = new HashSet <ulong>();


            var xmlText = File.ReadAllText(resourceFile);//MapFile.mapdata;//

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xmlText);

            SetBounds(doc.SelectSingleNode("/osm/bounds"));
            GetNodes(doc.SelectNodes("/osm/node"));
            GetWays(doc.SelectNodes("/osm/way"));
            setClosestNodes();

            float minx = (float)MercatorProjection.lonToX(bounds.MinLon);
            float maxx = (float)MercatorProjection.lonToX(bounds.MaxLon);
            float miny = (float)MercatorProjection.latToY(bounds.MinLat);
            float maxy = (float)MercatorProjection.latToY(bounds.MaxLat);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="node">Xml node</param>
        public OsmBounds(XmlNode node)
        {
            // Get the values from the node
            MinLat = GetAttribute <float>("minlat", node.Attributes);
            MaxLat = GetAttribute <float>("maxlat", node.Attributes);
            MinLon = GetAttribute <float>("minlon", node.Attributes);
            MaxLon = GetAttribute <float>("maxlon", node.Attributes);

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

            Centre = new Coordinates(x, 0, y);
        }
示例#3
0
        // /// <summary>
        // /// Implicit conversion between OsmNode and Vector3.
        // /// </summary>
        // /// <param name="node">OsmNode instance</param>
        // public static implicit operator Coordinates (OsmNode node)
        // {
        //     return new Coordinates(node.X, node.Y, 0);
        // }

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="node">Xml node</param>
        public OsmNode(XmlNode node, OsmNode firstNode)
        {
            // Get the attribute values
            Id        = GetAttribute <ulong>("id", node.Attributes);
            Latitude  = GetAttribute <float>("lat", node.Attributes);
            Longitude = GetAttribute <float>("lon", node.Attributes);

            // Calculate the position in Unity units
            X = MercatorProjection.lonToX(Longitude) * 0.1f;
            Y = MercatorProjection.latToY(Latitude) * 0.1f;

            if (firstNode == null)
            {
                coords = new Coordinates(MapReader.offsetX, 0, MapReader.offsetY);
            }
            else
            {
                coords = new Coordinates((X - firstNode.X) + MapReader.offsetX, 0, (Y - firstNode.Y) + MapReader.offsetY);
            }

            XmlNodeList tags = node.SelectNodes("tag");

            foreach (XmlNode t in tags)
            {
                string key = GetAttribute <string>("k", t.Attributes);
                if (key == "highway")
                {
                    string value = GetAttribute <string>("v", t.Attributes);
                    if (value == "bus_stop")
                    {
                        isBusStop = true;
                    }
                }
                else if (key == "naptan:AtcoCode")
                {
                    string value = GetAttribute <string>("v", t.Attributes);
                    actoCode = value;
                }
            }
            if (isBusStop && actoCode == "")
            {
                //throw new System.Exception("Is bus stop but no actoCode: node " + Id);
                isBusStop = false;
            }
        }