Beispiel #1
0
 void mapControl1_MapMouseClick(MapControlEventArgs e)
 {
     if (_router != null)
     {
         if (_point1 == null)
         {
             _point1 = _router.Resolve(Vehicle.Car, e.Position);
         }
         else if (_point2 == null)
         {
             _point2 = _router.Resolve(Vehicle.Car, e.Position);
         }
         else
         {
             _point1 = _point2;
             _point2 = _router.Resolve(Vehicle.Car, e.Position);
         }
         if (_point1 != null && _point2 != null)
         {
             OsmSharpRoute route = _router.Calculate(Vehicle.Car,
                                                     _point1, _point2);
             if (route != null)
             {
                 _routeLayer.Clear();
                 _routeLayer.AddRoute(route);
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Tests that a router preserves tags that are located on ways/arcs in the route.
        /// </summary>
        protected void DoTestArcTags()
        {
            var interpreter = new OsmRoutingInterpreter();
            IBasicRouterDataSource <TEdgeData> data        = this.BuildData(interpreter, "OsmSharp.UnitTests.test_network.osm");
            IBasicRouter <TEdgeData>           basicRouter = this.BuildBasicRouter(data);
            Router router = this.BuildRouter(
                data, interpreter, basicRouter);
            RouterPoint source = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0578532, 3.7192229));

            source.Tags.Add(new KeyValuePair <string, string>("name", "source"));
            RouterPoint target = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0576193, 3.7191801));

            target.Tags.Add(new KeyValuePair <string, string>("name", "target"));

            OsmSharpRoute route = router.Calculate(Vehicle.Car, source, target);

            Assert.IsNotNull(route);
            Assert.AreEqual(5, route.Entries.Length);

            Assert.AreEqual("highway", route.Entries[1].Tags[0].Key);
            Assert.AreEqual("residential", route.Entries[1].Tags[0].Value);

            Assert.AreEqual("highway", route.Entries[2].Tags[0].Key);
            Assert.AreEqual("residential", route.Entries[2].Tags[0].Value);

            Assert.AreEqual("highway", route.Entries[3].Tags[0].Key);
            Assert.AreEqual("residential", route.Entries[3].Tags[0].Value);
        }
Beispiel #3
0
        public AggregatedPointEnumerator(OsmSharpRoute route)
        {
            _idx = -1;

            _route   = route;
            _current = null;
        }
Beispiel #4
0
        /// <summary>
        /// Test if routes between resolved nodes are correctly calculated.
        ///
        /// 20--x---x--21---------16
        /// </summary>
        protected void DoTestResolveCase2()
        {
            // initialize data.
            var interpreter = new OsmRoutingInterpreter();
            IBasicRouterDataSource <TEdgeData> data = this.BuildData(interpreter, "OsmSharp.UnitTests.test_network.osm");

            var vertex20 = new GeoCoordinate(51.0578532, 3.7192229);
            var vertex21 = new GeoCoordinate(51.0578518, 3.7195654);
            var vertex16 = new GeoCoordinate(51.0577299, 3.719745);

            PointF2D point       = vertex20 + ((vertex21 - vertex20) * 0.25);
            var      vertex20211 = new GeoCoordinate(point[1], point[0]);

            point = vertex20 + ((vertex21 - vertex20) * 0.75);
            var vertex20212 = new GeoCoordinate(point[1], point[0]);

            // calculate route.
            IBasicRouter <TEdgeData> basicRouter = this.BuildBasicRouter(data);
            Router router = this.BuildRouter(data, interpreter, basicRouter);

            OsmSharpRoute route = router.Calculate(Vehicle.Car,
                                                   router.Resolve(Vehicle.Car, vertex20211),
                                                   router.Resolve(Vehicle.Car, vertex20212));

            Assert.AreEqual(2, route.Entries.Length);
            Assert.AreEqual(vertex20211.Latitude, route.Entries[0].Latitude, 0.0001);
            Assert.AreEqual(vertex20211.Longitude, route.Entries[0].Longitude, 0.0001);

            //Assert.AreEqual(vertex_21.Latitude, route.Entries[1].Latitude, 0.0001);
            //Assert.AreEqual(vertex_21.Longitude, route.Entries[1].Longitude, 0.0001);

            Assert.AreEqual(vertex20212.Latitude, route.Entries[1].Latitude, 0.0001);
            Assert.AreEqual(vertex20212.Longitude, route.Entries[1].Longitude, 0.0001);
        }
Beispiel #5
0
        /// <summary>
        /// Aggregates a route by remove information useless to the generation of routing instructions.
        /// </summary>
        /// <param name="route"></param>
        /// <returns></returns>
        public AggregatedPoint Aggregate(OsmSharpRoute route)
        {
            // create the enumerator.
            AggregatedPointEnumerator enumerator = new AggregatedPointEnumerator(route);

            AggregatedRoutePoint previous = null;
            AggregatedRoutePoint current  = null;
            AggregatedRoutePoint next     = null;

            // loop over all aggregated points.
            while (enumerator.MoveNext())
            {
                // get the next point.
                next = enumerator.Current;

                // process
                this.Process(route, previous, current, next);

                // make the next, current and the current previous.
                previous = current;
                current  = next;
                next     = null;
            }

            // process once more, the current current has not been processed.
            this.Process(route, previous, current, next);

            return(p);
        }
Beispiel #6
0
        /// <summary>
        /// Test if routes from a resolved node to itself is correctly calculated.
        ///
        /// Regression Test: Routing to self with a resolved node returns a route to the nearest real node and back.
        /// </summary>
        protected void DoTestResolveBetweenRouteToSelf()
        {
            var interpreter = new OsmRoutingInterpreter();
            IBasicRouterDataSource <TEdgeData> data        = this.BuildData(interpreter, "OsmSharp.UnitTests.test_network.osm");
            IBasicRouter <TEdgeData>           basicRouter = this.BuildBasicRouter(data);
            Router router = this.BuildRouter(data, interpreter, basicRouter);

            // first test a non-between node.
            RouterPoint   resolved = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0576193, 3.7191801));
            OsmSharpRoute route    = router.Calculate(Vehicle.Car, resolved, resolved);

            Assert.AreEqual(1, route.Entries.Length);
            Assert.AreEqual(0, route.TotalDistance);
            Assert.AreEqual(0, route.TotalTime);

            resolved = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0578761, 3.7193972)); //,-103,  -4,  -8
            route    = router.Calculate(Vehicle.Car, resolved, resolved);
            Assert.AreEqual(1, route.Entries.Length);
            Assert.AreEqual(0, route.TotalDistance);
            Assert.AreEqual(0, route.TotalTime);


            resolved = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0576510, 3.7194124)); //,-104, -14, -12
            route    = router.Calculate(Vehicle.Car, resolved, resolved);
            Assert.AreEqual(1, route.Entries.Length);
            Assert.AreEqual(0, route.TotalDistance);
            Assert.AreEqual(0, route.TotalTime);

            resolved = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0576829, 3.7196791)); //,-105, -12, -10
            route    = router.Calculate(Vehicle.Car, resolved, resolved);
            Assert.AreEqual(1, route.Entries.Length);
            Assert.AreEqual(0, route.TotalDistance);
            Assert.AreEqual(0, route.TotalTime);
        }
