/// <summary>
        /// Compares the two given routes.
        /// </summary>
        /// <param name="reference"></param>
        /// <param name="route"></param>
        protected void CompareRoutes(Route reference, Route route)
        {
            double delta = 0.0001;

            if (reference.Segments == null)
            { // both routes are empty.
                Assert.IsNull(route.Segments);
            }
            else
            { // compare the geometry of the routes.
                for (int idx = 0; idx < reference.Segments.Length; idx++)
                {
                    var referenceCoordinate = new GeoCoordinate(reference.Segments[idx].Latitude,
                        reference.Segments[idx].Longitude);
                    Meter referenceDistance, distance;
                    GeoCoordinate referenceProjected, projected;
                    Second referenceTime, time;
                    reference.ProjectOn(referenceCoordinate, out referenceProjected, out referenceDistance, out referenceTime);
                    route.ProjectOn(referenceCoordinate, out projected, out distance, out time);

                    Assert.AreEqual(0, referenceProjected.DistanceReal(projected).Value, delta); // projected points have to match.
                    Assert.AreEqual(referenceDistance.Value, distance.Value, 0.1); // compare calculated distance to 10cm accuracy.
                    Assert.AreEqual(referenceProjected.Latitude, projected.Latitude, delta);
                    Assert.AreEqual(referenceProjected.Longitude, projected.Longitude, delta);
                }
            }
        }
 /// <summary>
 /// Calculates metrics for the given route.
 /// </summary>
 /// <param name="route"></param>
 /// <returns></returns>
 public Dictionary<string, double> Calculate(Route route)
 {
     OsmSharp.Routing.ArcAggregation.ArcAggregator aggregator =
         new OsmSharp.Routing.ArcAggregation.ArcAggregator(_interpreter);
     AggregatedPoint p = aggregator.Aggregate(route);
     return this.Calculate(route.Vehicle, p);
 }
Пример #3
0
 /// <summary>
 /// Adds a new OsmSharpRoute.
 /// </summary>
 /// <param name="route">Stream.</param>
 public void AddRoute(Route route)
 {
     // set the default color if none is given.
     SimpleColor blue = SimpleColor.FromKnownColor (KnownColor.Blue);
     SimpleColor transparantBlue = SimpleColor.FromArgb (128, blue.R, blue.G, blue.B);
     this.AddRoute (route, transparantBlue.Value);
 }
Пример #4
0
 /// <summary>
 /// Concatenates two routes.
 /// </summary>
 /// <param name="route1"></param>
 /// <param name="route2"></param>
 /// <returns></returns>
 public static Route Concatenate(Route route1, Route route2)
 {
     return Route.Concatenate(route1, route2, true);
 }
Пример #5
0
        public void RoutePositionAfterRegressionTest1()
        {
            var delta = .00001;

            // a route of approx 30 m along the following coordinates:
            // 50.98624687752063, 2.902620979360633
            // 50.98624687752063, 2.9027639004471673 (10m)
            // 50.986156907620895, 2.9027639004471673  (20m)
            // 50.9861564788317, 2.902620884621392 (30m)

            var route1 = new Route();
            route1.Vehicle = Vehicle.Car.UniqueName;
            var route1entry1 = new RouteSegment();
            route1entry1.Distance = -1;
            route1entry1.Latitude = 50.98624687752063f;
            route1entry1.Longitude = 2.902620979360633f;
            route1entry1.Metrics = null;
            route1entry1.Points = new RoutePoint[1];
            route1entry1.Points[0] = new RoutePoint();
            route1entry1.Points[0].Name = "TestPoint1";
            route1entry1.Points[0].Tags = new RouteTags[1];
            route1entry1.Points[0].Tags[0] = new RouteTags();
            route1entry1.Points[0].Tags[0].Value = "TestValue1";
            route1entry1.Points[0].Tags[0].Key = "TestKey1";
            route1entry1.SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch() { 
                        Latitude = 51, 
                        Longitude = 3.999f,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "name", Value = "Street B" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        Name = "Street B"
                    }
                };
            route1entry1.Tags = new RouteTags[1];
            route1entry1.Tags[0] = new RouteTags();
            route1entry1.Tags[0].Key = "highway";
            route1entry1.Tags[0].Value = "residential";
            route1entry1.Time = 10;
            route1entry1.Type = RouteSegmentType.Start;
            route1entry1.Name = string.Empty;
            route1entry1.Names = null;

            RouteSegment route1entry2 = new RouteSegment();
            route1entry2.Distance = -1;
            route1entry2.Latitude = 50.98624687752063f;
            route1entry2.Longitude = 2.9027639004471673f;
            route1entry2.Metrics = null;
            route1entry2.Points = new RoutePoint[1];
            route1entry2.Points[0] = new RoutePoint();
            route1entry2.Points[0].Name = "TestPoint2";
            route1entry2.Points[0].Tags = new RouteTags[1];
            route1entry2.Points[0].Tags[0] = new RouteTags();
            route1entry2.Points[0].Tags[0].Value = "TestValue2";
            route1entry1.Points[0].Tags[0].Key = "TestKey2";
            route1entry2.SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch() { 
                        Latitude = 51, 
                        Longitude = 3.999f,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "name", Value = "Street B" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        Name = "Street B"
                    }
                };
            route1entry2.Tags = new RouteTags[1];
            route1entry2.Tags[0] = new RouteTags();
            route1entry2.Tags[0].Key = "highway";
            route1entry2.Tags[0].Value = "residential";
            route1entry2.Time = 10;
            route1entry2.Type = RouteSegmentType.Start;
            route1entry2.Name = string.Empty;
            route1entry2.Names = null;

            RouteSegment route1entry3 = new RouteSegment();
            route1entry3.Distance = -1;
            route1entry3.Latitude = 50.986156907620895f;
            route1entry3.Longitude = 2.9027639004471673f;
            route1entry3.Metrics = null;
            route1entry3.Points = new RoutePoint[1];
            route1entry3.Points[0] = new RoutePoint();
            route1entry3.Points[0].Name = "TestPoint3";
            route1entry3.Points[0].Tags = new RouteTags[1];
            route1entry3.Points[0].Tags[0] = new RouteTags();
            route1entry3.Points[0].Tags[0].Value = "TestValue3";
            route1entry1.Points[0].Tags[0].Key = "TestKey3";
            route1entry3.SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch() { 
                        Latitude = 51, 
                        Longitude = 3.999f,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "name", Value = "Street B" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        Name = "Street B"
                    }
                };
            route1entry3.Tags = new RouteTags[1];
            route1entry3.Tags[0] = new RouteTags();
            route1entry3.Tags[0].Key = "highway";
            route1entry3.Tags[0].Value = "residential";
            route1entry3.Time = 10;
            route1entry3.Type = RouteSegmentType.Start;
            route1entry3.Name = string.Empty;
            route1entry3.Names = null;

            RouteSegment route1entry4 = new RouteSegment();
            route1entry4.Distance = -1;
            route1entry4.Latitude = 50.9861564788317f;
            route1entry4.Longitude = 2.902620884621392f;
            route1entry4.Metrics = null;
            route1entry4.Points = new RoutePoint[1];
            route1entry4.Points[0] = new RoutePoint();
            route1entry4.Points[0].Name = "TestPoint4";
            route1entry4.Points[0].Tags = new RouteTags[1];
            route1entry4.Points[0].Tags[0] = new RouteTags();
            route1entry4.Points[0].Tags[0].Value = "TestValue4";
            route1entry1.Points[0].Tags[0].Key = "TestKey4";
            route1entry4.SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch() { 
                        Latitude = 51, 
                        Longitude = 3.999f,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "name", Value = "Street B" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        Name = "Street B"
                    }
                };
            route1entry4.Tags = new RouteTags[1];
            route1entry4.Tags[0] = new RouteTags();
            route1entry4.Tags[0].Key = "highway";
            route1entry4.Tags[0].Value = "residential";
            route1entry4.Time = 10;
            route1entry4.Type = RouteSegmentType.Start;
            route1entry4.Name = string.Empty;
            route1entry4.Names = null;

            route1.Segments = new RouteSegment[4];
            route1.Segments[0] = route1entry1;
            route1.Segments[1] = route1entry2;
            route1.Segments[2] = route1entry3;
            route1.Segments[3] = route1entry4;

            // create the route tracker.
            var routeTracker = new RouteTracker(route1, new OsmRoutingInterpreter());

            var distance = 5.0;
            var location = route1.PositionAfter(distance);
            routeTracker.Track(location);
            Assert.AreEqual(distance, routeTracker.DistanceFromStart.Value, delta);
            Assert.AreEqual(location.Latitude, routeTracker.PositionRoute.Latitude, delta);
            Assert.AreEqual(location.Longitude, routeTracker.PositionRoute.Longitude, delta);
            Assert.AreEqual(new GeoCoordinate(route1.Segments[1].Latitude, route1.Segments[1].Longitude).DistanceReal(location).Value, routeTracker.DistanceNextInstruction.Value, delta);
            var locationAfter = routeTracker.PositionAfter(10.0);

            distance = 15.0;
            location = route1.PositionAfter(distance);
            Assert.AreEqual(location.Latitude, locationAfter.Latitude, delta);
            Assert.AreEqual(location.Longitude, locationAfter.Longitude, delta);
            routeTracker.Track(location);
            Assert.AreEqual(distance, routeTracker.DistanceFromStart.Value, delta);
            Assert.AreEqual(location.Latitude, routeTracker.PositionRoute.Latitude, delta);
            Assert.AreEqual(location.Longitude, routeTracker.PositionRoute.Longitude, delta);
            Assert.AreEqual(new GeoCoordinate(route1.Segments[2].Latitude, route1.Segments[2].Longitude).DistanceReal(location).Value, routeTracker.DistanceNextInstruction.Value, delta);

            location = new GeoCoordinate(route1.Segments[3].Latitude, route1.Segments[3].Longitude);
            Meter distanceFromStart;
            route1.ProjectOn(location, out distanceFromStart);
            distance = distanceFromStart.Value;
            routeTracker.Track(location);
            Assert.AreEqual(distance, routeTracker.DistanceFromStart.Value, delta);
            Assert.AreEqual(location.Latitude, routeTracker.PositionRoute.Latitude, delta);
            Assert.AreEqual(location.Longitude, routeTracker.PositionRoute.Longitude, delta);
            Assert.AreEqual(0, routeTracker.DistanceNextInstruction.Value, delta);
        }
