Example #1
0
 /// <summary>
 /// Callback function for OSMXmlDataReader, checks whether node is used and adds the used node into DB
 /// </summary>
 /// <param name="node">The node read form the OSM file</param>
 void NodeRead(OSMNode node)
 {
     if (_usedNodes.ContainsKey(node.ID))
     {
         _storage.Nodes.Add(node);
     }
 }
Example #2
0
    private void Update()
    {
        /// check if the thread has finished his work
        if (parser != null)
        {
            if (parser.Update())
            {
                /// here the thread have finished
                /// lets get the data from the parser
                loadBounds();
                loadNodes();
                loadWays();

                /// set the parser to null to ignore it one time has finished
                parser     = null;
                downloaded = true;
            }
        }

        if (parser == null && nodes != null && GetComponent <UTerrain>() != null && GetComponent <UTerrain>().isFullyLoaded&& !nodesSettedInTerrain)
        {
            foreach (DictionaryEntry e in nodes)
            {
                OSMNode n = (OSMNode)e.Value;
                n.pos.y = GetComponent <Terrain>().SampleHeight(n.pos + transform.position) + GetComponent <Terrain>().GetPosition().y;
            }

            nodesSettedInTerrain = true;
        }
    }
Example #3
0
    private void getNodes()
    {
        /// node structure:
        /// <osm>
        ///     <node id="1423405850" lat="48.1405398" lon="11.5430526"/>
        ///     <node id="1463405850" lat="48.1872398" lon="11.5830526">
        ///         <tag k="waterway" v="river"/>
        ///     </node>
        /// </osm>

        nodes = new Hashtable();
        XmlNodeList nodeList = xmlData.SelectNodes("/osm/node");

        foreach (XmlNode n in nodeList)
        {
            double lat = double.Parse(n.Attributes["lat"].Value);
            double lon = double.Parse(n.Attributes["lon"].Value);

            /// Add node
            long id = long.Parse(n.Attributes["id"].Value);

            OSMNode node = new OSMNode(id, lon, lat);

            /// adding all the node tags
            foreach (XmlNode tag in n.SelectNodes("tag"))
            {
                string k = tag.Attributes["k"].Value;
                string v = tag.Attributes["v"].Value;
                node.tags.Add(k, v);
            }

            nodes.Add(id, node);
        }
    }
Example #4
0
    public OSMData(string osmXMLpath)
    {
        XmlTextReader xmlReader = new XmlTextReader(osmXMLpath);

        xmlReader.MoveToContent();
        while (xmlReader.Read())
        {
            if (xmlReader.NodeType.Equals(XmlNodeType.Element))
            {
                switch (xmlReader.LocalName)
                {
                case "node":
                    OSMNode n = ParseOSMNode(xmlReader);
                    nodes.Add(n.Id, n);
                    break;

                case "way":
                    OSMWay way = ParseOSMWay(xmlReader);
                    ways.Add(way.Id, way);
                    break;

                case "relation":
                    OSMRelation relation = ParseOSMRelation(xmlReader);
                    relations.Add(relation.Id, relation);
                    break;

                default:
                    //ignore other nodes
                    break;
                }
            }
        }
        UnityEngine.Debug.Log("New OSMDATA: " + nodes.Count + " Nodes " + ways.Count + " Ways " + relations.Count + " Relations");
        Console.AddMessage("New OSMDATA: " + nodes.Count + " Nodes " + ways.Count + " Ways " + relations.Count + " Relations");
    }