Beispiel #7
0
 /// <summary>
 /// Raises the intermidiate results event.
 /// </summary>
 /// <param name="result"></param>
 /// <param name="weight"></param>
 protected void RaiseIntermidiateResult(OsmSharpRoute result, double weight)
 {
     if (IntermidiateResult != null)
     {
         this.IntermidiateResult(result, weight);
     }
 }
        /// <summary>
        /// Adds a new OsmSharpRoute.
        /// </summary>
        /// <param name="route">Stream.</param>
        /// <param name="argb">Stream.</param>
        public void AddRoute(OsmSharpRoute route, int argb)
        {
            if (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 blue = new SimpleColor()
                {
                    Value = argb
                };
                SimpleColor color = SimpleColor.FromArgb(argb);
                this.Scene.AddLine(float.MinValue, float.MaxValue, x, y,
                                   color.Value, 4);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Calculates metrics for the given route.
        /// </summary>
        /// <param name="route"></param>
        /// <returns></returns>
        public Dictionary <string, double> Calculate(OsmSharpRoute route)
        {
            OsmSharp.Routing.ArcAggregation.ArcAggregator aggregator =
                new OsmSharp.Routing.ArcAggregation.ArcAggregator(_interpreter);
            AggregatedPoint p = aggregator.Aggregate(route);

            return(this.Calculate(route.Vehicle, p));
        }
        /// <summary>
        /// Adds a new OsmSharpRoute.
        /// </summary>
        /// <param name="route">Stream.</param>
        public void AddRoute(OsmSharpRoute 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);
        }
Beispiel #11
0
        /// <summary>
        /// Generates instructions.
        /// </summary>
        /// <param name="route"></param>
        /// <param name="interpreter"></param>
        /// <param name="language_generator"></param>
        /// <returns></returns>
        public List <Instruction> Generate(OsmSharpRoute route, IRoutingInterpreter interpreter, ILanguageGenerator language_generator)
        {
            OsmSharp.Routing.ArcAggregation.ArcAggregator aggregator =
                new OsmSharp.Routing.ArcAggregation.ArcAggregator(interpreter);
            AggregatedPoint point =
                aggregator.Aggregate(route);

            return(this.Generate(point, interpreter, language_generator));
        }
        /// <summary>
        /// Compares all routes against the reference router.
        /// </summary>
        public void TestCompareAll(string embeddedName)
        {
            // build the routing settings.
            IRoutingInterpreter interpreter = new OsmSharp.Routing.Osm.Interpreter.OsmRoutingInterpreter();

            // get the osm data source.
            IBasicRouterDataSource <LiveEdge> data = this.BuildDykstraDataSource(interpreter, embeddedName);

            // build the reference router.;
            Router referenceRouter = this.BuildDykstraRouter(
                this.BuildDykstraDataSource(interpreter, embeddedName), interpreter,
                new DykstraRoutingLive(data.TagsIndex));

            // build the router to be tested.
            Router router = this.BuildRouter(interpreter, embeddedName);

            // loop over all nodes and resolve their locations.
            var resolvedReference = new RouterPoint[data.VertexCount - 1];
            var resolved          = new RouterPoint[data.VertexCount - 1];

            for (uint idx = 1; idx < data.VertexCount; idx++)
            { // resolve each vertex.
                float latitude, longitude;
                if (data.GetVertex(idx, out latitude, out longitude))
                {
                    resolvedReference[idx - 1] = referenceRouter.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude));
                    resolved[idx - 1]          = router.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude));
                }

                Assert.IsNotNull(resolvedReference[idx - 1]);
                Assert.IsNotNull(resolved[idx - 1]);

                Assert.AreEqual(resolvedReference[idx - 1].Location.Latitude,
                                resolved[idx - 1].Location.Latitude, 0.0001);
                Assert.AreEqual(resolvedReference[idx - 1].Location.Longitude,
                                resolved[idx - 1].Location.Longitude, 0.0001);
            }

            // check all the routes having the same weight(s).
            for (int fromIdx = 0; fromIdx < resolved.Length; fromIdx++)
            {
                for (int toIdx = 0; toIdx < resolved.Length; toIdx++)
                {
                    OsmSharpRoute referenceRoute = referenceRouter.Calculate(Vehicle.Car,
                                                                             resolvedReference[fromIdx], resolvedReference[toIdx]);
                    OsmSharpRoute route = router.Calculate(Vehicle.Car,
                                                           resolved[fromIdx], resolved[toIdx]);

                    Assert.IsNotNull(referenceRoute);
                    Assert.IsNotNull(route);
                    Assert.AreEqual(referenceRoute.TotalDistance, route.TotalDistance, 0.0001);
                    // TODO: meta data is missing in some CH routing; see issue
                    //Assert.AreEqual(reference_route.TotalTime, route.TotalTime, 0.0001);
                }
            }
        }
        /// <summary>
        /// Converts a simple VRP solution into a solution containing the actual routes.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="solution"></param>
        /// <param name="points"></param>
        protected OsmSharpRoute[] ConvertSolution(Vehicle vehicle, int[][] solution, RouterPoint[] points)
        {
            var routes = new OsmSharpRoute[solution.Length];

            for (int routeIdx = 0; routeIdx < solution.Length; routeIdx++)
            {
                // concatenate the route(s).
                OsmSharpRoute tsp = null;
                OsmSharpRoute route;
                for (int idx = 0; idx < solution[routeIdx].Length - 1; idx++)
                {
                    route = _router.Calculate(Vehicle.Car, points[solution[routeIdx][idx]],
                                              points[solution[routeIdx][idx + 1]]);
                    if (route != null && route.Entries.Length > 0)
                    {
                        if (tsp == null)
                        { // first route = start
                            tsp = route;
                        }
                        else
                        { // concatenate.
                            tsp = OsmSharpRoute.Concatenate(tsp, route);
                        }
                    }
                }

                // concatenate the route from the last to the first point again.
                route = _router.Calculate(vehicle, points[solution[routeIdx][solution[routeIdx].Length - 1]],
                                          points[solution[routeIdx][0]]);
                if (route.Entries.Length > 0)
                {
                    tsp = OsmSharpRoute.Concatenate(tsp, route);
                }

                // set the result.
                routes[routeIdx] = tsp;

                if (routes[routeIdx] != null)
                { // route exists!
                    var tags          = new List <RouteTags>();
                    var customerCount = new RouteTags();
                    customerCount.Key   = "customer_count";
                    customerCount.Value = solution[routeIdx].Length.ToString();
                    tags.Add(customerCount);
                    routes[routeIdx].Tags = tags.ToArray();

                    // set the correct vehicle type.
                    routes[routeIdx].Vehicle = vehicle;
                }
            }

            return(routes);
        }