Пример #6
0
        /// <summary>
        /// Concatenates two routes.
        /// </summary>
        /// <param name="route1"></param>
        /// <param name="route2"></param>
        /// <param name="clone"></param>
        /// <returns></returns>
        public static Route Concatenate(Route route1, Route route2, bool clone)
        {
            if (route1 == null) return route2;
            if (route2 == null) return route1;
            if (route1.Entries.Length == 0) return route2;
            if (route2.Entries.Length == 0) return route1;
            if (route1.Vehicle != route2.Vehicle) { throw new ArgumentException("Route vechicles do not match!"); }

            // get the end/start point.
            RoutePointEntry end = route1.Entries[route1.Entries.Length - 1];
            RoutePointEntry start = route2.Entries[0];

            // only do all this if the routes are 'concatenable'.
            if (end.Latitude == start.Latitude &&
                end.Longitude == start.Longitude)
            {
                // construct the new route.
                Route route = new Route();

                // concatenate points.
                List<RoutePointEntry> entries = new List<RoutePointEntry>();
                // add points for the first route except the last point.
                for (int idx = 0; idx < route1.Entries.Length - 1; idx++)
                {
                    if (clone)
                    {
                        entries.Add(route1.Entries[idx].Clone() as RoutePointEntry);
                    }
                    else
                    {
                        entries.Add(route1.Entries[idx]);
                    }
                }

                // merge last and first entry.
                RoutePointEntry mergedEntry =
                    route1.Entries[route1.Entries.Length - 1].Clone() as RoutePointEntry;
                mergedEntry.Type = RoutePointEntryType.Along;
                if (route2.Entries[0].Points != null && route2.Entries[0].Points.Length > 0)
                { // merge in important points from the second route too but do not keep duplicates.
                    List<RoutePoint> points = new List<RoutePoint>(mergedEntry.Points);
                    for (int otherIdx = 0; otherIdx < route2.Entries[0].Points.Length; otherIdx++)
                    {
                        bool found = false;
                        for (int idx = 0; idx < points.Count; idx++)
                        {
                            if (points[idx].RepresentsSame(
                                route2.Entries[0].Points[otherIdx]))
                            { // the points represent the same info!
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        { // the point was not in there yet!
                            points.Add(route2.Entries[0].Points[otherIdx]);
                        }
                    }
                    mergedEntry.Points = points.ToArray();
                }
                entries.Add(mergedEntry);

                // add points of the next route.
                for (int idx = 1; idx < route2.Entries.Length; idx++)
                {
                    if (clone)
                    {
                        entries.Add(route2.Entries[idx].Clone() as RoutePointEntry);
                    }
                    else
                    {
                        entries.Add(route2.Entries[idx]);
                    }
                }
                route.Entries = entries.ToArray();

                // concatenate tags.
                List<RouteTags> tags = new List<RouteTags>();
                if (route1.Tags != null) { tags.AddRange(route1.Tags); }
                if (route2.Tags != null) { tags.AddRange(route2.Tags); }
                route.Tags = tags.ToArray();

                //// calculate metrics.
                //Routing.Core.Metrics.Time.TimeCalculator calculator = new OsmSharp.Routing.Metrics.Time.TimeCalculator();
                //Dictionary<string, double> metrics = calculator.Calculate(route);
                //route.TotalDistance = metrics[Routing.Core.Metrics.Time.TimeCalculator.DISTANCE_KEY];
                //route.TotalTime = metrics[Routing.Core.Metrics.Time.TimeCalculator.TIME_KEY];

                // set the vehicle.
                route.Vehicle = route1.Vehicle;
                return route;
            }
            else
            {
                throw new ArgumentOutOfRangeException("Contatenation routes can only be done when the end point of the first route equals the start of the second.");
            }
        }
        /// <summary>
        /// Compares the two given routes.
        /// </summary>
        /// <param name="reference"></param>
        /// <param name="route"></param>
        protected void CompareRoutes(Route reference, Route route)
        {
            double delta = 0.0001;

            if (reference.Entries == null)
            {
                Assert.IsNull(route.Entries);
            }
            else
            {
                Assert.AreEqual(reference.Entries.Length, route.Entries.Length);
                for (int idx = 0; idx < reference.Entries.Length; idx++)
                {
                    Assert.AreEqual(reference.Entries[idx].Distance,
                        route.Entries[idx].Distance);
                    Assert.AreEqual(reference.Entries[idx].Latitude,
                        route.Entries[idx].Latitude);
                    Assert.AreEqual(reference.Entries[idx].Longitude,
                        route.Entries[idx].Longitude);
                    Assert.AreEqual(reference.Entries[idx].Time,
                        route.Entries[idx].Time);
                    Assert.AreEqual(reference.Entries[idx].Type,
                        route.Entries[idx].Type);
                    Assert.AreEqual(reference.Entries[idx].WayFromName,
                        route.Entries[idx].WayFromName);

                    // something that is allowed to be different in this case!
                    // route3540.Entries[idx].Points != null

                    // check sidestreets.
                    if (reference.Entries[idx].SideStreets != null &&
                        reference.Entries[idx].SideStreets.Length > 0)
                    { // check if the sidestreets represent the same information.
                        Assert.AreEqual(reference.Entries[idx].SideStreets.Length,
                            route.Entries[idx].SideStreets.Length);
                        for (int metricIdx = 0; metricIdx < reference.Entries[idx].SideStreets.Length; metricIdx++)
                        {
                            Assert.AreEqual(reference.Entries[idx].SideStreets[metricIdx].WayName,
                                route.Entries[idx].SideStreets[metricIdx].WayName);
                            Assert.AreEqual(reference.Entries[idx].SideStreets[metricIdx].Latitude,
                                route.Entries[idx].SideStreets[metricIdx].Latitude);
                            Assert.AreEqual(reference.Entries[idx].SideStreets[metricIdx].Longitude,
                                route.Entries[idx].SideStreets[metricIdx].Longitude);
                        }
                    }
                    else
                    { // check if the sidestreets represent the same information.
                        Assert.IsTrue(route.Entries[idx].SideStreets == null ||
                            route.Entries[idx].SideStreets.Length == 0);
                    }

                    if (reference.Entries[idx].Tags != null &&
                        reference.Entries[idx].Tags.Length > 0)
                    { // check if the Tags represent the same information.
                        Assert.AreEqual(reference.Entries[idx].Tags.Length,
                            route.Entries[idx].Tags.Length);
                        for (int metricIdx = 0; metricIdx < route.Entries[idx].Tags.Length; metricIdx++)
                        {
                            Assert.AreEqual(reference.Entries[idx].Tags[metricIdx].Key,
                                route.Entries[idx].Tags[metricIdx].Key);
                            Assert.AreEqual(reference.Entries[idx].Tags[metricIdx].Value,
                                route.Entries[idx].Tags[metricIdx].Value);
                        }
                    }
                    else
                    { // check if the sidestreets represent the same information.
                        Assert.IsTrue(route.Entries[idx].Tags == null ||
                            route.Entries[idx].Tags.Length == 0);
                    }

                    Assert.AreEqual(reference.Entries[idx].Distance, route.Entries[idx].Distance);
                }
                if (reference.Tags != null &&
                    reference.Tags.Length > 0)
                {
                    for (int tagIdx = 0; tagIdx < reference.Tags.Length; tagIdx++)
                    {
                        if (reference.Tags[tagIdx].Key != "debug_route")
                        {
                            Assert.AreEqual(reference.Tags[tagIdx].Key,
                                route.Tags[tagIdx].Key);
                            Assert.AreEqual(reference.Tags[tagIdx].Value,
                                route.Tags[tagIdx].Value);
                        }
                    }
                }
                else
                {
                    Assert.IsTrue(route.Tags == null ||
                        route.Tags.Length == 0);
                }
                if (reference.Metrics != null)
                {
                    for (int metricIdx = 0; metricIdx < reference.Entries.Length; metricIdx++)
                    {
                        Assert.AreEqual(reference.Metrics[metricIdx].Key,
                            route.Metrics[metricIdx].Key);
                        Assert.AreEqual(reference.Metrics[metricIdx].Value,
                            route.Metrics[metricIdx].Value);
                    }
                }
                else
                {
                    Assert.IsNull(route.Metrics);
                }
            }

            Assert.AreEqual(reference.TotalDistance, route.TotalDistance, delta);
            Assert.AreEqual(reference.TotalTime, route.TotalTime, delta);
            //Assert.AreEqual(reference.Vehicle, route.Vehicle, delta);
        }
Пример #8
0
        public void RouteToFeatureCollection()
        {
            // build a test route.
            var route = new Route();
            route.Vehicle = Vehicle.Car.UniqueName;
            var route1entry1 = new RouteSegment();
            route1entry1.Distance = 10;
            route1entry1.Latitude = -1;
            route1entry1.Longitude = -1;
            route1entry1.Metrics = null;
            route1entry1.Points = new RoutePoint[1];
            route1entry1.Points[0] = new RoutePoint();
            route1entry1.Points[0].Name = "TestPoint1";
            route1entry1.Points[0].Tags = new RouteTags[1];
            route1entry1.Points[0].Tags[0] = new RouteTags();
            route1entry1.Points[0].Tags[0].Value = "TestValue1";
            route1entry1.Points[0].Tags[0].Key = "TestKey1";
            route1entry1.SideStreets = null;
            route1entry1.Tags = new RouteTags[1];
            route1entry1.Tags[0] = new RouteTags();
            route1entry1.Tags[0].Key = "highway";
            route1entry1.Tags[0].Value = "residential";
            route1entry1.Time = 10;
            route1entry1.Type = RouteSegmentType.Start;
            route1entry1.Name = string.Empty;
            route1entry1.Names = null;

            var route1entry2 = new RouteSegment();
            route1entry2.Distance = 10;
            route1entry2.Latitude = -1;
            route1entry2.Longitude = -1;
            route1entry2.Metrics = null;
            route1entry2.Points = new RoutePoint[1];
            route1entry2.Points[0] = new RoutePoint();
            route1entry2.Points[0].Name = "TestPoint2";
            route1entry2.Points[0].Tags = new RouteTags[1];
            route1entry2.Points[0].Tags[0] = new RouteTags();
            route1entry2.Points[0].Tags[0].Value = "TestValue2";
            route1entry2.Points[0].Tags[0].Key = "TestKey2";
            route1entry2.SideStreets = null;
            route1entry2.Tags = new RouteTags[1];
            route1entry2.Tags[0] = new RouteTags();
            route1entry2.Tags[0].Key = "highway";
            route1entry2.Tags[0].Value = "residential";
            route1entry2.Time = 10;
            route1entry2.Type = RouteSegmentType.Start;
            route1entry2.Name = string.Empty;
            route1entry2.Names = null;

            route.Segments = new RouteSegment[2];
            route.Segments[0] = route1entry1;
            route.Segments[1] = route1entry2;

            // execute the conversion.
            var features = route.ToFeatureCollection();

            // check result, two points, one linestring.
            Assert.IsNotNull(features);
            Assert.AreEqual(3, features.Count);
            var featuresList = new List<Feature>(features);
            Assert.IsInstanceOf<Point>(featuresList[0].Geometry);
            Assert.IsInstanceOf<LineString>(featuresList[1].Geometry);
            Assert.IsInstanceOf<Point>(featuresList[2].Geometry);
        }
Пример #9
0
        public void RouteConcatenateTagsTest()
        {
            var route1 = new Route();
            route1.Vehicle = Vehicle.Car.UniqueName;
            var route1entry1 = new RouteSegment();
            route1entry1.Distance = 10;
            route1entry1.Latitude = -1;
            route1entry1.Longitude = -1;
            route1entry1.Metrics = null;
            route1entry1.Points = new RoutePoint[1];
            route1entry1.Points[0] = new RoutePoint();
            route1entry1.Points[0].Name = "TestPoint1";
            route1entry1.Points[0].Tags = new RouteTags[1];
            route1entry1.Points[0].Tags[0] = new RouteTags();
            route1entry1.Points[0].Tags[0].Value = "TestValue1";
            route1entry1.Points[0].Tags[0].Key = "TestKey1";
            route1entry1.SideStreets = null;
            route1entry1.Tags = new RouteTags[1];
            route1entry1.Tags[0] = new RouteTags();
            route1entry1.Tags[0].Key = "highway";
            route1entry1.Tags[0].Value = "residential";
            route1entry1.Time = 10;
            route1entry1.Type = RouteSegmentType.Start;
            route1entry1.Name = string.Empty;
            route1entry1.Names = null;

            RouteSegment route1entry2 = new RouteSegment();
            route1entry2.Distance = 10;
            route1entry2.Latitude = -1;
            route1entry2.Longitude = -1;
            route1entry2.Metrics = null;
            route1entry2.Points = new RoutePoint[1];
            route1entry2.Points[0] = new RoutePoint();
            route1entry2.Points[0].Name = "TestPoint2";
            route1entry2.Points[0].Tags = new RouteTags[1];
            route1entry2.Points[0].Tags[0] = new RouteTags();
            route1entry2.Points[0].Tags[0].Value = "TestValue2";
            route1entry1.Points[0].Tags[0].Key = "TestKey2";
            route1entry2.SideStreets = null;
            route1entry2.Tags = new RouteTags[1];
            route1entry2.Tags[0] = new RouteTags();
            route1entry2.Tags[0].Key = "highway";
            route1entry2.Tags[0].Value = "residential";
            route1entry2.Time = 10;
            route1entry2.Type = RouteSegmentType.Start;
            route1entry2.Name = string.Empty;
            route1entry2.Names = null;

            route1.Segments = new RouteSegment[2];
            route1.Segments[0] = route1entry1;
            route1.Segments[1] = route1entry2;

            var route2 = new Route();
            route2.Vehicle = Vehicle.Car.UniqueName;
            var route2entry1 = new RouteSegment();
            route2entry1.Distance = 10;
            route2entry1.Latitude = -1;
            route2entry1.Longitude = -1;
            route2entry1.Metrics = null;
            route2entry1.Points = new RoutePoint[1];
            route2entry1.Points[0] = new RoutePoint();
            route2entry1.Points[0].Name = "TestPoint3";
            route2entry1.Points[0].Tags = new RouteTags[1];
            route2entry1.Points[0].Tags[0] = new RouteTags();
            route2entry1.Points[0].Tags[0].Value = "TestValue3";
            route2entry1.Points[0].Tags[0].Key = "TestKey3";
            route2entry1.SideStreets = null;
            route2entry1.Tags = new RouteTags[1];
            route2entry1.Tags[0] = new RouteTags();
            route2entry1.Tags[0].Key = "highway";
            route2entry1.Tags[0].Value = "residential";
            route2entry1.Time = 10;
            route2entry1.Type = RouteSegmentType.Start;
            route2entry1.Name = string.Empty;
            route2entry1.Names = null;

            RouteSegment route2entry2 = new RouteSegment();
            route2entry2.Distance = 10;
            route2entry2.Latitude = -1;
            route2entry2.Longitude = -1;
            route2entry2.Metrics = null;
            route2entry2.Points = new RoutePoint[1];
            route2entry2.Points[0] = new RoutePoint();
            route2entry2.Points[0].Name = "TestPoint4";
            route2entry2.Points[0].Tags = new RouteTags[1];
            route2entry2.Points[0].Tags[0] = new RouteTags();
            route2entry2.Points[0].Tags[0].Value = "TestValue4";
            route2entry1.Points[0].Tags[0].Key = "TestKey4";
            route2entry2.SideStreets = null;
            route2entry2.Tags = new RouteTags[1];
            route2entry2.Tags[0] = new RouteTags();
            route2entry2.Tags[0].Key = "highway";
            route2entry2.Tags[0].Value = "residential";
            route2entry2.Time = 10;
            route2entry2.Type = RouteSegmentType.Start;
            route2entry2.Name = string.Empty;
            route2entry2.Names = null;

            route2.Segments = new RouteSegment[2];
            route2.Segments[0] = route2entry1;
            route2.Segments[1] = route2entry2;

            Route concatenated = Route.Concatenate(route1, route2);

            // test the result.
            Assert.IsNotNull(concatenated);
            Assert.IsNotNull(concatenated.Segments);
            Assert.AreEqual(route1.Vehicle, concatenated.Vehicle);
            Assert.AreEqual(3, concatenated.Segments.Length);
            Assert.AreEqual("TestPoint1", concatenated.Segments[0].Points[0].Name);
            Assert.AreEqual("TestPoint2", concatenated.Segments[1].Points[0].Name);
            Assert.AreEqual("TestPoint3", concatenated.Segments[1].Points[1].Name);
            Assert.AreEqual("TestPoint4", concatenated.Segments[2].Points[0].Name);
        }
Пример #10
0
        public void TestRoundaboutExtended()
        {
            var westWest = new GeoCoordinate(51, 3.998);
            var west = new GeoCoordinate(51, 3.999);
            var eastEast = new GeoCoordinate(51, 4.002);
            var east = new GeoCoordinate(51, 4.001);
            var north = new GeoCoordinate(51.001, 4);
            var northNorth = new GeoCoordinate(51.002, 4);
            var south = new GeoCoordinate(50.999, 4);
            var southSouth = new GeoCoordinate(50.998, 4);
            var southSouthSouth = new GeoCoordinate(50.997, 4);
            var center = new GeoCoordinate(51, 4);

            var route = new Route();
            route.Vehicle = Vehicle.Car.UniqueName;
            route.Segments = new RouteSegment[6];
            route.Segments[0] = new RouteSegment()
            {
                Distance = 0,
                Latitude = (float)southSouth.Latitude,
                Longitude = (float)southSouth.Longitude,
                Points = new RoutePoint[] { 
                    new RoutePoint() 
                    {
                        Latitude = (float)southSouthSouth.Latitude,
                        Longitude = (float)southSouthSouth.Longitude,
                        Name = "Start"
                    }},
                SideStreets = null,
                Type = RouteSegmentType.Start
            };
            route.Segments[1] = new RouteSegment()
            {
                Distance = 0,
                Latitude = (float)southSouth.Latitude,
                Longitude = (float)southSouth.Longitude,
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "name", Value = "SouthStreet" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                SideStreets = null,
                Type = RouteSegmentType.Along
            };
            route.Segments[2] = new RouteSegment()
            {
                Distance = 0,
                Latitude = (float)south.Latitude,
                Longitude = (float)south.Longitude,
                Type = RouteSegmentType.Along,
                Name = "SouthStreet",
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "name", Value = "SouthStreet" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch() { 
                        Latitude = (float)west.Latitude,
                        Longitude = (float)west.Longitude,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "junction", Value = "roundabout" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        Name = "Street B"
                    },
                    new RouteSegmentBranch() { 
                        Latitude = (float)east.Latitude,
                        Longitude = (float)east.Longitude,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "junction", Value = "roundabout" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        Name = "Street B"
                    }
                }
            };
            route.Segments[3] = new RouteSegment()
            {
                Distance = 0,
                Latitude = (float)east.Latitude,
                Longitude = (float)east.Longitude,
                Type = RouteSegmentType.Along,
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "junction", Value = "roundabout" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch() { 
                        Latitude = (float)eastEast.Latitude,
                        Longitude = (float)eastEast.Longitude,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "name", Value = "EastStreet" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        Name = "EastStreet"
                    }
                }
            };
            route.Segments[4] = new RouteSegment()
            {
                Distance = 0,
                Latitude = (float)north.Latitude,
                Longitude = (float)north.Longitude,
                Type = RouteSegmentType.Along,
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "junction", Value = "roundabout" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch() { 
                        Latitude = (float)west.Latitude,
                        Longitude = (float)west.Longitude,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "junction", Value = "roundabout" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        }
                    }
                }
            };
            route.Segments[5] = new RouteSegment()
            {
                Distance = 0,
                Latitude = (float)northNorth.Latitude,
                Longitude = (float)northNorth.Longitude,
                Type = RouteSegmentType.Stop,
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "name", Value = "NorthStreet" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                Points = new RoutePoint[] { 
                    new RoutePoint() 
                    {
                        Latitude = (float)north.Latitude,
                        Longitude = (float)north.Longitude,
                        Name = "Stop"
                    }}
            };

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // generate instructions.
            List<Instruction> instructions = InstructionGenerator.Generate(route, new OsmRoutingInterpreter(), languageGenerator);
            Assert.AreEqual(3, instructions.Count);
            Assert.AreEqual("GenerateRoundabout:3", instructions[1].Text);
        }