Example #5
0
    private static void ReadTrailNode(OSMData trailData, Dictionary <long, OSMNode> wayNodes, XmlElement node)
    {
        OSMNode trailNode = new OSMNode();

        if (node.ChildNodes.Count > 0)
        {
            string iconName = "";
            string name     = "";
            foreach (XmlElement childNode in node.ChildNodes)
            {
                if (childNode.LocalName.Equals(tagElement) && childNode.GetAttribute("k").Equals(iconKeyValue))
                {
                    iconName = childNode.GetAttribute("v");
                }
                else if (childNode.LocalName.Equals(tagElement) && childNode.GetAttribute("k").Equals(POIName))
                {
                    name = childNode.GetAttribute("v");
                }
            }
            if (!iconName.Equals("") && !name.Equals(""))
            {
                POINode poiNode = new POINode(iconName, name);
                poiNode.id  = long.Parse(node.GetAttribute(idAttribute));
                poiNode.lat = float.Parse(node.GetAttribute(latAttribute));
                poiNode.lon = float.Parse(node.GetAttribute(lonAttribute));
                trailData.AddPOI(poiNode);
            }
        }

        trailNode.id  = long.Parse(node.GetAttribute(idAttribute));
        trailNode.lat = float.Parse(node.GetAttribute(latAttribute));
        trailNode.lon = float.Parse(node.GetAttribute(lonAttribute));

        wayNodes.Add(trailNode.id, trailNode);
    }
Example #6
0
 /// <summary>
 /// On node found.
 /// </summary>
 /// <param name="node">Node.</param>
 protected void OnNodeFound(OSMNode node)
 {
     if (this.FoundNode != null)
     {
         this.FoundNode(node);
     }
 }
Example #7
0
 /// <summary>
 /// On node found.
 /// </summary>
 /// <param name="node">Node.</param>
 /// <param name="rawData">Raw data.</param>
 /// <param name="infos">Infos.</param>
 protected void OnNodeFound(OSMNode node, byte[] rawData, ElementDebugInfos infos)
 {
     if (this.FoundNodeRaw != null)
     {
         this.FoundNodeRaw(node, rawData, infos);
     }
 }
Example #8
0
        public static void SaveCandidateIncomingConnections(CandidatePoint candidate, string filename)
        {
            int   counter = -1;
            OSMDB result  = new OSMDB();

            OSMNode osmCandidate = new OSMNode(counter--, candidate.MapPoint.Latitude, candidate.MapPoint.Longitude);

            osmCandidate.Tags.Add(new OSMTag("observation", candidate.ObservationProbability.ToString()));
            osmCandidate.Tags.Add(new OSMTag("time", candidate.Layer.TrackPoint.Time.ToString()));
            result.Nodes.Add(osmCandidate);
            foreach (var connection in candidate.IncomingConnections)
            {
                OSMNode from = new OSMNode(counter--, connection.From.MapPoint.Latitude, connection.From.MapPoint.Longitude);
                from.Tags.Add(new OSMTag("observation", connection.From.ObservationProbability.ToString()));
                from.Tags.Add(new OSMTag("time", connection.From.Layer.TrackPoint.Time.ToString()));
                result.Nodes.Add(from);

                OSMWay osmConnection = new OSMWay(counter--, new long[] { from.ID, osmCandidate.ID });
                osmConnection.Tags.Add(new OSMTag("transmission", connection.TransmissionProbability.ToString()));

                result.Ways.Add(osmConnection);
            }

            result.Save(filename);
        }
Example #9
0
        static void GenerateOsmFiles(List <Bucket> buckets, PathReconstructer reconstructor, OSMDB map, List <GPXTrack> gpxTrackList)
        {
            foreach (var b in buckets)
            {
                if (b.Paths.Any())
                {
                    var mapCopy = ObjectCopier.Clone <OSMDB>(map);
                    List <Polyline <IPointGeo> > pathList = new List <Polyline <IPointGeo> >();

                    OSMNode bucketInfo = new OSMNode(0, 0, 0);
                    OSMTag  start      = new OSMTag("start", b.Start.ToString());
                    OSMTag  end        = new OSMTag("end", b.End.ToString());
                    bucketInfo.Tags.Add(start);
                    bucketInfo.Tags.Add(end);

                    foreach (var p in b.Paths)
                    {
                        var uniquePath = p.Value.GroupBy(x => new { x.Id }).Select(x => x.First());

                        foreach (var seg in uniquePath)
                        {
                            if (seg.Id != 0)
                            {
                                var matchingWay = mapCopy.Ways[seg.Id];
                                var avgSpeed    = getAverageSpeed(p.Key, gpxTrackList);

                                if (avgSpeed != null)
                                {
                                    if (matchingWay.Tags.ContainsTag("avgSpeed"))
                                    {
                                        matchingWay.Tags["avgSpeed"].Value = avgSpeed;
                                    }
                                    else
                                    {
                                        matchingWay.Tags.Add(new OSMTag("avgSpeed", avgSpeed));
                                    }
                                }

                                if (matchingWay.Tags.ContainsTag("traffic"))
                                {
                                    matchingWay.Tags["traffic"].Value += "," + p.Key;
                                }
                                else
                                {
                                    matchingWay.Tags.Add(new OSMTag("traffic", p.Key));
                                }
                            }
                        }
                        pathList.AddRange(uniquePath);
                    }

                    //OSMDB resultMap = reconstructor.SaveToOSM(pathList);
                    //resultMap.Save("map" + b.Name + ".osm");

                    mapCopy.Nodes.Add(bucketInfo);
                    mapCopy.Save("map" + b.Name + ".osm");
                }
            }
        }