Beispiel #14
0
        /// <summary>
        /// Builds an OsmSharRoute.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="points"></param>
        /// <param name="tspSolution"></param>
        /// <param name="weight"></param>
        /// <returns></returns>
        public OsmSharpRoute BuildRoute(Vehicle vehicle, RouterPoint[] points, IRoute tspSolution, double weight)
        {
            int[] solution = tspSolution.ToArray();

            OsmSharpRoute tsp = null;
            OsmSharpRoute route;

            for (int idx = 0; idx < solution.Length - 1; idx++)
            {
                route = _router.Calculate(Vehicle.Car, points[solution[idx]],
                                          points[solution[idx + 1]]);
                if (tsp == null)
                { // first route = start
                    tsp = route;
                }
                else
                { // concatenate.
                    tsp = OsmSharpRoute.Concatenate(tsp, route);
                }
            }
            if (tspSolution.IsRound)
            {
                // concatenate the route from the last to the first point again.
                route = _router.Calculate(Vehicle.Car, points[solution[solution.Length - 1]],
                                          points[solution[0]]);
                tsp = OsmSharpRoute.Concatenate(tsp, route);
            }

            if (tsp != null)
            {
                tsp.Vehicle = vehicle; // set the correct vehicle type.

                if (_interpreter != null)
                { // there is an interpreter set: calculate time/distance.
                    // calculate metrics.
                    var calculator = new TimeCalculator(_interpreter);
                    Dictionary <string, double> metrics = calculator.Calculate(tsp);
                    tsp.TotalDistance = metrics[TimeCalculator.DISTANCE_KEY];
                    tsp.TotalTime     = metrics[TimeCalculator.TIME_KEY];
                }

                tsp.Tags          = new RouteTags[1];
                tsp.Tags[0]       = new RouteTags();
                tsp.Tags[0].Key   = "internal_weight";
                tsp.Tags[0].Value = weight.ToString(System.Globalization.CultureInfo.InvariantCulture);
            }

            return(tsp);
        }
Beispiel #15
0
        public void TestTSPWrapperVehicle()
        {
            // calculate TSP.
            OsmSharpRoute route = this.CalculateTSP(Assembly.GetExecutingAssembly()
                                                    .GetManifestResourceStream(
                                                        @"OsmSharp.UnitTests.tsp_real.osm"),
                                                    Assembly.GetExecutingAssembly()
                                                    .GetManifestResourceStream(
                                                        @"OsmSharp.UnitTests.tsp_real.csv"),
                                                    false,
                                                    Vehicle.Car);

            Assert.IsNotNull(route);
            Assert.AreEqual(Vehicle.Car, route.Vehicle);
        }
Beispiel #16
0
        /// <summary>
        /// Tests that a router actually finds the shortest route.
        /// </summary>
        protected void DoTestShortestResolved2()
        {
            var interpreter = new OsmRoutingInterpreter();
            IBasicRouterDataSource <TEdgeData> data        = this.BuildData(interpreter, "OsmSharp.UnitTests.test_network.osm");
            IBasicRouter <TEdgeData>           basicRouter = this.BuildBasicRouter(data);
            Router router = this.BuildRouter(
                data, interpreter, basicRouter);
            RouterPoint source = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0581843, 3.7201209)); // between 2 - 3
            RouterPoint target = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0581484, 3.7194957)); // between 9 - 8

            OsmSharpRoute route = router.Calculate(Vehicle.Car, source, target);

            Assert.IsNotNull(route);
            Assert.AreEqual(5, route.Entries.Length);
        }
Beispiel #17
0
        /// <summary>
        /// Tests that a router actually finds the shortest route.
        /// </summary>
        protected void DoTestShortestResolved1()
        {
            var interpreter = new OsmRoutingInterpreter();
            IBasicRouterDataSource <TEdgeData> data        = this.BuildData(interpreter, "OsmSharp.UnitTests.test_network.osm");
            IBasicRouter <TEdgeData>           basicRouter = this.BuildBasicRouter(data);
            Router router = this.BuildRouter(
                data, interpreter, basicRouter);
            RouterPoint source = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0578153, 3.7193937));
            RouterPoint target = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0582408, 3.7194636));

            OsmSharpRoute route = router.Calculate(Vehicle.Car, source, target);

            Assert.IsNotNull(route);
            Assert.AreEqual(10, route.Entries.Length);
        }
Beispiel #18
0
        /// <summary>
        /// Tests that a router actually finds the shortest route.
        /// </summary>
        protected void DoTestShortestAgainstDirection()
        {
            var interpreter = new OsmRoutingInterpreter();
            IBasicRouterDataSource <EdgeData> data        = this.BuildData(interpreter);
            IBasicRouter <EdgeData>           basicRouter = this.BuildBasicRouter(data);
            Router router = this.BuildRouter(
                data, interpreter, basicRouter);
            RouterPoint source = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0579530, 3.7196168)); // -56
            RouterPoint target = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0582205, 3.7192647)); // -52

            OsmSharpRoute route = router.Calculate(Vehicle.Car, source, target);

            Assert.IsNotNull(route);
            Assert.AreEqual(6, route.Entries.Length);

            float latitude, longitude;

            data.GetVertex(10, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[0].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[0].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Start, route.Entries[0].Type);

            data.GetVertex(12, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[1].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[1].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Along, route.Entries[1].Type);

            data.GetVertex(13, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[2].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[2].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Along, route.Entries[2].Type);

            data.GetVertex(14, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[3].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[3].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Along, route.Entries[3].Type);

            data.GetVertex(15, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[4].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[4].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Along, route.Entries[4].Type);

            data.GetVertex(19, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[5].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[5].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Stop, route.Entries[5].Type);
        }