Пример #11
0
 /// <summary>
 /// Calculates instructions for a given route.
 /// </summary>
 /// <param name="route"></param>
 /// <returns></returns>
 public override List<Instruction> GetInstructions(Route route)
 {
     return InstructionGenerator.Generate(route, new OsmRoutingInterpreter());
 }
Пример #12
0
        /// <summary>
        /// Converts the given route to a line string.
        /// </summary>
        /// <returns></returns>
        public override FeatureCollection GetFeatures(Route route, RouteAggregationType aggregationType)
        {
            if (aggregationType == RouteAggregationType.All ||
                aggregationType == RouteAggregationType.Modal)
            { // one mode, one LineString.
                var featureCollection = new FeatureCollection();
                var coordinates = route.GetPoints();
                if (coordinates.Count > 1)
                {
                    var lineString = new LineString(coordinates.ToArray());

                    var attributes = new SimpleGeometryAttributeCollection();
                    attributes.Add("osmsharp:total_time", route.TotalTime.ToInvariantString());
                    attributes.Add("osmsharp:total_distance", route.TotalDistance.ToInvariantString());

                    var feature = new Feature(lineString, attributes);

                    featureCollection.Add(feature);
                }
                return featureCollection;
            }
            else
            { // one LineString per instruction.
                var instructions = this.GetInstructions(route);
                var featureCollection = new FeatureCollection();
                for (int i = 0; i < instructions.Count; i++)
                {
                    var instruction = instructions[i];
                    var coordinates = new List<GeoCoordinate>();
                    for (int segmentIdx = instruction.FirstSegmentIdx; segmentIdx <= instruction.LastSegmentIdx; segmentIdx++)
                    {
                        coordinates.Add(new GeoCoordinate(route.Segments[segmentIdx].Latitude, route.Segments[segmentIdx].Longitude));
                    }

                    // build attributes.
                    var currentArcTags = instruction.MetaData;
                    var attributesTable = new SimpleGeometryAttributeCollection();
                    if (currentArcTags != null)
                    { // there are tags.
                        foreach (var tag in currentArcTags)
                        {
                            if (tag.Value != null)
                            {
                                var t = tag.Value.GetType();
                                if (t.IsPrimitive || t == typeof(Decimal) || t == typeof(String))
                                {
                                    attributesTable.Add(tag.Key, tag.Value);
                                }
                            }
                        }
                    }

                    // build feature.
                    var lineString = new LineString(coordinates);
                    featureCollection.Add(new Feature(lineString, attributesTable));

                    // build poi-features if any.
                    if (instruction.Pois != null)
                    {
                        foreach (var poi in instruction.Pois)
                        {
                            // build attributes.
                            var poiTags = poi.Tags;
                            var poiAttributesTable = new SimpleGeometryAttributeCollection();
                            if (poiTags != null)
                            { // there are tags.
                                foreach (var tag in poiTags)
                                {
                                    poiAttributesTable.Add(tag.Key, tag.Value);
                                }
                            }

                            // build feature.
                            var point = new Point(poi.Location);
                            featureCollection.Add(new Feature(point, poiAttributesTable));
                        }
                    }
                }
                return featureCollection;
            }
        }