Example #10
0
 public void MapCoordinates(OSMNode node)
 {
     if (node != null)
     {
         Vector2 pos = Vector2.zero;
         GetPos(node.lon, node.lat, ref pos);
     }
 }
Example #11
0
 void GetNodes(XmlNodeList xmlNodeList)
 {
     foreach (XmlNode n in xmlNodeList)
     {
         OSMNode node = new OSMNode(n);
         nodes[node.ID] = node;
     }
 }
Example #12
0
    private static void OnObjectCreated(OSMapInfo mapInfo, OSMWay way, Vector3 origin, List <Vector3> vectors, List <Vector3> normals, List <Vector2> uvs, List <int> indices)
    {
        for (int i = 1; i < way.NodeIDs.Count; i++)
        {
            OSMNode p1 = mapInfo.Nodes[way.NodeIDs[i - 1]];
            OSMNode p2 = mapInfo.Nodes[way.NodeIDs[i]];

            Vector3 s1 = p1 - origin;
            Vector3 s2 = p2 - origin;

            Vector3 diff = (s2 - s1).normalized;
            // elongate the road a little bit
            s1 -= diff;
            s2 += diff;

            // https://en.wikipedia.org/wiki/Lane
            // According to the article, it's 3.7m in Canada
            var cross = Vector3.Cross(diff, Vector3.up) * 3.7f * way.Lanes;

            // Create points that represent the width of the road
            Vector3 v1 = s1 + cross;
            Vector3 v2 = s1 - cross;
            Vector3 v3 = s2 + cross;
            Vector3 v4 = s2 - cross;

            vectors.Add(v1);
            vectors.Add(v2);
            vectors.Add(v3);
            vectors.Add(v4);

            uvs.Add(new Vector2(0, 0));
            uvs.Add(new Vector2(1, 0));
            uvs.Add(new Vector2(0, 1));
            uvs.Add(new Vector2(1, 1));

            normals.Add(Vector3.up);
            normals.Add(Vector3.up);
            normals.Add(Vector3.up);
            normals.Add(Vector3.up);

            int idx1, idx2, idx3, idx4;
            idx4 = vectors.Count - 1;
            idx3 = vectors.Count - 2;
            idx2 = vectors.Count - 3;
            idx1 = vectors.Count - 4;

            // first triangle v1, v3, v2
            indices.Add(idx1);
            indices.Add(idx3);
            indices.Add(idx2);

            // second         v3, v4, v2
            indices.Add(idx3);
            indices.Add(idx4);
            indices.Add(idx2);
        }
    }
Example #13
0
        /// <summary>
        /// Raises the NodeRead event
        /// </summary>
        /// <param name="node">The OSMNode read from the database</param>
        protected void OnNodeRead(OSMNode node)
        {
            OSMNodeReadHandler temp = NodeRead;

            if (temp != null)
            {
                temp(node);
            }
        }
Example #14
0
 public void AddNode(OSMNode node)
 {
     if (node != null)
     {
         if (!nodes.Keys.Contains(node.Id))
         {
             nodes.Add(node.Id, node);
         }
     }
 }