Beispiel #19
0
        /// <summary>
        /// Tests that a router actually finds the shortest route.
        /// </summary>
        protected void DoTestShortestDefault()
        {
            var interpreter = new OsmRoutingInterpreter();
            IBasicRouterDataSource <TEdgeData> data        = this.BuildData(interpreter, "OsmSharp.UnitTests.test_network.osm");
            IBasicRouter <TEdgeData>           basicRouter = this.BuildBasicRouter(data);
            Router router = this.BuildRouter(
                data, interpreter, basicRouter);
            RouterPoint source = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0578532, 3.7192229));
            RouterPoint target = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0576193, 3.7191801));

            OsmSharpRoute route = router.Calculate(Vehicle.Car, source, target);

            Assert.IsNotNull(route);
            Assert.AreEqual(5, route.Entries.Length);

            float latitude, longitude;

            data.GetVertex(20, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[0].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[0].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Start, route.Entries[0].Type);

            data.GetVertex(21, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[1].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[1].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Along, route.Entries[1].Type);

            data.GetVertex(16, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[2].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[2].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Along, route.Entries[2].Type);

            data.GetVertex(22, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[3].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[3].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Along, route.Entries[3].Type);

            data.GetVertex(23, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[4].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[4].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Stop, route.Entries[4].Type);
        }
        /// <summary>
        /// Tests access for a given vehicle type and for a given network between two given points.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="interpreter"></param>
        protected bool DoTestForVehicle(Vehicle vehicle, GeoCoordinate from, GeoCoordinate to,
                                        IRoutingInterpreter interpreter)
        {
            IBasicRouterDataSource <TEdgeData> data =
                this.BuildData(interpreter, "OsmSharp.UnitTests.test_segments.osm", vehicle);
            IBasicRouter <TEdgeData> basicRouter =
                this.BuildBasicRouter(data);
            Router router =
                this.BuildRouter(data, interpreter, basicRouter);

            RouterPoint resolvedFrom = router.Resolve(vehicle, from);
            RouterPoint resolvedTo   = router.Resolve(vehicle, to);

            if (resolvedFrom != null && resolvedTo != null)
            {
                OsmSharpRoute route = router.Calculate(vehicle, resolvedFrom, resolvedTo);
                return(route != null);
            }
            return(false);
        }
Beispiel #21
0
        public void RoutingRegressionTest1()
        {
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            SimpleTagsIndex tags_index = new SimpleTagsIndex();

            // do the data processing.
            DynamicGraphRouterDataSource <LiveEdge> memory_data =
                new DynamicGraphRouterDataSource <LiveEdge>(tags_index);
            LiveGraphOsmStreamWriter target_data = new LiveGraphOsmStreamWriter(
                memory_data, interpreter, memory_data.TagsIndex);
            XmlOsmStreamSource data_processor_source = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.UnitTests.test_routing_regression1.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);

            // resolve the three points in question.
            GeoCoordinate point35         = new GeoCoordinate(51.01257, 4.000753);
            RouterPoint   point35resolved = router.Resolve(Vehicle.Car, point35);
            GeoCoordinate point40         = new GeoCoordinate(51.01250, 4.000013);
            RouterPoint   point40resolved = router.Resolve(Vehicle.Car, point40);
            GeoCoordinate point45         = new GeoCoordinate(51.01315, 3.999588);
            RouterPoint   point45resolved = router.Resolve(Vehicle.Car, point45);

            // route between 35 and 45.
            OsmSharpRoute routebefore = router.Calculate(Vehicle.Car, point35resolved, point45resolved);

            GeoCoordinate point129         = new GeoCoordinate(51.01239, 3.999573);
            RouterPoint   point129resolved = router.Resolve(Vehicle.Car, point129);

            // route between 35 and 45.
            OsmSharpRoute routeafter = router.Calculate(Vehicle.Car, point35resolved, point45resolved);

            Assert.AreEqual(routebefore.TotalDistance, routeafter.TotalDistance);
        }
Beispiel #22
0
        /// <summary>
        /// Test if routes between two resolved nodes are correctly calculated.
        /// </summary>
        protected void DoTestResolveBetweenClose()
        {
            // initialize data.
            var interpreter = new OsmRoutingInterpreter();
            IBasicRouterDataSource <TEdgeData> data = this.BuildData(interpreter, "OsmSharp.UnitTests.test_network.osm");

            var vertex20 = new GeoCoordinate(51.0578532, 3.7192229);
            var vertex21 = new GeoCoordinate(51.0578518, 3.7195654);
            var vertex16 = new GeoCoordinate(51.0577299, 3.719745);

            for (double position1 = 0.1; position1 < 0.91; position1 = position1 + 0.1)
            {
                PointF2D point      = vertex20 + ((vertex21 - vertex20) * position1);
                var      vertex2021 = new GeoCoordinate(point[1], point[0]);
                for (double position2 = 0.1; position2 < 0.91; position2 = position2 + 0.1)
                {
                    point = vertex21 + ((vertex16 - vertex21) * position2);
                    var vertex2116 = new GeoCoordinate(point[1], point[0]);

                    // calculate route.
                    IBasicRouter <TEdgeData> basicRouter = this.BuildBasicRouter(data);
                    Router router = this.BuildRouter(data, interpreter, basicRouter);

                    OsmSharpRoute route = router.Calculate(Vehicle.Car,
                                                           router.Resolve(Vehicle.Car, vertex2021),
                                                           router.Resolve(Vehicle.Car, vertex2116));

                    Assert.AreEqual(3, route.Entries.Length);
                    Assert.AreEqual(vertex2021.Latitude, route.Entries[0].Latitude, 0.0001);
                    Assert.AreEqual(vertex2021.Longitude, route.Entries[0].Longitude, 0.0001);

                    Assert.AreEqual(vertex21.Latitude, route.Entries[1].Latitude, 0.0001);
                    Assert.AreEqual(vertex21.Longitude, route.Entries[1].Longitude, 0.0001);

                    Assert.AreEqual(vertex2116.Latitude, route.Entries[2].Latitude, 0.0001);
                    Assert.AreEqual(vertex2116.Longitude, route.Entries[2].Longitude, 0.0001);
                }
            }
        }