Пример #13
0
        /// <summary>
        /// Builds a route along all the given points.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="resolved"></param>
        /// <param name="coordinates"></param>
        /// <returns></returns>
        public Route BuildRoute(Vehicle vehicle, RouterPoint[] resolved, GeoCoordinate[] coordinates)
        {
            var routes = new Route[resolved.Length - 1];
            for (int idx = 1; idx < resolved.Length; idx++)
            {
                if (resolved[idx - 1] == null || resolved[idx] == null)
                { // failed to resolve point(s), replace with a dummy route.
                    routes[idx - 1] = null;
                }
                else
                { // both points are resolved, calculate route.
                    var localRoute = _router.Calculate(vehicle, resolved[idx - 1], resolved[idx]);
                    if (localRoute != null)
                    { // route was found.
                        routes[idx - 1] = localRoute;
                    }
                    else
                    { // failed to calculate route, replace with a dummy route.
                        routes[idx - 1] = null;
                    }
                }
            }

            // add dummy routes in place of routes that have not been found.
            for (int idx = 0; idx < routes.Length; idx++)
            {
                if (routes[idx] == null)
                { // the route is null here.
                    GeoCoordinate coordinate1, coordinate2;
                    if (idx > 0 &&
                        routes[idx - 1] != null)
                    { // there is a route before this one, take the last point of it as start of this one.
                        coordinate1 = new GeoCoordinate(
                            routes[idx - 1].Segments[routes[idx - 1].Segments.Length - 1].Latitude,
                            routes[idx - 1].Segments[routes[idx - 1].Segments.Length - 1].Longitude);
                    }
                    else
                    { // take the coordinate itself.
                        coordinate1 = coordinates[idx];
                    }
                    if (routes.Length > idx + 1 &&
                        routes[idx + 1] != null)
                    { // there is a route before this one, take the last point of it as start of this one.
                        coordinate2 = new GeoCoordinate(
                            routes[idx + 1].Segments[0].Latitude,
                            routes[idx + 1].Segments[0].Longitude);
                    }
                    else
                    { // take the coordinate itself.
                        coordinate2 = coordinates[idx + 1];
                    }

                    // build the dummy route.
                    routes[idx] = this.BuildDummyRoute(vehicle, coordinate1, coordinate2);
                }
            }

            // concatenate the routes.
            var route = routes[0];
            for (int idx = 1; idx < routes.Length; idx++)
            {
                route = Route.Concatenate(route, routes[idx]);
            }
            return route;
        }
Пример #14
0
 /// <summary>
 /// Creates a new OsmSharpRoute enumerable.
 /// </summary>
 /// <param name="route"></param>
 /// <param name="interval"></param>
 internal RouteEnumerable(Route route, Meter interval)
 {
     _route         = route;
     _intervalMeter = interval.Value;
 }
Пример #15
0
 /// <summary>
 /// Creates a new OsmSharpRoute enumerable.
 /// </summary>
 /// <param name="route"></param>
 internal RouteEnumerable(Route route)
 {
     _route         = route;
     _intervalMeter = 10;
 }
Пример #16
0
 /// <summary>
 /// Disposes all resource associated with this enumerator.
 /// </summary>
 public void Dispose()
 {
     _route = null;
 }
Пример #17
0
 /// <summary>
 /// Creates a new OsmSharpRoute enumerator.
 /// </summary>
 /// <param name="route"></param>
 /// <param name="intervalMeter"></param>
 public OsmSharpRouteEnumerator(Route route, double intervalMeter)
 {
     _route         = route;
     _currentMeter  = 0;
     _intervalMeter = intervalMeter;
 }