Example #15
0
    public HighwayNode(OSMNode osmNode, Vector3 MapCenter, string Name)
    {
        ID = osmNode.ID;

        float XCoord = osmNode.XCoord;
        float YCoord = osmNode.YCoord;

        Position   = new Vector3(XCoord, 0.0f, YCoord) - MapCenter;
        Neighbours = new List <HighwayNode>();
        this.Name  = Name;
    }
Example #16
0
        /// <summary>
        /// Saves path to the OSMDB
        /// </summary>
        /// <param name="path">The list of polylines that represent matched path</param>
        /// <returns>OSMDB with path converted to the OSM format</returns>
        public OSMDB SaveToOSM(IList <Polyline <IPointGeo> > path)
        {
            _db        = new OSMDB();
            _dbCounter = -1;

            IPointGeo lastPoint = null;
            OSMNode   node      = null;

            foreach (var line in path)
            {
                if (line.Nodes.Count == 0)
                {
                    continue;
                }

                if (line.Nodes.Count == 1)
                {
                    throw new Exception();
                }

                OSMWay way = new OSMWay(_dbCounter--);
                way.Tags.Add(new OSMTag("way-id", ((PolylineID)line).WayID.ToString()));
                way.Tags.Add(new OSMTag("order", (_db.Ways.Count + 1).ToString()));
                _db.Ways.Add(way);
                foreach (var point in line.Nodes)
                {
                    if (point != lastPoint)
                    {
                        lastPoint = point;
                        PointEx pt = (PointEx)point;

                        node = new OSMNode(_dbCounter--, pt.Latitude, pt.Longitude);
                        if (pt.NodeID != 0)
                        {
                            node.Tags.Add(new OSMTag("node-id", pt.NodeID.ToString()));
                        }
                        if (pt.Time != DateTime.MinValue)
                        {
                            node.Tags.Add(new OSMTag("time", pt.Time.ToString()));
                        }
                        if (pt.Crossroad)
                        {
                            node.Tags.Add(new OSMTag("crossroad", "yes"));
                        }

                        _db.Nodes.Add(node);
                    }
                    way.Nodes.Add(node.ID);
                }
            }

            return(_db);
        }
Example #17
0
 public static bool TryCreateFromOSM(OSMNode node, Tile tile)
 {
     if (node.Tags.ContainsKey("highway"))
     {
         if (node.Tags["highway"] == "traffic_signals")
         {
             TrafficSignals.Add(new TrafficSignal(node, tile.Query.OSM), tile);
             return(true);
         }
     }
     return(false);
 }
Example #18
0
    private void DrawWay(OSMapInfo mapInfo, OSMWay way, Color color)
    {
        for (int i = 1; i < way.NodeIDs.Count; i++)
        {
            OSMNode p1 = mapInfo.Nodes[way.NodeIDs[i - 1]];
            OSMNode p2 = mapInfo.Nodes[way.NodeIDs[i]];

            Vector3 v1 = p1 - mapInfo.Bounds.Center;
            Vector3 v2 = p2 - mapInfo.Bounds.Center;

            Debug.DrawLine(v1, v2, color);
        }
    }
Example #19
0
        /// <summary>
        /// Writes the specific OSMNode to the output
        /// </summary>
        /// <param name="node">The OSMNode to be written.</param>
        public void WriteNode(OSMNode node)
        {
            _xmlWriter.WriteStartElement("node");

            WriteOSMObjectAttributes(node);

            _xmlWriter.WriteAttributeString("lat", node.Latitude.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
            _xmlWriter.WriteAttributeString("lon", node.Longitude.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));

            WriteOSMObjectTags(node);

            _xmlWriter.WriteEndElement();
        }