Beispiel #23
0
        /// <summary>
        /// Tests that a router actually finds the shortest route.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="accessTags"></param>
        protected void DoTestShortestWithAccess(Vehicle vehicle, List <KeyValuePair <string, string> > accessTags)
        {
            var interpreter = new OsmRoutingInterpreter();
            IBasicRouterDataSource <EdgeData> data        = this.BuildData(interpreter, vehicle, accessTags);
            IBasicRouter <EdgeData>           basicRouter = this.BuildBasicRouter(data, vehicle);
            Router router = this.BuildRouter(
                data, interpreter, basicRouter);
            RouterPoint source = router.Resolve(vehicle, new GeoCoordinate(51.0582205, 3.7192647)); // -52
            RouterPoint target = router.Resolve(vehicle, new GeoCoordinate(51.0579530, 3.7196168)); // -56

            OsmSharpRoute route = router.Calculate(vehicle, source, target);

            Assert.IsNotNull(route);
            Assert.AreEqual(4, route.Entries.Length);

            float latitude, longitude;

            data.GetVertex(19, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[0].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[0].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Start, route.Entries[0].Type);

            data.GetVertex(8, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[1].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[1].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Along, route.Entries[1].Type);

            data.GetVertex(9, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[2].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[2].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Along, route.Entries[2].Type);

            data.GetVertex(10, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[3].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[3].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Stop, route.Entries[3].Type);
        }
Beispiel #24
0
        /// <summary>
        /// Tests that a router preserves tags given to resolved points.
        /// </summary>
        protected void DoTestResolvedTags()
        {
            var interpreter = new OsmRoutingInterpreter();
            IBasicRouterDataSource <TEdgeData> data        = this.BuildData(interpreter, "OsmSharp.UnitTests.test_network.osm");
            IBasicRouter <TEdgeData>           basicRouter = this.BuildBasicRouter(data);
            Router router = this.BuildRouter(
                data, interpreter, basicRouter);
            RouterPoint source = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0578532, 3.7192229));

            source.Tags.Add(new KeyValuePair <string, string>("name", "source"));
            RouterPoint target = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0576193, 3.7191801));

            target.Tags.Add(new KeyValuePair <string, string>("name", "target"));

            OsmSharpRoute route = router.Calculate(Vehicle.Car, source, target);

            Assert.IsNotNull(route);
            Assert.AreEqual(5, route.Entries.Length);

            float latitude, longitude;

            data.GetVertex(20, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[0].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[0].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Start, route.Entries[0].Type);
            Assert.IsNotNull(route.Entries[0].Points[0].Tags);
            Assert.AreEqual(1, route.Entries[0].Points[0].Tags.Length);
            Assert.AreEqual("source", route.Entries[0].Points[0].Tags[0].Value);

            data.GetVertex(23, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[4].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[4].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Stop, route.Entries[4].Type);
            Assert.IsNotNull(route.Entries[4].Points[0].Tags);
            Assert.AreEqual(1, route.Entries[4].Points[0].Tags.Length);
            Assert.AreEqual("target", route.Entries[4].Points[0].Tags[0].Value);
        }
Beispiel #25
0
 private void MapMarkerClicked(object sender, EventArgs e)
 {
     if (sender is MapMarker)
     {
         lock (_router) {
             MapMarker   marker = sender as MapMarker;
             RouterPoint point  = _router.Resolve(Vehicle.Car, marker.Location);
             if (point != null)
             {
                 if (_previousPoint != null)
                 {
                     _routeLayer.Clear();
                     OsmSharpRoute route = _router.Calculate(Vehicle.Car, _previousPoint, point);
                     if (route != null)
                     {
                         _routeLayer.AddRoute(route);
                     }
                     _routeLayer.Invalidate();
                 }
                 _previousPoint = point;
             }
         }
     }
 }
Beispiel #26
0
        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);
            LiveGraphOsmStreamWriter target_data = new LiveGraphOsmStreamWriter(
                memory_data, interpreter, memory_data.TagsIndex);
            XmlOsmStreamSource data_processor_source = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.UnitTests.test_routing_regression1.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);

            // resolve the three points in question.
            GeoCoordinate point35         = new GeoCoordinate(51.01257, 4.000753);
            RouterPoint   point35resolved = router.Resolve(Vehicle.Car, point35);
            GeoCoordinate point45         = new GeoCoordinate(51.01315, 3.999588);
            RouterPoint   point45resolved = router.Resolve(Vehicle.Car, point45);
            GeoCoordinate point40         = new GeoCoordinate(51.01250, 4.000013);
            RouterPoint   point40resolved = router.Resolve(Vehicle.Car, point40);

            // calculate two smaller routes.
            OsmSharpRoute route3545             = router.Calculate(Vehicle.Car, point35resolved, point45resolved);
            OsmSharpRoute route4540             = router.Calculate(Vehicle.Car, point45resolved, point40resolved);
            OsmSharpRoute route3540concatenated = OsmSharpRoute.Concatenate(route3545, route4540);

            OsmSharpRoute route3540 = router.Calculate(Vehicle.Car, point35resolved, point40resolved);

            // check if both routes are equal.
            Assert.AreEqual(route3540.Entries.Length, route3540concatenated.Entries.Length);
            for (int idx = 0; idx < route3540.Entries.Length; idx++)
            {
                Assert.AreEqual(route3540.Entries[idx].Distance, route3540concatenated.Entries[idx].Distance);
                Assert.AreEqual(route3540.Entries[idx].Latitude, route3540concatenated.Entries[idx].Latitude);
                Assert.AreEqual(route3540.Entries[idx].Longitude, route3540concatenated.Entries[idx].Longitude);
                Assert.AreEqual(route3540.Entries[idx].Time, route3540concatenated.Entries[idx].Time);
                Assert.AreEqual(route3540.Entries[idx].Type, route3540concatenated.Entries[idx].Type);
                Assert.AreEqual(route3540.Entries[idx].WayFromName, route3540concatenated.Entries[idx].WayFromName);

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

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


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

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

            // remove the point in between, the only difference between the regular and the concatenated route.
            route3540concatenated.Entries[7].Points = null;

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

            // generate the instructions.
            var instructionGenerator        = new InstructionGenerator();
            List <Instruction> instructions =
                instructionGenerator.Generate(route3540, interpreter, languageGenerator);
            List <Instruction> instructionsConcatenated =
                instructionGenerator.Generate(route3540concatenated, interpreter, languageGenerator);

            Assert.AreEqual(instructions.Count, instructionsConcatenated.Count);
            for (int idx = 0; idx < instructions.Count; idx++)
            {
                Assert.AreEqual(instructions[idx].Location.Center,
                                instructionsConcatenated[idx].Location.Center);
                Assert.AreEqual(instructions[idx].Text,
                                instructionsConcatenated[idx].Text);
            }
        }