Пример #18
0
        /// <summary>
        /// Concatenates two routes.
        /// </summary>
        /// <param name="route1"></param>
        /// <param name="route2"></param>
        /// <param name="clone"></param>
        /// <returns></returns>
        public static Route Concatenate(Route route1, Route route2, bool clone)
        {
            if (route1 == null)
            {
                return(route2);
            }
            if (route2 == null)
            {
                return(route1);
            }
            if (route1.Segments.Length == 0)
            {
                return(route2);
            }
            if (route2.Segments.Length == 0)
            {
                return(route1);
            }
            if (route1.Vehicle != route2.Vehicle)
            {
                throw new ArgumentException("Route vechicles do not match!");
            }

            // get the end/start point.
            RouteSegment end   = route1.Segments[route1.Segments.Length - 1];
            RouteSegment start = route2.Segments[0];

            // only do all this if the routes are 'concatenable'.
            if (end.Latitude == start.Latitude &&
                end.Longitude == start.Longitude)
            {
                // construct the new route.
                Route route = new Route();

                // concatenate points.
                List <RouteSegment> entries = new List <RouteSegment>();
                // add points for the first route except the last point.
                for (int idx = 0; idx < route1.Segments.Length - 1; idx++)
                {
                    if (clone)
                    {
                        entries.Add(route1.Segments[idx].Clone() as RouteSegment);
                    }
                    else
                    {
                        entries.Add(route1.Segments[idx]);
                    }
                }

                // merge last and first entry.
                RouteSegment mergedEntry =
                    route1.Segments[route1.Segments.Length - 1].Clone() as RouteSegment;
                mergedEntry.Type = RouteSegmentType.Along;
                if (route2.Segments[0].Points != null && route2.Segments[0].Points.Length > 0)
                { // merge in important points from the second route too but do not keep duplicates.
                    var points = new List <RoutePoint>();
                    if (mergedEntry.Points != null)
                    { // keep originals.
                        points.AddRange(mergedEntry.Points);
                    }
                    for (int otherIdx = 0; otherIdx < route2.Segments[0].Points.Length; otherIdx++)
                    { // remove duplicates.
                        bool found = false;
                        for (int idx = 0; idx < points.Count; idx++)
                        {
                            if (points[idx].RepresentsSame(
                                    route2.Segments[0].Points[otherIdx]))
                            { // the points represent the same info!
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        { // the point was not in there yet!
                            points.Add(route2.Segments[0].Points[otherIdx]);
                        }
                    }
                    mergedEntry.Points = points.ToArray();
                }
                entries.Add(mergedEntry);

                // add points of the next route.
                for (int idx = 1; idx < route2.Segments.Length; idx++)
                {
                    if (clone)
                    {
                        entries.Add(route2.Segments[idx].Clone() as RouteSegment);
                    }
                    else
                    {
                        entries.Add(route2.Segments[idx]);
                    }
                }
                route.Segments = entries.ToArray();

                // concatenate tags.
                List <RouteTags> tags = new List <RouteTags>();
                if (route1.Tags != null)
                {
                    tags.AddRange(route1.Tags);
                }
                if (route2.Tags != null)
                {
                    tags.AddRange(route2.Tags);
                }
                route.Tags = tags.ToArray();

                //// calculate metrics.
                //Routing.Core.Metrics.Time.TimeCalculator calculator = new OsmSharp.Routing.Metrics.Time.TimeCalculator();
                //Dictionary<string, double> metrics = calculator.Calculate(route);
                //route.TotalDistance = metrics[Routing.Core.Metrics.Time.TimeCalculator.DISTANCE_KEY];
                //route.TotalTime = metrics[Routing.Core.Metrics.Time.TimeCalculator.TIME_KEY];

                // set the vehicle.
                route.Vehicle = route1.Vehicle;
                return(route);
            }
            else
            {
                throw new ArgumentOutOfRangeException("Contatenation routes can only be done when the end point of the first route equals the start of the second.");
            }
        }
Пример #19
0
 /// <summary>
 /// Calculates instructions for the given route and vehicle.
 /// </summary>
 /// <param name="route"></param>
 /// <returns></returns>
 public abstract List<Instruction> GetInstructions(Route route);
Пример #20
0
        /// <summary>
        /// Builds a dummy route (as the crow flies) for segments of a route not found.
        /// </summary>
        /// <returns></returns>
        public virtual Route BuildDummyRoute(Vehicle vehicle, GeoCoordinate coordinate1, GeoCoordinate coordinate2)
        {
            var route = new Route();
            route.Vehicle = vehicle.UniqueName;

            var segments = new RouteSegment[2];
            segments[0] = new RouteSegment();
            segments[0].Distance = 0;
            segments[0].Time = 0;
            segments[0].Type = RouteSegmentType.Start;
            segments[0].Vehicle = vehicle.UniqueName;
            segments[0].Latitude = (float)coordinate1.Latitude;
            segments[0].Longitude = (float)coordinate1.Longitude;

            var distance = coordinate1.DistanceReal(coordinate2).Value;
            var timeEstimage = distance / (vehicle.MaxSpeed().Value) * 3.6;
            var tags = new TagsCollection();
            tags.Add("route", "not_found");
            segments[1] = new RouteSegment();
            segments[1].Distance = distance;
            segments[1].Time = timeEstimage;
            segments[1].Type = RouteSegmentType.Stop;
            segments[1].Vehicle = vehicle.UniqueName;
            segments[1].Latitude = (float)coordinate2.Latitude;
            segments[1].Longitude = (float)coordinate2.Longitude;
            segments[1].Tags = RouteTagsExtensions.ConvertFrom(tags);

            route.Segments = segments;

            return route;
        }
Пример #21
0
        public void TestSimpleTurn()
        {
            var route = new Route();
            route.Vehicle = Vehicle.Car.UniqueName;
            route.Segments = new RouteSegment[3];
            route.Segments[0] = new RouteSegment()
            {
                Distance = 0,
                Latitude = 50.999f,
                Longitude = 4,
                Points = new RoutePoint[] { 
                    new RoutePoint() 
                    {
                        Latitude = 50.999f,
                        Longitude = 4,
                        Name = "Start"
                    }},
                SideStreets = null,
                Type = RouteSegmentType.Start
            };
            route.Segments[1] = new RouteSegment()
            {
                Distance = 0,
                Latitude = 51,
                Longitude = 4,
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "name", Value = "Street A" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                Type = RouteSegmentType.Along,
                SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch() { 
                        Latitude = 51, 
                        Longitude = 3.999f,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "name", Value = "Street B" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        Name = "Street B"
                    }
                }
            };
            route.Segments[2] = new RouteSegment()
            {
                Distance = 0,
                Latitude = 51,
                Longitude = 4.001f,
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "name", Value = "Street B" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                Type = RouteSegmentType.Stop,
                Points = new RoutePoint[] { 
                    new RoutePoint() 
                    {
                        Latitude = 51,
                        Longitude = 4.001f,
                        Name = "Stop"
                    }},
            };

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // generate instructions.
            List<Instruction> instructions = InstructionGenerator.Generate(route, new OsmRoutingInterpreter(), languageGenerator);
            Assert.AreEqual(3, instructions.Count);
            Assert.AreEqual("GenerateDirectTurn:0_Right_0", instructions[1].Text);
        }
Пример #22
0
 /// <summary>
 /// Adds a new OsmSharpRoute.
 /// </summary>
 /// <param name="route">Route.</param>
 /// <param name="argb">ARGB.</param>
 public void AddRoute(Route route, int argb)
 {
     this.AddRoute (route, argb, 8);
 }
Пример #23
0
        public void RoutePositionAfterRegressionTest1()
        {
            var delta = .00001;

            // a route of approx 30 m along the following coordinates:
            // 50.98624687752063, 2.902620979360633
            // 50.98624687752063, 2.9027639004471673 (10m)
            // 50.986156907620895, 2.9027639004471673  (20m)
            // 50.9861564788317, 2.902620884621392 (30m)

            Route route1 = new Route();
            route1.Vehicle = Vehicle.Car.UniqueName;
            RouteSegment route1entry1 = new RouteSegment();
            route1entry1.Distance = -1;
            route1entry1.Latitude = 50.98624687752063f;
            route1entry1.Longitude = 2.902620979360633f;
            route1entry1.Metrics = null;
            route1entry1.Points = new RoutePoint[1];
            route1entry1.Points[0] = new RoutePoint();
            route1entry1.Points[0].Name = "TestPoint1";
            route1entry1.Points[0].Tags = new RouteTags[1];
            route1entry1.Points[0].Tags[0] = new RouteTags();
            route1entry1.Points[0].Tags[0].Value = "TestValue1";
            route1entry1.Points[0].Tags[0].Key = "TestKey1";
            route1entry1.SideStreets = null;
            route1entry1.Tags = new RouteTags[1];
            route1entry1.Tags[0] = new RouteTags();
            route1entry1.Tags[0].Key = "highway";
            route1entry1.Tags[0].Value = "residential";
            route1entry1.Time = 10;
            route1entry1.Type = RouteSegmentType.Start;
            route1entry1.Name = string.Empty;
            route1entry1.Names = null;

            RouteSegment route1entry2 = new RouteSegment();
            route1entry2.Distance = -1;
            route1entry2.Latitude = 50.98624687752063f;
            route1entry2.Longitude = 2.9027639004471673f;
            route1entry2.Metrics = null;
            route1entry2.Points = new RoutePoint[1];
            route1entry2.Points[0] = new RoutePoint();
            route1entry2.Points[0].Name = "TestPoint2";
            route1entry2.Points[0].Tags = new RouteTags[1];
            route1entry2.Points[0].Tags[0] = new RouteTags();
            route1entry2.Points[0].Tags[0].Value = "TestValue2";
            route1entry1.Points[0].Tags[0].Key = "TestKey2";
            route1entry2.SideStreets = null;
            route1entry2.Tags = new RouteTags[1];
            route1entry2.Tags[0] = new RouteTags();
            route1entry2.Tags[0].Key = "highway";
            route1entry2.Tags[0].Value = "residential";
            route1entry2.Time = 10;
            route1entry2.Type = RouteSegmentType.Start;
            route1entry2.Name = string.Empty;
            route1entry2.Names = null;

            RouteSegment route1entry3 = new RouteSegment();
            route1entry3.Distance = -1;
            route1entry3.Latitude = 50.986156907620895f;
            route1entry3.Longitude = 2.9027639004471673f;
            route1entry3.Metrics = null;
            route1entry3.Points = new RoutePoint[1];
            route1entry3.Points[0] = new RoutePoint();
            route1entry3.Points[0].Name = "TestPoint3";
            route1entry3.Points[0].Tags = new RouteTags[1];
            route1entry3.Points[0].Tags[0] = new RouteTags();
            route1entry3.Points[0].Tags[0].Value = "TestValue3";
            route1entry1.Points[0].Tags[0].Key = "TestKey3";
            route1entry3.SideStreets = null;
            route1entry3.Tags = new RouteTags[1];
            route1entry3.Tags[0] = new RouteTags();
            route1entry3.Tags[0].Key = "highway";
            route1entry3.Tags[0].Value = "residential";
            route1entry3.Time = 10;
            route1entry3.Type = RouteSegmentType.Start;
            route1entry3.Name = string.Empty;
            route1entry3.Names = null;

            RouteSegment route1entry4 = new RouteSegment();
            route1entry4.Distance = -1;
            route1entry4.Latitude = 50.9861564788317f;
            route1entry4.Longitude = 2.902620884621392f;
            route1entry4.Metrics = null;
            route1entry4.Points = new RoutePoint[1];
            route1entry4.Points[0] = new RoutePoint();
            route1entry4.Points[0].Name = "TestPoint4";
            route1entry4.Points[0].Tags = new RouteTags[1];
            route1entry4.Points[0].Tags[0] = new RouteTags();
            route1entry4.Points[0].Tags[0].Value = "TestValue4";
            route1entry1.Points[0].Tags[0].Key = "TestKey4";
            route1entry4.SideStreets = null;
            route1entry4.Tags = new RouteTags[1];
            route1entry4.Tags[0] = new RouteTags();
            route1entry4.Tags[0].Key = "highway";
            route1entry4.Tags[0].Value = "residential";
            route1entry4.Time = 10;
            route1entry4.Type = RouteSegmentType.Start;
            route1entry4.Name = string.Empty;
            route1entry4.Names = null;

            route1.Segments = new RouteSegment[4];
            route1.Segments[0] = route1entry1;
            route1.Segments[1] = route1entry2;
            route1.Segments[2] = route1entry3;
            route1.Segments[3] = route1entry4;

            // first test position after.
            var positionAfter = route1.PositionAfter(5);
            Assert.IsNotNull(positionAfter);
            Assert.AreEqual(5.0, positionAfter.DistanceReal(new GeoCoordinate(route1.Segments[0].Latitude, route1.Segments[0].Longitude)).Value, .0001);
            positionAfter = route1.PositionAfter(15);
            Assert.IsNotNull(positionAfter);
            Assert.AreEqual(15.0,
                new GeoCoordinate(route1.Segments[0].Latitude, route1.Segments[0].Longitude).DistanceReal(new GeoCoordinate(route1.Segments[1].Latitude, route1.Segments[1].Longitude)).Value +
                positionAfter.DistanceReal(new GeoCoordinate(route1.Segments[1].Latitude, route1.Segments[1].Longitude)).Value, .0001);
            positionAfter = route1.PositionAfter(25);
            Assert.IsNotNull(positionAfter);
            Assert.AreEqual(25.0,
                new GeoCoordinate(route1.Segments[0].Latitude, route1.Segments[0].Longitude).DistanceReal(new GeoCoordinate(route1.Segments[1].Latitude, route1.Segments[1].Longitude)).Value +
                new GeoCoordinate(route1.Segments[1].Latitude, route1.Segments[1].Longitude).DistanceReal(new GeoCoordinate(route1.Segments[2].Latitude, route1.Segments[2].Longitude)).Value +
                positionAfter.DistanceReal(new GeoCoordinate(route1.Segments[2].Latitude, route1.Segments[2].Longitude)).Value, .0001);

            // use position after to test project on.
            int entryIdx;
            GeoCoordinate projected;
            Meter distanceFromStart;
            Second timeFromStart;

            var distance = 5.0;
            var location = route1.PositionAfter(distance);
            Assert.IsTrue(route1.ProjectOn(location, out projected, out entryIdx, out distanceFromStart, out timeFromStart));
            Assert.AreEqual(distance, distanceFromStart.Value, delta);
            Assert.AreEqual(location.Latitude, projected.Latitude, delta);
            Assert.AreEqual(location.Longitude, projected.Longitude, delta);
            Assert.AreEqual(0, entryIdx);

            location = route1.PositionAfter(distanceFromStart);
            Assert.AreEqual(location.Latitude, projected.Latitude, delta);
            Assert.AreEqual(location.Longitude, projected.Longitude, delta);

            distance = 15.0;
            location = route1.PositionAfter(distance);
            Assert.IsTrue(route1.ProjectOn(location, out projected, out entryIdx, out distanceFromStart, out timeFromStart));
            Assert.AreEqual(distance, distanceFromStart.Value, delta);
            Assert.AreEqual(location.Latitude, projected.Latitude, delta);
            Assert.AreEqual(location.Longitude, projected.Longitude, delta);
            Assert.AreEqual(1, entryIdx);

            location = route1.PositionAfter(distanceFromStart);
            Assert.AreEqual(location.Latitude, projected.Latitude, delta);
            Assert.AreEqual(location.Longitude, projected.Longitude, delta);

            distance = 25;
            location = route1.PositionAfter(distance);
            Assert.IsTrue(route1.ProjectOn(location, out projected, out entryIdx, out distanceFromStart, out timeFromStart));
            Assert.AreEqual(distance, distanceFromStart.Value, delta);
            Assert.AreEqual(location.Latitude, projected.Latitude, delta);
            Assert.AreEqual(location.Longitude, projected.Longitude, delta);
            Assert.AreEqual(2, entryIdx);

            location = route1.PositionAfter(distanceFromStart);
            Assert.AreEqual(location.Latitude, projected.Latitude, delta);
            Assert.AreEqual(location.Longitude, projected.Longitude, delta);
        }
Пример #24
0
        /// <summary>
        /// Adds a new OsmSharpRoute.
        /// </summary>
        /// <param name="route">Stream.</param>
        /// <param name="argb">Stream.</param>
        public void AddRoute(Route route, int argb, double width)
        {
            if (route != null &&
                route.Entries != null &&
                route.Entries.Length > 0)
            { // there are entries.
                // get x/y.
                var x = new double[route.Entries.Length];
                var y = new double[route.Entries.Length];
                for (int idx = 0; idx < route.Entries.Length; idx++)
                {
                    x[idx] = _projection.LongitudeToX(
                        route.Entries[idx].Longitude);
                    y[idx] = _projection.LatitudeToY(
                        route.Entries[idx].Latitude);
                }

                // set the default color if none is given.
                SimpleColor color = SimpleColor.FromArgb (argb);
                this.Scene.AddLine(float.MinValue, float.MaxValue, x, y,
                                   color.Value, width);
            }
        }
Пример #25
0
        public void RouteToGeoJson()
        {
            // build a test route.
            var route = new Route();
            route.Vehicle = Vehicle.Car.UniqueName;
            var route1entry1 = new RouteSegment();
            route1entry1.Distance = 0;
            route1entry1.Latitude = 1;
            route1entry1.Longitude = 1;
            route1entry1.Metrics = null;
            route1entry1.Points = new RoutePoint[1];
            route1entry1.Points[0] = new RoutePoint();
            route1entry1.Points[0].Name = "TestPoint1";
            route1entry1.Points[0].Tags = new RouteTags[1];
            route1entry1.Points[0].Tags[0] = new RouteTags();
            route1entry1.Points[0].Tags[0].Value = "TestValue1";
            route1entry1.Points[0].Tags[0].Key = "TestKey1";
            route1entry1.SideStreets = null;
            route1entry1.Tags = new RouteTags[1];
            route1entry1.Tags[0] = new RouteTags();
            route1entry1.Tags[0].Key = "highway";
            route1entry1.Tags[0].Value = "residential";
            route1entry1.Time = 0;
            route1entry1.Type = RouteSegmentType.Start;
            route1entry1.Name = string.Empty;
            route1entry1.Names = null;

            var route1entry2 = new RouteSegment();
            route1entry2.Distance = 10;
            route1entry2.Latitude = 2;
            route1entry2.Longitude = 2;
            route1entry2.Metrics = null;
            route1entry2.Points = new RoutePoint[1];
            route1entry2.Points[0] = new RoutePoint();
            route1entry2.Points[0].Name = "TestPoint2";
            route1entry2.Points[0].Tags = new RouteTags[1];
            route1entry2.Points[0].Tags[0] = new RouteTags();
            route1entry2.Points[0].Tags[0].Value = "TestValue2";
            route1entry2.Points[0].Tags[0].Key = "TestKey2";
            route1entry2.SideStreets = null;
            route1entry2.Tags = new RouteTags[1];
            route1entry2.Tags[0] = new RouteTags();
            route1entry2.Tags[0].Key = "highway";
            route1entry2.Tags[0].Value = "residential";
            route1entry2.Time = 20;
            route1entry2.Type = RouteSegmentType.Start;
            route1entry2.Name = string.Empty;
            route1entry2.Names = null;

            route.Segments = new RouteSegment[2];
            route.Segments[0] = route1entry1;
            route.Segments[1] = route1entry2;

            // execute the conversion.
            var geojson = route.ToGeoJson();
            geojson = geojson.RemoveWhitespace();

            Assert.AreEqual("{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{\"TestKey1\":\"TestValue1\"},\"geometry\":{\"type\":\"Point\",\"coordinates\":[0.0,0.0]}},{\"type\":\"Feature\",\"properties\":{\"highway\":\"residential\",\"time\":20.0,\"distance\":10.0},\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[1.0,1.0],[2.0,2.0]]}},{\"type\":\"Feature\",\"properties\":{\"TestKey2\":\"TestValue2\"},\"geometry\":{\"type\":\"Point\",\"coordinates\":[0.0,0.0]}}]}",
                geojson);
        }
Пример #26
0
        public void TestRoundabout()
        {
            GeoCoordinate westWest = new GeoCoordinate(51, 3.998);
            GeoCoordinate west = new GeoCoordinate(51, 3.999);
            GeoCoordinate eastEast = new GeoCoordinate(51, 4.002);
            GeoCoordinate east = new GeoCoordinate(51, 4.001);
            GeoCoordinate north = new GeoCoordinate(51.001, 4);
            GeoCoordinate northNorth = new GeoCoordinate(51.002, 4);
            GeoCoordinate south = new GeoCoordinate(50.999, 4);
            GeoCoordinate southSouth = new GeoCoordinate(50.998, 4);
            GeoCoordinate center = new GeoCoordinate(51, 4);

            Route route = new Route();
            route.Vehicle = Vehicle.Car;
            route.Entries = new RoutePointEntry[5];
            route.Entries[0] = new RoutePointEntry()
            {
                Distance = 0,
                Latitude = (float)southSouth.Latitude,
                Longitude = (float)southSouth.Longitude,
                Points = new RoutePoint[] {
                    new RoutePoint()
                    {
                        Latitude = (float)southSouth.Latitude,
                        Longitude = (float)southSouth.Longitude,
                        Name = "Start"
                    }},
                SideStreets = null,
                Type = RoutePointEntryType.Start
            };
            route.Entries[1] = new RoutePointEntry()
            {
                Distance = 0,
                Latitude = (float)south.Latitude,
                Longitude = (float)south.Longitude,
                Type = RoutePointEntryType.Along,
                WayFromName = "SouthStreet",
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "name", Value = "SouthStreet" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                SideStreets = new RoutePointEntrySideStreet[] {
                    new RoutePointEntrySideStreet() {
                        Latitude = (float)west.Latitude,
                        Longitude = (float)west.Longitude,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "junction", Value = "roundabout" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        WayName = "Street B"
                    },
                    new RoutePointEntrySideStreet() {
                        Latitude = (float)east.Latitude,
                        Longitude = (float)east.Longitude,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "junction", Value = "roundabout" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        WayName = "Street B"
                    }
                }
            };
            route.Entries[2] = new RoutePointEntry()
            {
                Distance = 0,
                Latitude = (float)east.Latitude,
                Longitude = (float)east.Longitude,
                Type = RoutePointEntryType.Along,
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "junction", Value = "roundabout" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                SideStreets = new RoutePointEntrySideStreet[] {
                    new RoutePointEntrySideStreet() {
                        Latitude = (float)eastEast.Latitude,
                        Longitude = (float)eastEast.Longitude,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "name", Value = "EastStreet" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        WayName = "EastStreet"
                    }
                }
            };
            route.Entries[3] = new RoutePointEntry()
            {
                Distance = 0,
                Latitude = (float)north.Latitude,
                Longitude = (float)north.Longitude,
                Type = RoutePointEntryType.Along,
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "junction", Value = "roundabout" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                SideStreets = new RoutePointEntrySideStreet[] {
                    new RoutePointEntrySideStreet() {
                        Latitude = (float)west.Latitude,
                        Longitude = (float)west.Longitude,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "junction", Value = "roundabout" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        }
                    }
                }
            };
            route.Entries[4] = new RoutePointEntry()
            {
                Distance = 0,
                Latitude = (float)northNorth.Latitude,
                Longitude = (float)northNorth.Longitude,
                Type = RoutePointEntryType.Stop,
                Tags = new RouteTags[] {
                    new RouteTags() { Key = "name", Value = "NorthStreet" },
                    new RouteTags() { Key = "highway", Value = "residential" }
                },
                Points = new RoutePoint[] {
                    new RoutePoint()
                    {
                        Latitude = (float)north.Latitude,
                        Longitude = (float)north.Longitude,
                        Name = "Stop"
                    }}
            };

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // generate instructions.
            List<Instruction> instructions = InstructionGenerator.Generate(route, new OsmRoutingInterpreter(), languageGenerator);
            Assert.AreEqual(3, instructions.Count);
            Assert.AreEqual("GenerateRoundabout:1", instructions[1].Text);
        }