Example #20
0
        /// <summary>
        /// Gets PointEx from the internal storage or creates a new one (for given point)
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        PointEx GetOrCreatePointEx(IPointGeo point, DateTime time)
        {
            if (_points.ContainsKey(point))
            {
                if (_points[point].Time == DateTime.MinValue || _points[point].Time == time)
                {
                    _points[point].Time = time;
                    return(_points[point]);
                }
                else
                {
                    PointEx result = new PointEx()
                    {
                        Latitude = point.Latitude, Longitude = point.Longitude, Elevation = point.Elevation, Time = time
                    };
                    _points[point] = result;

                    OSMNode pointOSM = point as OSMNode;
                    if (pointOSM != null)
                    {
                        result.NodeID = pointOSM.ID;
                        if (pointOSM.Tags.ContainsTag("crossroad"))
                        {
                            result.Crossroad = true;
                        }
                    }
                    return(result);
                }
            }
            else
            {
                PointEx result = new PointEx()
                {
                    Latitude = point.Latitude, Longitude = point.Longitude, Elevation = point.Elevation, Time = time
                };
                _points.Add(point, result);

                OSMNode pointOSM = point as OSMNode;
                if (pointOSM != null)
                {
                    result.NodeID = pointOSM.ID;
                    if (pointOSM.Tags.ContainsTag("crossroad"))
                    {
                        result.Crossroad = true;
                    }
                }
                return(result);
            }
        }
Example #21
0
    /*
     * <!ELEMENT node (tag*)>
     * <!ATTLIST node id                CDATA #REQUIRED>
     * <!ATTLIST node lat               CDATA #REQUIRED>
     * <!ATTLIST node lon               CDATA #REQUIRED>
     * <!ATTLIST node changeset         CDATA #IMPLIED>
     * <!ATTLIST node visible           (true|false) #REQUIRED>
     * <!ATTLIST node user              CDATA #IMPLIED>
     * <!ATTLIST node timestamp         CDATA #IMPLIED>
     * */
    public static OSMNode ParseNode(XmlNode node)
    {
        OSMNode osmNode = new OSMNode();

        //bool keep = false;

        // parse node-attributes
        foreach (XmlAttribute attribute in node.Attributes)
        {
            //string name = ;
            switch (attribute.Name)
            {
            case "id":
                osmNode.Id = long.Parse(attribute.Value);
                break;

            case "lat":
                osmNode.Latitude = float.Parse(attribute.Value, CultureInfo.CreateSpecificCulture("en-US"));
                break;

            case "lon":
                osmNode.Longitude = float.Parse(attribute.Value, CultureInfo.CreateSpecificCulture("en-US"));
                break;

            case "visible":
                osmNode.Visible = bool.Parse(attribute.Value);
                //keep = osmNode.visible;
                break;

            case "version":
                osmNode.version = int.Parse(attribute.Value);
                break;

            default:
                break;
            }
        }

        foreach (XmlNode child in node.ChildNodes)
        {
            if (child.Name == "tag")
            {
                //osmNode.AddTag(OSMParser.ReadKeyValue(child));
                osmNode.AddTag(node.Attributes[0].Value, node.Attributes[1].Value);
            }
        }
        return(osmNode);
    }
Example #22
0
        private void ReadNode()
        {
            string attId = _xmlReader.GetAttribute("id");

            if (attId == null)
            {
                throw new XmlException("Attribute 'id' is missing.");
            }
            long nodeId = long.Parse(attId, System.Globalization.CultureInfo.InvariantCulture);

            string attLat = _xmlReader.GetAttribute("lat");

            if (attLat == null)
            {
                throw new XmlException("Attribute 'lat' is missing.");
            }
            double nodeLat = double.Parse(attLat, System.Globalization.CultureInfo.InvariantCulture);

            string attLon = _xmlReader.GetAttribute("lon");

            if (attLon == null)
            {
                throw new XmlException("Attribute 'lon'is missing.");
            }
            double nodeLon = double.Parse(attLon, System.Globalization.CultureInfo.InvariantCulture);

            OSMNode node = new OSMNode(nodeId, nodeLat, nodeLon);

            if (_xmlReader.IsEmptyElement == false)
            {
                _xmlReader.Read();

                while (_xmlReader.NodeType != XmlNodeType.EndElement)
                {
                    if (_xmlReader.NodeType == XmlNodeType.Element && _xmlReader.Name == "tag")
                    {
                        node.Tags.Add(ReadTag());
                    }
                    else
                    {
                        _xmlReader.Skip();
                    }
                }
            }

            OnNodeRead(node);
            _xmlReader.Skip();
        }