Beispiel #27
0
        public void RoutingRegressionTest4()
        {
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            SimpleTagsIndex tags_index = new SimpleTagsIndex();

            // do the data processing.
            DynamicGraphRouterDataSource <LiveEdge> memory_data =
                new DynamicGraphRouterDataSource <LiveEdge>(tags_index);
            LiveGraphOsmStreamWriter target_data = new LiveGraphOsmStreamWriter(
                memory_data, interpreter, memory_data.TagsIndex);
            XmlOsmStreamSource data_processor_source = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.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.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.
            OsmSharpRoute[][] referenceRoutes = new OsmSharpRoute[testPoints.Count][];
            int[]             permuationArray = new int[testPoints.Count];
            for (int fromIdx = 0; fromIdx < testPoints.Count; fromIdx++)
            {
                permuationArray[fromIdx] = fromIdx;
                referenceRoutes[fromIdx] = new OsmSharpRoute[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)
            {
                // 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.
                        OsmSharpRoute route = router.Calculate(Vehicle.Car, resolvedPoints[fromIdx], resolvedPoints[toIdx]);

                        Assert.AreEqual(referenceRoutes[fromIdx][toIdx].TotalDistance, route.TotalDistance, 0.1);
                    }
                }
            }
        }
        public void RouteConcatenateTagsTest()
        {
            OsmSharpRoute route1 = new OsmSharpRoute();

            route1.Vehicle = Vehicle.Car;
            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";
            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          = RoutePointEntryType.Start;
            route1entry2.WayFromName   = string.Empty;
            route1entry2.WayFromNames  = null;

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


            OsmSharpRoute route2 = new OsmSharpRoute();

            route2.Vehicle = Vehicle.Car;
            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          = "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          = 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";
            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          = RoutePointEntryType.Start;
            route2entry2.WayFromName   = string.Empty;
            route2entry2.WayFromNames  = null;

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

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

            // test the result.
            Assert.IsNotNull(concatenated);
            Assert.IsNotNull(concatenated.Entries);
            Assert.AreEqual(route1.Vehicle, concatenated.Vehicle);
            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("TestPoint3", concatenated.Entries[1].Points[1].Name);
            Assert.AreEqual("TestPoint4", concatenated.Entries[2].Points[0].Name);
        }
Beispiel #29
0
        /// <summary>
        /// Saves the route to a gpx file.
        /// </summary>
        /// <param name="file"></param>
        /// <param name="route"></param>
        internal static void Save(FileInfo file, OsmSharpRoute route)
        {
            XmlFileSource source = new XmlFileSource(file);
            GpxDocument output_document = new GpxDocument(source);
            gpxType output_gpx = new gpxType();
            output_gpx.trk = new trkType[1];

            // initialize all objects.
            List<wptType> segments = new List<wptType>();
            trkType track = new trkType();
            List<wptType> poi_gpx = new List<wptType>();

            track.trkseg = new trksegType[1];

            // ============= CONSTRUCT TRACK SEGMENT ==============
            trksegType track_segment = new trksegType();

            // loop over all points.
            for (int idx = 0; idx < route.Entries.Length; idx++)
            {
                // get the current entry.
                RoutePointEntry entry = route.Entries[idx];

                // ================== INITIALIZE A NEW SEGMENT IF NEEDED! ========
                wptType waypoint;
                if (entry.Points != null)
                { // loop over all points and create a waypoint for each.
                    for (int p_idx = 0; p_idx < entry.Points.Length; p_idx++)
                    {
                        RoutePoint point = entry.Points[p_idx];

                        waypoint = new wptType();
                        waypoint.lat = (decimal)point.Latitude;
                        waypoint.lon = (decimal)point.Longitude;
                        waypoint.name = point.Name;
                        poi_gpx.Add(waypoint);
                    }
                }

                // insert poi's.
                double longitde = entry.Longitude;
                double latitude = entry.Latitude;

                waypoint = new wptType();
                waypoint.lat = (decimal)entry.Latitude;
                waypoint.lon = (decimal)entry.Longitude;

                segments.Add(waypoint);
            }

            // put the segment in the track.
            track_segment.trkpt = segments.ToArray();
            track.trkseg[0] = track_segment;

            // set the track to the output.
            output_gpx.trk[0] = track;
            output_gpx.wpt = poi_gpx.ToArray();

            // save the ouput.
            output_document.Gpx = output_gpx;
            output_document.Save();
        }
