Ejemplo n.º 1
0
        public void SearchClosestVertexTest()
        {
            var graph = new GeometricGraph(1);

            graph.AddVertex(0, 1, 1);
            graph.AddVertex(1, 2, 2);

            graph.Sort();

            Assert.AreEqual(0, graph.SearchClosest(1, 1, 1, 1));
            Assert.AreEqual(1, graph.SearchClosest(2, 2, 1, 1));
            Assert.AreEqual(Constants.NO_VERTEX, graph.SearchClosest(3, 3, .5f, .5f));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Searches for an edge that has the exact start- and endpoints given within the given tolerance.
        /// </summary>
        public static uint SearchEdgeExact(this GeometricGraph graph, Coordinate location1, Coordinate location2, float tolerance)
        {
            var vertex1 = graph.SearchClosest(location1.Latitude, location1.Longitude, 0.01f, 0.01f);

            if (vertex1 == Constants.NO_VERTEX)
            {
                return(Constants.NO_EDGE);
            }
            var vertex1Location = graph.GetVertex(vertex1);

            if (Coordinate.DistanceEstimateInMeter(location1, vertex1Location) > tolerance)
            {
                return(Constants.NO_EDGE);
            }
            var edgeEnumerator = graph.GetEdgeEnumerator();
            var best           = float.MaxValue;
            var bestEdge       = Constants.NO_EDGE;

            while (edgeEnumerator.MoveNext())
            {
                var vertex2Location = graph.GetVertex(edgeEnumerator.To);
                var dist            = Coordinate.DistanceEstimateInMeter(location2, vertex2Location);
                if (dist < tolerance &&
                    dist < best)
                {
                    best     = dist;
                    bestEdge = edgeEnumerator.Id;
                }
            }
            return(bestEdge);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Executes the actual algorithm.
        /// </summary>
        protected override void DoRun()
        {
            // calculate maxOffset in degrees.
            var offsettedLocation = (new Coordinate(_latitude, _longitude)).OffsetWithDistances(_maxOffsetInMeter);
            var latitudeOffset    = System.Math.Abs(_latitude - offsettedLocation.Latitude);
            var longitudeOffset   = System.Math.Abs(_longitude - offsettedLocation.Longitude);

            // get the closest edge.
            uint vertexId = _graph.SearchClosest(_latitude, _longitude,
                                                 latitudeOffset, longitudeOffset, _isAcceptable);

            if (vertexId == Constants.NO_EDGE)
            { // oeps, no edge was found, too far from road network.
                this.ErrorMessage = string.Format("Could not resolve point at [{0}, {1}]. Probably too far from closest road or outside of the loaded network.",
                                                  _latitude.ToInvariantString(), _longitude.ToInvariantString());
                return;
            }

            _result = _graph.CreateRouterPointForVertex(vertexId, _isAcceptable);

            this.HasSucceeded = true;
        }