Example #23
0
    /*
     * public bool loadOSM(string filePath)
     * {
     *  // load OSM data
     *  string rawData = OSMLoader.loadFromFile(filePath);
     *  if (rawData == "") return false;
     *
     *  // initialize the parser
     *  parser = new OSMParser();
     *  parser.load(rawData);
     *  loadBounds();
     *
     *  return true;
     * }
     */

    private bool loadNodes()
    {
        nodes = parser.nodes;

        /// normalize
        double minX = UMaths.lon2x(minLon);
        double minY = UMaths.lat2y(minLat);

        /// Mercator
        foreach (DictionaryEntry e in nodes)
        {
            OSMNode n = (OSMNode)e.Value;
            n.pos.x = (float)UMaths.lon2x(n.lon) - (float)minX;
            n.pos.z = (float)UMaths.lat2y(n.lat) - (float)minY;
        }
        return(true);
    }
Example #24
0
    private OSMNode ParseOSMNode(XmlTextReader xmlReader)
    {
        OSMNode node   = new OSMNode(long.Parse(xmlReader.GetAttribute("id")), float.Parse(xmlReader.GetAttribute("lat")), float.Parse(xmlReader.GetAttribute("lon")));
        string  childs = xmlReader.ReadOuterXml();

        XmlTextReader outerXmlReader = new XmlTextReader(new System.IO.StringReader(childs));

        outerXmlReader.MoveToContent();
        while (outerXmlReader.Read())
        {
            if (outerXmlReader.NodeType.Equals(XmlNodeType.Element) && outerXmlReader.LocalName.Equals("tag"))
            {
                node.AddTag(outerXmlReader.GetAttribute("k"), outerXmlReader.GetAttribute("v"));
            }
        }
        return(node);
    }
Example #25
0
    public static OSMMap ParseMap(XmlDocument doc, ref XmlTextReader xmlReader, ref OSMMap osmMap)
    {
        //osmMap = new OSMMap();

        XmlNode rootnode = doc.ReadNode(xmlReader);

        OSMMap.ParseOSMHeader(rootnode, ref osmMap);

        int nodeCount     = 0;
        int wayCount      = 0;
        int relationCount = 0;

        foreach (XmlNode node in rootnode.ChildNodes)
        {
            switch (node.Name)
            {
            case "bounds":
                osmMap.AddBounds(OSMMap.ParseBounds(node, ref osmMap));
                break;

            case "node":
                nodeCount++;
                osmMap.AddNode(OSMNode.ParseNode(node));
                break;

            case "way":
                wayCount++;
                osmMap.AddWay(OSMWay.ParseWay(node, ref osmMap));
                break;

            case "relation":
                relationCount++;
                osmMap.AddRelation(OSMRelation.ParseRelation(node, ref osmMap));
                break;

            default:
                break;
            }
        }
        //Console.WriteLine("nodeCount = {0} = {1}", nodeCount, osmMap.nodes.Count);
        //Console.WriteLine("wayCount = {0} = {1}", wayCount, osmMap.ways.Count);
        //Console.WriteLine("relationCount = {0} = {1}", relationCount, osmMap.relations.Count);

        return(osmMap);
    }
Example #26
0
    public void AddDisplayNode(OSMNode node, OSMNode nextNode)
    {
        if (nodeGenerationRate < 1)
        {
            return;
        }

        for (int i = 1; i <= this.nodeGenerationRate; i++)
        {
            Vector2 point = mapData.GetMapSpecificCoordinatesRelativeToTopLeftFromLatLon(
                new MapPoint(
                    x: (double)(i * (nextNode.lon - node.lon) / (nodeGenerationRate + 1) + node.lon),
                    y: (double)(i * (nextNode.lat - node.lat) / (nodeGenerationRate + 1) + node.lat)
                    )
                );
            displayNodes.Add(new DisplayNode((int)point.x, (int)point.y));
        }
    }