Beispiel #30
0
        static void MainTemp(string[] args)
        {
            NpgsqlConnection schemaConnection = new NpgsqlConnection(connPostGreSql);

            schemaConnection.Open();
            var       databaseName = "GIS";
            DataTable dataTables   = schemaConnection.GetSchema("Tables", new string[] { databaseName, "public", null, null });

            foreach (DataRow rowTable in dataTables.Rows)
            {
                string tableName = rowTable["table_name"].ToString();
                if (tableName != "geometry_collection")
                {
                    continue;
                }
                DataTable     dataColumns = schemaConnection.GetSchema("Columns", new string[] { databaseName, "public", tableName });
                StringBuilder sb          = new StringBuilder();
                sb.AppendLine("public class " + tableName);
                sb.AppendLine("{");
                sb.AppendLine("\tpublic " + tableName + "(){}");

                foreach (DataRow rowColumn in dataColumns.Rows)
                {
                    string columnName = rowColumn["column_name"].ToString();
                    string type       = rowColumn["data_type"].ToString();
                    sb.AppendLine("\tpublic " + type + " " + columnName + " {get;set;}");
                }
                sb.AppendLine("}");
                sb.Replace("int8", "long");
                sb.Replace("int4", "int");
                sb.Replace("text", "string");
                sb.Replace("oid", "long");
                sb.Replace("numeric", "float");
                sb.Replace("timestamp", "DateTime");
                var def = sb.ToString();
            }

            schemaConnection.Close();
            return;

            var geometryRetrieval = geometryCollection.GetSingleObjectWithId("8", true, connPostGreSql);

            // testing GeometryCollection
            Aram.OSMParser.geometryCollection col = new Aram.OSMParser.geometryCollection();

            // col.gisId =
            col.gisType     = "dummy";
            col.format      = "txt";
            col.largeObject = null;
            col.lastUpdate  = DateTime.Now;
            col.latitude    = 563213212;
            col.longitude   = 171231231;
            col.name        = "Test2";
            col.pivot       = new Aram.OSMParser.Vector3GaPS()
            {
                x = 1f, y = 2f, z = 3f
            };
            col.version = new Aram.OSMParser.GaPSlabsVersion()
            {
                versionTitle = "development", major = 0, minor = 1
            };

            col.AddGeometryCollectionToDatabase(connPostGreSql, false);
            var bytes = File.ReadAllBytes(@"C:\Users\admgaming\Documents\Visual Studio 2012\Projects\GaPSLabs\AramOSMParser\OsmParserTestApplication\bin\Debug\Npgsql.xml");

            col.largeObject = bytes;
            col.UpdateThisGeometryOnDatabase(connPostGreSql, true);
            var resultBytes = geometryCollection.GetLargeObject(col.largeObjectReference, connPostGreSql);

            File.WriteAllBytes("c:\\dummy", resultBytes);

            return;

            // ERROR: 42704: invalid large-object descriptor: 0 ??
            // largeobject only works within a transaction. Use bytea as an alternative to large objects.
            // http://www.postgresql.org/message-id/002701c49d7e$0f059240$d604460a@zaphod
            NpgsqlConnection testConnection = new NpgsqlConnection(connPostGreSql);

            testConnection.Open();

            NpgsqlTypes.LargeObjectManager lm = new NpgsqlTypes.LargeObjectManager(testConnection);

            var generatedLO = lm.Create(NpgsqlTypes.LargeObjectManager.READWRITE);

            // It must be within a transaction
            var         TransWrite = testConnection.BeginTransaction();
            LargeObject lo         = lm.Open(generatedLO, LargeObjectManager.READWRITE);

            lo.Write(new byte[] { 0, 10, 50, 24 });
            lo.Close();
            TransWrite.Commit();

            var TransRead = testConnection.BeginTransaction();
            var loOid     = lo.GetOID();
            var readlo    = lm.Open(loOid, LargeObjectManager.READWRITE);
            var resultLo  = readlo.Read(readlo.Size());

            lm.Delete(generatedLO);
            TransRead.Commit();

            testConnection.Close();
            return;

            OSMPostgresqlSource sourceVisTest = new OSMPostgresqlSource(connPostGreSql);
            var bounds = sourceVisTest.Bounds;



            return;

            GaPSlabsSimulationLibrary.SUMOSimulationFCD df = new GaPSlabsSimulationLibrary.SUMOSimulationFCD();
            //df.LoadFromXML(@"C:\Users\admgaming\Desktop\Dropbox\GaPSLabs\SUMO Packet Tester\Pedestrians.xml");
            //df.LoadFromXML(@"C:\Users\admgaming\Desktop\Dropbox\GaPSLabs\SUMO Packet Tester\bufferoutput - 500.xml");

            ServiceGapslabsClient client2 = ServicePropertiesClass.GetGapslabsService(ServicePropertiesClass.ServiceUri);
            int id = client2.LoadSUMOFCDSimulationList(@"C:\Users\admgaming\Desktop\Dropbox\GaPSLabs\SUMO Packet Tester\bufferoutput - 500.xml", "__POSTFIX");

            //client.LoadSUMOFCDSimulation(@"C:\Users\admgaming\Desktop\Dropbox\GaPSLabs\SUMO Packet Tester\bufferoutput - 500.xml");
            while (!client2.IsSimulationLoadedList(id))
            {
            }
            var vvvv  = client2.GetTimestepAtList(6, id);
            var vvvv2 = client2.GetTimestepAtList(7, id);


            return;


            int size = 16777216;

            int[] aa   = new int[size];
            int[] bbb  = new int[size];
            int[] cccc = new int[size];
            for (int i = 0; i < size; i++)
            {
                aa[i]  = i;
                bbb[i] = i;
            }
            var apointer = aa.ToIntPtr <int[]>();
            var bpointer = bbb.ToIntPtr <int[]>();
            var cpointer = cccc.ToIntPtr <int[]>();

            long      MinGPU         = 1000000;
            long      MinCPU         = 1000000;
            long      MinCPUParallel = 100000;
            Stopwatch watch          = new Stopwatch();

            bool SkipCpu = false;

            GPU_WarmUp();
            int TestCounter = 0;
            int blockSize   = 16;

            while (TestCounter++ < 7)
            {
                watch.Restart();
                GPU_Add(apointer, bpointer, cpointer, size, blockSize);
                watch.Stop();
                Console.WriteLine("Total GPU" + "(" + blockSize + ")" + ": " + watch.ElapsedMilliseconds);
                if (watch.ElapsedMilliseconds < MinGPU)
                {
                    MinGPU = watch.ElapsedMilliseconds;
                }
                blockSize *= 2;
            }
            Console.WriteLine("Minimum GPU was " + MinGPU);

            if (!SkipCpu)
            {
                TestCounter = 0;
                while (TestCounter++ < 10)
                {
                    watch.Restart();
                    CPU_AddParallel(apointer, bpointer, cpointer, size);
                    watch.Stop();
                    Console.WriteLine("Total CPU Parallel: " + watch.ElapsedMilliseconds);
                    if (watch.ElapsedMilliseconds < MinCPUParallel)
                    {
                        MinCPUParallel = watch.ElapsedMilliseconds;
                    }
                }
                Console.WriteLine("Minimum CPU was " + MinCPU);

                TestCounter = 0;
                while (TestCounter++ < 10)
                {
                    watch.Restart();
                    CPU_Add(apointer, bpointer, cpointer, size);
                    watch.Stop();
                    Console.WriteLine("Total CPU: " + watch.ElapsedMilliseconds);
                    if (watch.ElapsedMilliseconds < MinCPU)
                    {
                        MinCPU = watch.ElapsedMilliseconds;
                    }
                }
                Console.WriteLine("Minimum CPU was " + MinCPU);
            }
            //apointer.Free();
            //bpointer.Free();
            //cpointer.Free();
            Console.ReadLine();
            return;

            //GaPSlabsSimulationLibrary.SUMOSimulationFCD simulation = new GaPSlabsSimulationLibrary.SUMOSimulationFCD();
            //simulation.LoadFromXML(@"C:\Users\admgaming\Desktop\Dropbox\GaPSLabs\SUMOData\fcdoutput.xml");
            //simulation.LoadFromCSV(@"C:\Users\admgaming\Desktop\Notable Software\iMobility\stkhlm-taxi.csv");

            ServiceGapslabsClient client = ServicePropertiesClass.GetGapslabsService(ServicePropertiesClass.ServiceUri);
            //client.LoadSUMOFCDSimulation(@"C:\Users\admgaming\Desktop\Dropbox\GaPSLabs\SUMO Packet Tester\bufferoutput - 500.xml");
            //while (!client.IsSimulationLoaded())
            //    Console.WriteLine("Loading...");
            //Console.WriteLine("Load finished");
            //Console.ReadLine();
            //return;



            OSMPostgresqlSource sour = new OSMPostgresqlSource(connPostGreSql);
            // var TrafficNodes = sour.GetNodeIdsInBoundWithInfo(sour.Bounds, "traffic_signals");



            var result = client.GetWayTags("134972364", connPostGreSql);



            BoundsWCF b = new BoundsWCF();

            b.minlat = 59.32973;
            b.maxlat = 59.34481;
            b.minlon = 18.07556;
            b.maxlon = 18.1062;
            client.GetWayExtIdsInBound(connPostGreSql, b);

            client.InitializeRouter(connPostGreSql);

            OsmNodeWCF n1 = new OsmNodeWCF();

            n1.id    = "none";
            n1.order = -1;
            n1.lat   = 59.330957;
            n1.lon   = 18.059285;
            //n1.lat = 59.374563;
            //n1.lon = 18.0135727;
            OsmNodeWCF n2 = new OsmNodeWCF();

            n2.id    = "none";
            n2.order = -1;
            n2.lat   = 59.33784;
            n2.lon   = 18.088558;
            //n2.lat = 59.37225;
            //n2.lon = 18.00733;


            var RouterResult = client.RouteUsingDykstra(VehicleEnum.Car, n1, n2);

            OsmGeo.ShapeInterperter = new SimpleShapeInterpreter();
            PostgreSQLSimpleSchemaSource source = new PostgreSQLSimpleSchemaSource(connPostGreSql);

            // keeps a memory-efficient version of the osm-tags.
            OsmTagsIndex tags_index = new OsmTagsIndex();

            // creates a routing interpreter. (used to translate osm-tags into a routable network)
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            // create routing inter
            OsmSourceRouterDataSource routing_data = new OsmSourceRouterDataSource(
                interpreter, tags_index, source);

            // create the router object.
            //IRouter<RouterPoint> router = new Router<PreProcessedEdge>(routing_data, interpreter,
            //    new DykstraRoutingPreProcessed(routing_data.TagsIndex));
            IRouter <RouterPoint> router = new Router <PreProcessedEdge>(routing_data, interpreter
                                                                         , new DykstraRoutingPreProcessed(routing_data.TagsIndex));


            // resolve both points; find the closest routable road.

            //RouterPoint point1 = router.Resolve(VehicleEnum.Car, new GeoCoordinate(60.1674654,18.454302));
            // RouterPoint point2 = router.Resolve(VehicleEnum.Car, new GeoCoordinate(60.1673373,18.4541732));

            // Working
            //RouterPoint point1 = router.Resolve(VehicleEnum.Car, new GeoCoordinate(59.3863281, 18.0176665));
            //RouterPoint point2 = router.Resolve(VehicleEnum.Car, new GeoCoordinate(59.3675634, 18.0140447));

            // Working
            RouterPoint point1 = router.Resolve(VehicleEnum.Car, new GeoCoordinate(59.374563, 18.0135727));
            RouterPoint point2 = router.Resolve(VehicleEnum.Car, new GeoCoordinate(59.37225, 18.00733));

            //ArrayList al=new ArrayList();
            //foreach (var en in Enum.GetValues(typeof(VehicleEnum)))
            //{
            //    al.Add(Enum.GetName(typeof(VehicleEnum), (VehicleEnum)en) + "=" + router.SupportsVehicle((VehicleEnum)en));
            //}

            // calculate route.
            OsmSharpRoute route = router.Calculate(VehicleEnum.Car, point1, point2);

            route.SaveAsGpx(new FileInfo("route.gpx"));



            Console.ReadLine();
        }