Пример #27
0
        public void RouteConcatenateTagsIdenticalTest()
        {
            Route route1 = new Route();
            RoutePointEntry route1entry1 = new RoutePointEntry();
            route1entry1.Distance = 10;
            route1entry1.Latitude = -1;
            route1entry1.Longitude = -1;
            route1entry1.Metrics = null;
            route1entry1.Points = new RoutePoint[1];
            route1entry1.Points[0] = new RoutePoint();
            route1entry1.Points[0].Name = "TestPoint1";
            route1entry1.Points[0].Tags = new RouteTags[1];
            route1entry1.Points[0].Tags[0] = new RouteTags();
            route1entry1.Points[0].Tags[0].Value = "TestValue1";
            route1entry1.Points[0].Tags[0].Key = "TestKey1";
            route1entry1.SideStreets = null;
            route1entry1.Tags = new RouteTags[1];
            route1entry1.Tags[0] = new RouteTags();
            route1entry1.Tags[0].Key = "highway";
            route1entry1.Tags[0].Value = "residential";
            route1entry1.Time = 10;
            route1entry1.Type = RoutePointEntryType.Start;
            route1entry1.WayFromName = string.Empty;
            route1entry1.WayFromNames = null;

            RoutePointEntry route1entry2 = new RoutePointEntry();
            route1entry2.Distance = 10;
            route1entry2.Latitude = -1;
            route1entry2.Longitude = -1;
            route1entry2.Metrics = null;
            route1entry2.Points = new RoutePoint[1];
            route1entry2.Points[0] = new RoutePoint();
            route1entry2.Points[0].Name = "TestPoint2";
            route1entry2.Points[0].Tags = new RouteTags[1];
            route1entry2.Points[0].Tags[0] = new RouteTags();
            route1entry2.Points[0].Tags[0].Value = "TestValue2";
            route1entry2.Points[0].Tags[0].Key = "TestKey2";
            route1entry2.SideStreets = null;
            route1entry2.Tags = new RouteTags[1];
            route1entry2.Tags[0] = new RouteTags();
            route1entry2.Tags[0].Key = "highway";
            route1entry2.Tags[0].Value = "residential";
            route1entry2.Time = 10;
            route1entry2.Type = RoutePointEntryType.Start;
            route1entry2.WayFromName = string.Empty;
            route1entry2.WayFromNames = null;

            route1.Entries = new RoutePointEntry[2];
            route1.Entries[0] = route1entry1;
            route1.Entries[1] = route1entry2;

            Route route2 = new Route();
            RoutePointEntry route2entry1 = new RoutePointEntry();
            route2entry1.Distance = 10;
            route2entry1.Latitude = -1;
            route2entry1.Longitude = -1;
            route2entry1.Metrics = null;
            route2entry1.Points = new RoutePoint[1];
            route2entry1.Points[0] = new RoutePoint();
            route2entry1.Points[0].Name = "TestPoint2";
            route2entry1.Points[0].Tags = new RouteTags[1];
            route2entry1.Points[0].Tags[0] = new RouteTags();
            route2entry1.Points[0].Tags[0].Value = "TestValue2";
            route2entry1.Points[0].Tags[0].Key = "TestKey2";
            route2entry1.SideStreets = null;
            route2entry1.Tags = new RouteTags[1];
            route2entry1.Tags[0] = new RouteTags();
            route2entry1.Tags[0].Key = "highway";
            route2entry1.Tags[0].Value = "residential";
            route2entry1.Time = 10;
            route2entry1.Type = RoutePointEntryType.Start;
            route2entry1.WayFromName = string.Empty;
            route2entry1.WayFromNames = null;

            RoutePointEntry route2entry2 = new RoutePointEntry();
            route2entry2.Distance = 10;
            route2entry2.Latitude = -1;
            route2entry2.Longitude = -1;
            route2entry2.Metrics = null;
            route2entry2.Points = new RoutePoint[1];
            route2entry2.Points[0] = new RoutePoint();
            route2entry2.Points[0].Name = "TestPoint4";
            route2entry2.Points[0].Tags = new RouteTags[1];
            route2entry2.Points[0].Tags[0] = new RouteTags();
            route2entry2.Points[0].Tags[0].Value = "TestValue4";
            route2entry2.Points[0].Tags[0].Key = "TestKey4";
            route2entry2.SideStreets = null;
            route2entry2.Tags = new RouteTags[1];
            route2entry2.Tags[0] = new RouteTags();
            route2entry2.Tags[0].Key = "highway";
            route2entry2.Tags[0].Value = "residential";
            route2entry2.Time = 10;
            route2entry2.Type = RoutePointEntryType.Start;
            route2entry2.WayFromName = string.Empty;
            route2entry2.WayFromNames = null;

            route2.Entries = new RoutePointEntry[2];
            route2.Entries[0] = route2entry1;
            route2.Entries[1] = route2entry2;

            Route concatenated = Route.Concatenate(route1, route2);

            // test the result.
            Assert.IsNotNull(concatenated);
            Assert.IsNotNull(concatenated.Entries);
            Assert.AreEqual(3, concatenated.Entries.Length);
            Assert.AreEqual("TestPoint1", concatenated.Entries[0].Points[0].Name);
            Assert.AreEqual("TestPoint2", concatenated.Entries[1].Points[0].Name);
            Assert.AreEqual(1, concatenated.Entries[1].Points.Length);
            Assert.AreEqual("TestPoint4", concatenated.Entries[2].Points[0].Name);
        }