Example #27
0
    public List <DisplayNode> TranslateTrail(Trail trail)
    {
        displayNodes = new List <DisplayNode> ();
        List <OSMNode> nodes = trail.GetNodeList();

        for (int i = 0; i < nodes.Count - 1; i++)
        {
            OSMNode node     = nodes[i];
            OSMNode nextNode = nodes[i + 1];
            AddDisplayNode(node);
            AddDisplayNode(node, nextNode);
        }
        OSMNode lastNode = nodes[nodes.Count - 1];

        AddDisplayNode(lastNode);

        return(displayNodes);
    }
Example #28
0
        private void WriteNode(OSMNode node, out byte[] writtenData)
        {
            if (!this._nodesStarted)
            {
                this.Reset();
                this._stream.WriteByte((byte)O5MFileByteMarker.Reset);
                this._nodesStarted = true;
            }

            this._stream.WriteByte((byte)O5MFileByteMarker.Node);

            var bytes   = new List <byte>();
            var diffId  = (long)node.Id - this._lastNodeId;
            var idBytes = VarintBitConverter.GetVarintBytes(diffId);

            bytes.AddRange(idBytes);
            this._lastNodeId = (long)node.Id;

            this.WriteVersionData(node, bytes);

            var varIntLongitude = (int)Math.Round(node.Longitude * POINT_DIVIDER);
            var diffLongitude   = varIntLongitude - this._lastLongitude;
            var longitudeBytes  = VarintBitConverter.GetVarintBytes(diffLongitude);

            bytes.AddRange(longitudeBytes);
            this._lastLongitude = varIntLongitude;

            var varIntLatitude = (int)Math.Round(node.Latitude * POINT_DIVIDER);
            var diffLatitude   = varIntLatitude - this._lastLatitude;
            var latitudeBytes  = VarintBitConverter.GetVarintBytes(diffLatitude);

            bytes.AddRange(latitudeBytes);
            this._lastLatitude = varIntLatitude;

            this.WriteTags(node, bytes);

            var length = VarintBitConverter.GetVarintBytes((ulong)bytes.Count);

            this._stream.Write(length, 0, length.Length);
            writtenData = bytes.ToArray();
            this._stream.Write(writtenData, 0, bytes.Count);
        }
Example #29
0
 private void CreateHighwayNodesFromWay(OSMWay osmWay)
 {
     foreach (ulong nodeID in osmWay.NodeIDs)
     {
         HighwayNode highwayNode;
         NavInfo.Nodes.TryGetValue(nodeID, out highwayNode);
         if (null == highwayNode)
         {
             OSMNode osmNode = MapInfo.Nodes[nodeID];
             highwayNode = new HighwayNode(osmNode, MapInfo.Bounds.Center, osmWay.Name);
             NavInfo.Nodes[highwayNode.ID] = highwayNode;
         }
         else
         {
             if (highwayNode.Name.Equals("") && !osmWay.Name.Equals(""))
             {
                 highwayNode.Name = osmWay.Name;
                 NavInfo.Nodes[highwayNode.ID] = highwayNode;
             }
         }
     }
 }
Example #30
0
    private static void ReadWay(Dictionary <long, OSMway> ways, XmlElement node)
    {
        OSMway way = new OSMway(long.Parse(node.GetAttribute(idAttribute)));

        foreach (XmlElement childNode in node.ChildNodes)
        {
            if (childNode.LocalName.Equals(childNodeElement))
            {
                OSMNode wayNode = new OSMNode();
                wayNode.id = long.Parse(childNode.GetAttribute(refAttribute));
                way.AddNode(wayNode);
            }
            if (childNode.LocalName.Equals(tagElement))
            {
                way.AddTag(childNode.GetAttribute("k"), childNode.GetAttribute("v"));
            }
            else if (childNode.GetAttribute("k").Equals(labelName))
            {
                way.AddTag(childNode.GetAttribute("k"), childNode.GetAttribute("v"));
            }
        }
        ways.Add(way.GetID(), way);
    }