Beispiel #31
0
        /// <summary>
        /// Processes a part of the route.
        /// </summary>
        /// <param name="route"></param>
        /// <param name="previous"></param>
        /// <param name="current"></param>
        /// <param name="next"></param>
        private void Process(OsmSharpRoute route, AggregatedRoutePoint previous, AggregatedRoutePoint current, AggregatedRoutePoint next)
        {
            // process the current point.
            if (current != null)
            {
                if (previous == null)
                { // point is always significant, it is the starting point!
                    // create point.
                    p              = new AggregatedPoint();
                    p.Angle        = null;
                    p.ArcsNotTaken = null;
                    p.Location     = new GeoCoordinate(current.Entry.Latitude, current.Entry.Longitude);
                    p.Points       = new List <PointPoi>();

                    if (current.Entry.Points != null)
                    {
                        foreach (RoutePoint route_point in current.Entry.Points)
                        {
                            PointPoi poi = new PointPoi();
                            poi.Name     = route_point.Name;
                            poi.Tags     = route_point.Tags.ConvertTo();
                            poi.Location = new GeoCoordinate(route_point.Latitude, route_point.Longitude);
                            poi.Angle    = null; // there is no previous point; no angle is specified.
                            p.Points.Add(poi);
                        }
                    }

                    previous_point = p;
                }
                else
                { // test if point is significant.
                    AggregatedArc next_arc = this.CreateArcAndPoint(previous, current, next);

                    // test if the next point is significant.
                    if (previous_arc == null)
                    { // this arc is always significant; it is the first arc.
                        previous_point.Next = next_arc;
                        previous_arc        = next_arc;
                    }
                    else
                    {     // there is a previous arc; a test can be done if the current point is significant.
                        if (this.IsSignificant(route.Vehicle, previous_arc, next_arc))
                        { // the arc is significant; append it to the previous arc.
                            previous_arc.Next.Next = next_arc;
                            previous_arc           = next_arc;
                            previous_point         = next_arc.Next;
                        }
                        else
                        { // if the arc is not significant compared to the previous one, the previous one can extend until the next point.
                          // THIS IS THE AGGREGATION STEP!

                            // add distance.
                            Meter distance_to_next = previous_arc.Next.Location.DistanceReal(next_arc.Next.Location);
                            previous_arc.Distance = previous_arc.Distance + distance_to_next;

                            // set point.
                            previous_arc.Next = next_arc.Next;
                        }
                    }
                }
            }
        }
Beispiel #32
0
 internal static void Save(FileInfo file, OsmSharpRoute osmSharpRoute)
 {
     throw new NotImplementedException();
 }