Пример #28
0
 /// <summary>
 /// Calculates metrics for the given route.
 /// </summary>
 /// <param name="route"></param>
 /// <returns></returns>
 public Dictionary<string, double> Calculate(Route route)
 {
     var aggregator =  new OsmSharp.Routing.ArcAggregation.ArcAggregator(_interpreter);
     var p = aggregator.Aggregate(route);
     return this.Calculate(Vehicle.GetByUniqueName(route.Vehicle), p);
 }
 /// <summary>
 /// Compares the two given routes.
 /// </summary>
 /// <param name="reference"></param>
 /// <param name="route"></param>
 protected void CompareRoutes(Route reference, Route route)
 {
     if (reference.Segments == null)
     {
         Assert.IsNull(route.Segments);
     }
     else
     {
         Assert.AreEqual(reference.Segments.Length, route.Segments.Length);
         for (int idx = 0; idx < reference.Segments.Length; idx++)
         {
             Assert.AreEqual(reference.Segments[idx].Distance,
                 route.Segments[idx].Distance);
             Assert.AreEqual(reference.Segments[idx].Latitude,
                 route.Segments[idx].Latitude);
             Assert.AreEqual(reference.Segments[idx].Longitude,
                 route.Segments[idx].Longitude);
             Assert.AreEqual(reference.Segments[idx].Time,
                 route.Segments[idx].Time);
             Assert.AreEqual(reference.Segments[idx].Type,
                 route.Segments[idx].Type);
             Assert.AreEqual(reference.Segments[idx].Name,
                 route.Segments[idx].Name);
         }
     }
 }
        public void RoutingRegressionTest2()
        {
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            SimpleTagsIndex tags_index = new SimpleTagsIndex();

            // do the data processing.
            DynamicGraphRouterDataSource<LiveEdge> memory_data =
                new DynamicGraphRouterDataSource<LiveEdge>(tags_index);
            LiveGraphOsmStreamTarget target_data = new LiveGraphOsmStreamTarget(
                memory_data, interpreter, memory_data.TagsIndex);
            XmlOsmStreamSource data_processor_source = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_network.osm"));
            OsmStreamFilterSort sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(data_processor_source);
            target_data.RegisterSource(sorter);
            target_data.Pull();

            IBasicRouter<LiveEdge> basic_router = new DykstraRoutingLive(memory_data.TagsIndex);
            Router router = Router.CreateLiveFrom(memory_data, basic_router, interpreter);

            // build coordinates list of resolved points.
            List<GeoCoordinate> testPoints = new List<GeoCoordinate>();
            testPoints.Add(new GeoCoordinate(51.0582204, 3.7193524));
            testPoints.Add(new GeoCoordinate(51.0582199, 3.7194002));
            //testPoints.Add(new GeoCoordinate(51.0582178, 3.7195025));

            testPoints.Add(new GeoCoordinate(51.0581727, 3.7195833));
            testPoints.Add(new GeoCoordinate(51.0581483, 3.7195553));
            //testPoints.Add(new GeoCoordinate(51.0581219, 3.7195231));
            //testPoints.Add(new GeoCoordinate(51.0580965, 3.7194918));

            testPoints.Add(new GeoCoordinate(51.0581883, 3.7196617));
            testPoints.Add(new GeoCoordinate(51.0581628, 3.7196889));

            // build a matrix of routes between all points.
            Route[][] referenceRoutes = new Route[testPoints.Count][];
            int[] permuationArray = new int[testPoints.Count];
            for (int fromIdx = 0; fromIdx < testPoints.Count; fromIdx++)
            {
                permuationArray[fromIdx] = fromIdx;
                referenceRoutes[fromIdx] = new Route[testPoints.Count];
                for (int toIdx = 0; toIdx < testPoints.Count; toIdx++)
                {
                    // create router from scratch.
                    router = Router.CreateLiveFrom(
                        memory_data, basic_router, interpreter);

                    // resolve points.
                    RouterPoint from = router.Resolve(Vehicle.Car, testPoints[fromIdx]);
                    RouterPoint to = router.Resolve(Vehicle.Car, testPoints[toIdx]);

                    // calculate route.
                    referenceRoutes[fromIdx][toIdx] = router.Calculate(Vehicle.Car, from, to);
                }
            }

            // resolve points in some order and compare the resulting routes.
            // they should be identical in length except for some numerical rounding errors.
            PermutationEnumerable<int> enumerator = new PermutationEnumerable<int>(
                permuationArray);
            foreach (int[] permutation in enumerator)
            {
                //int[] permutation = new int[] { 5, 0, 1, 2, 4, 3, 6, 7, 8 };

                //// incrementally resolve points.
                //// create router from scratch.
                //router = new Router<SimpleWeighedEdge>(memory_data, interpreter, basic_router);

                //// resolve in the order of the permutation.
                //RouterPoint[] resolvedPoints = new RouterPoint[permutation.Length];
                //resolvedPoints[permutation[0]] = router.Resolve(VehicleEnum.Car, testPoints[permutation[0]]);
                //for (int idx = 1; idx < permutation.Length; idx++)
                //{
                //    resolvedPoints[permutation[idx]] = router.Resolve(VehicleEnum.Car, testPoints[permutation[idx]]);

                //    for (int fromIdx = 0; fromIdx <= idx; fromIdx++)
                //    {
                //        for (int toIdx = 0; toIdx <= idx; toIdx++)
                //        {
                //            // calculate route.
                //            OsmSharpRoute route = router.Calculate(VehicleEnum.Car,
                //                resolvedPoints[permutation[fromIdx]], resolvedPoints[permutation[toIdx]]);

                //            Assert.AreEqual(referenceRoutes[permutation[fromIdx]][permutation[toIdx]].TotalDistance,
                //                route.TotalDistance, 0.1);
                //        }
                //    }
                //}

                // create router from scratch.
                router = Router.CreateLiveFrom(memory_data, basic_router, interpreter);

                // resolve in the order of the permutation.
                RouterPoint[] resolvedPoints = new RouterPoint[permutation.Length];
                for (int idx = 0; idx < permutation.Length; idx++)
                {
                    resolvedPoints[permutation[idx]] = router.Resolve(Vehicle.Car, testPoints[permutation[idx]]);
                }

                for (int fromIdx = 0; fromIdx < testPoints.Count; fromIdx++)
                {
                    for (int toIdx = 0; toIdx < testPoints.Count; toIdx++)
                    {
                        // calculate route.
                        Route route = router.Calculate(Vehicle.Car, resolvedPoints[fromIdx], resolvedPoints[toIdx]);

                        Assert.AreEqual(referenceRoutes[fromIdx][toIdx].TotalDistance, route.TotalDistance, 0.1);
                    }
                }
            }
        }
