public override void AddWay(Way way)
        {
            if (!way.Tags.ContainsKey("highway"))
            {
                return;
            }

            if (_firstPass)
            { // keep track of nodes that are used as routing nodes.
                _nodeIndex.AddId(way.Nodes[0]);
                for (var i = 0; i < way.Nodes.Length; i++)
                {
                    _nodeIndex.AddId(way.Nodes[i]);
                }
                _nodeIndex.AddId(way.Nodes[way.Nodes.Length - 1]);
            }
            else
            {
                var vertex1 = VertexId.Empty;
                var shape   = new List <Coordinate>();
                for (var n = 0; n < way.Nodes.Length; n++)
                {
                    var node = way.Nodes[n];
                    if (!_vertexPerNode.TryGetValue(node, out var vertex2))
                    {     // no already a vertex, get the coordinates and it's status.
                        if (!_nodeIndex.TryGetValue(node, out var latitude, out var longitude, out var isCore, out _, out _))
                        { // an incomplete way, node not in source.
                            isCore = false;
                            break;
                        }

                        if (!isCore)
                        { // node is just a shape point, keep it but don't add is as a vertex.
                            shape.Add(new Coordinate(longitude, latitude));
                            continue;
                        }
                        else
                        { // node is a core vertex, add it as a vertex.
                            vertex2 = _routerDb.AddVertex(longitude, latitude);
                            _vertexPerNode[node] = vertex2;
                        }
                    }

                    if (vertex1.IsEmpty())
                    {
                        vertex1 = vertex2;
                        continue;
                    }

                    _routerDb.AddEdge(vertex1, vertex2,
                                      shape: shape,
                                      attributes: new TagAttributeCollection(way.Tags));
                    vertex1 = vertex2;
                    shape.Clear();
                }
            }
        }
Ejemplo n.º 2
0
        public void NodeIndex_Regression1()
        {
            var index = new NodeIndex();

            index.AddId(4444197607);

            index.SortAndConvertIndex();
            var i = index.TryGetIndex(4444197607);

            Assert.AreEqual(0, i);
        }
Ejemplo n.º 3
0
        public void TestNegativeIds()
        {
            var index = new NodeIndex();

            index.AddId(-128510752);
            index.SortAndConvertIndex();
            index.Set(-128510752, 11);

            index.TryGetValue(-128510752, out var latitude, out var longitude, out var isCore, out var vertex);
            Assert.AreEqual(float.MaxValue, latitude);
            Assert.AreEqual(float.MaxValue, longitude);
            Assert.AreEqual(false, isCore);
            Assert.AreEqual(11, vertex);
        }
Ejemplo n.º 4
0
        public void TestNegativeIds()
        {
            var index = new NodeIndex();

            index.AddId(-128510752);
            index.Set(-128510752, 11);

            float latitude, longitude;
            bool  isCore;
            uint  vertex;

            index.TryGetValue(-128510752, out latitude, out longitude, out isCore, out vertex);
            Assert.AreEqual(float.MaxValue, latitude);
            Assert.AreEqual(float.MaxValue, longitude);
            Assert.AreEqual(false, isCore);
            Assert.AreEqual(11, vertex);
        }