Пример #31
0
        public void RoutingRegressionTest2()
        {
            var interpreter = new OsmRoutingInterpreter();
            var tagsIndex = new TagsIndex();

            // do the data processing.
            var memoryData = new RouterDataSource<Edge>(new Graph<Edge>(), tagsIndex);
            var targetData = new GraphOsmStreamTarget(memoryData, interpreter, tagsIndex);
            var dataProcessorSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Routing.Test.data.test_network.osm"));
            var sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            var basicRouter = new Dykstra();
            var router = Router.CreateFrom(memoryData, basicRouter, interpreter);

            // build coordinates list of resolved points.
            var testPoints = new List<GeoCoordinate>();
            testPoints.Add(new GeoCoordinate(51.0582204, 3.7193524));
            testPoints.Add(new GeoCoordinate(51.0582199, 3.7194002));

            testPoints.Add(new GeoCoordinate(51.0581727, 3.7195833));
            testPoints.Add(new GeoCoordinate(51.0581483, 3.7195553));

            testPoints.Add(new GeoCoordinate(51.0581883, 3.7196617));
            testPoints.Add(new GeoCoordinate(51.0581628, 3.7196889));

            // build a matrix of routes between all points.
            var referenceRoutes = new Route[testPoints.Count][];
            var permuationArray = new int[testPoints.Count];
            for (int fromIdx = 0; fromIdx < testPoints.Count; fromIdx++)
            {
                permuationArray[fromIdx] = fromIdx;
                referenceRoutes[fromIdx] = new Route[testPoints.Count];
                for (int toIdx = 0; toIdx < testPoints.Count; toIdx++)
                {
                    // create router from scratch.
                    router = Router.CreateFrom(
                        memoryData, basicRouter, interpreter);

                    // resolve points.
                    var from = router.Resolve(Vehicle.Car, testPoints[fromIdx]);
                    var to = router.Resolve(Vehicle.Car, testPoints[toIdx]);

                    // calculate route.
                    referenceRoutes[fromIdx][toIdx] = router.Calculate(Vehicle.Car, from, to);
                }
            }

            // resolve points in some order and compare the resulting routes.
            // they should be identical in length except for some numerical rounding errors.
            var enumerator = new PermutationEnumerable<int>(permuationArray);
            foreach (int[] permutation in enumerator)
            {
                // create router from scratch.
                router = Router.CreateFrom(memoryData, basicRouter, interpreter);

                // resolve in the order of the permutation.
                var resolvedPoints = new RouterPoint[permutation.Length];
                for (int idx = 0; idx < permutation.Length; idx++)
                {
                    resolvedPoints[permutation[idx]] = router.Resolve(Vehicle.Car, testPoints[permutation[idx]]);
                }

                for (int fromIdx = 0; fromIdx < testPoints.Count; fromIdx++)
                {
                    for (int toIdx = 0; toIdx < testPoints.Count; toIdx++)
                    {
                        // calculate route.
                        var route = router.Calculate(Vehicle.Car, resolvedPoints[fromIdx], resolvedPoints[toIdx]);

                        // TODO: changed the resolve accuracy to .5m. Make sure this is more accurate in the future.
                        Assert.AreEqual(referenceRoutes[fromIdx][toIdx].TotalDistance, route.TotalDistance, 1);
                    }
                }
            }
        }
Пример #32
0
        public void RoutingRegressionTest3()
        {
            var interpreter = new OsmRoutingInterpreter();
            var tagsIndex = new TagsTableCollectionIndex();

            // do the data processing.
            var memoryData = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            var targetData = new LiveGraphOsmStreamTarget(memoryData, interpreter, tagsIndex);
            var dataProcessorSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_network.osm"));
            var sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            var basicRouter = new Dykstra();
            var router = Router.CreateLiveFrom(memoryData, basicRouter, interpreter);

            // build coordinates list of resolved points.
            var testPoints = new List<GeoCoordinate>();
            testPoints.Add(new GeoCoordinate(51.0581719, 3.7201622));
            testPoints.Add(new GeoCoordinate(51.0580439, 3.7202134));
            testPoints.Add(new GeoCoordinate(51.0580573, 3.7204378));
            testPoints.Add(new GeoCoordinate(51.0581862, 3.7203758));

            // build a matrix of routes between all points.
            var referenceRoutes = new Route[testPoints.Count][];
            var permuationArray = new int[testPoints.Count];
            for (int fromIdx = 0; fromIdx < testPoints.Count; fromIdx++)
            {
                permuationArray[fromIdx] = fromIdx;
                referenceRoutes[fromIdx] = new Route[testPoints.Count];
                for (int toIdx = 0; toIdx < testPoints.Count; toIdx++)
                {
                    // create router from scratch.
                    router = Router.CreateLiveFrom(
                        memoryData, basicRouter, interpreter);

                    // resolve points.
                    var from = router.Resolve(Vehicle.Car, testPoints[fromIdx]);
                    var to = router.Resolve(Vehicle.Car, testPoints[toIdx]);

                    // calculate route.
                    referenceRoutes[fromIdx][toIdx] = router.Calculate(Vehicle.Car, from, to);
                }
            }

            // resolve points in some order and compare the resulting routes.
            // they should be identical in length except for some numerical rounding errors.
            var enumerator = new PermutationEnumerable<int>(
                permuationArray);
            foreach (int[] permutation in enumerator)
            {
                // create router from scratch.
                router = Router.CreateLiveFrom(memoryData, basicRouter, interpreter);

                // resolve in the order of the permutation.
                var resolvedPoints = new RouterPoint[permutation.Length];
                for (int idx = 0; idx < permutation.Length; idx++)
                {
                    resolvedPoints[permutation[idx]] = router.Resolve(Vehicle.Car, testPoints[permutation[idx]]);
                }

                for (int fromIdx = 0; fromIdx < testPoints.Count; fromIdx++)
                {
                    for (int toIdx = 0; toIdx < testPoints.Count; toIdx++)
                    {
                        // calculate route.
                        var route = router.Calculate(Vehicle.Car, resolvedPoints[fromIdx], resolvedPoints[toIdx]);

                        Assert.AreEqual(referenceRoutes[fromIdx][toIdx].TotalDistance, route.TotalDistance, 0.1);
                    }
                }
            }
        }
Пример #33
0
        /// <summary>
        /// Concatenates two routes.
        /// </summary>
        /// <param name="route1"></param>
        /// <param name="route2"></param>
        /// <param name="clone"></param>
        /// <returns></returns>
        public static Route Concatenate(Route route1, Route route2, bool clone)
        {
            if (route1 == null) return route2;
            if (route2 == null) return route1;
            if (route1.Segments.Length == 0) return route2;
            if (route2.Segments.Length == 0) return route1;
            var vehicle = route1.Vehicle;
            if (route1.Vehicle != route2.Vehicle)
            { // vehicles are different, is possible, vehicles also set in each segment.
                vehicle = null;
            }

            // get the end/start point.
            var end = route1.Segments[route1.Segments.Length - 1];
            var endTime = end.Time;
            var endDistance = end.Distance;
            var start = route2.Segments[0];

            // only do all this if the routes are 'concatenable'.
            if (end.Latitude == start.Latitude &&
                end.Longitude == start.Longitude)
            {
                // construct the new route.
                var route = new Route();

                // concatenate points.
                var entries = new List<RouteSegment>();
                for (var idx = 0; idx < route1.Segments.Length - 1; idx++)
                {
                    if (clone)
                    {
                        entries.Add(route1.Segments[idx].Clone() as RouteSegment);
                    }
                    else
                    {
                        entries.Add(route1.Segments[idx]);
                    }
                }

                // merge last and first entry.
                var mergedEntry = route1.Segments[route1.Segments.Length - 1].Clone() as RouteSegment;
                mergedEntry.Type = RouteSegmentType.Along;
                if (route2.Segments[0].Points != null && route2.Segments[0].Points.Length > 0)
                { // merge in important points from the second route too but do not keep duplicates.
                    var points = new List<RoutePoint>();
                    if (mergedEntry.Points != null)
                    { // keep originals.
                        points.AddRange(mergedEntry.Points);
                    }
                    for (int otherIdx = 0; otherIdx < route2.Segments[0].Points.Length; otherIdx++)
                    { // remove duplicates.
                        bool found = false;
                        for (int idx = 0; idx < points.Count; idx++)
                        {
                            if (points[idx].RepresentsSame(
                                route2.Segments[0].Points[otherIdx]))
                            { // the points represent the same info!
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        { // the point was not in there yet!
                            points.Add(route2.Segments[0].Points[otherIdx]);
                        }
                    }
                    mergedEntry.Points = points.ToArray();
                }
                entries.Add(mergedEntry);

                // add points of the next route.
                for (var idx = 1; idx < route2.Segments.Length; idx++)
                {
                    if (clone)
                    {
                        entries.Add(route2.Segments[idx].Clone() as RouteSegment);
                    }
                    else
                    {
                        entries.Add(route2.Segments[idx]);
                    }
                    entries[entries.Count - 1].Distance = entries[entries.Count - 1].Distance + endDistance;
                    entries[entries.Count - 1].Time = entries[entries.Count - 1].Time + endTime;
                }
                route.Segments = entries.ToArray();

                // concatenate tags.
                var tags = new List<RouteTags>();
                if (route1.Tags != null) { tags.AddRange(route1.Tags); }
                if (route2.Tags != null) { tags.AddRange(route2.Tags); }
                route.Tags = tags.ToArray();

                // set the vehicle.
                route.Vehicle = vehicle;
                return route;
            }
            else
            {
                throw new ArgumentOutOfRangeException("Contatenation routes can only be done when the end point of the first route equals the start of the second.");
            }
        }
Пример #34
0
 /// <summary>
 /// Concatenates two routes.
 /// </summary>
 /// <param name="route1"></param>
 /// <param name="route2"></param>
 /// <returns></returns>
 public static Route Concatenate(Route route1, Route route2)
 {
     return(Route.Concatenate(route1, route2, true));
 }
Пример #35
0
 /// <summary>
 /// Adds a new route layer with the given route loaded.
 /// </summary>
 /// <param name="route"></param>
 /// <returns></returns>
 public LayerRoute AddLayerRoute(Route route)
 {
     var layerRoute = new LayerRoute(this.Projection);
     layerRoute.AddRoute(route);
     this.AddLayer(layerRoute);
     return layerRoute;
 }
Пример #36
0
 /// <summary>
 /// Converts the given route to a feature collection.
 /// </summary>
 public abstract FeatureCollection GetFeatures(Route route, RouteAggregationType aggregationType);