Пример #1
0
        /// <summary>
        /// Generates instructions.
        /// </summary>
        /// <param name="route"></param>
        /// <param name="interpreter"></param>
        /// <param name="languageGenerator"></param>
        /// <returns></returns>
        public static List <Instruction> Generate(Route route, IRoutingInterpreter interpreter, ILanguageGenerator languageGenerator)
        {
            if (route == null)
            {
                throw new ArgumentNullException("route");
            }
            if (route.Vehicle == null)
            {
                throw new InvalidOperationException("Vehicle not set on route: Cannot generate instruction for a route without a vehicle!");
            }
            if (interpreter == null)
            {
                throw new ArgumentNullException("interpreter");
            }
            if (languageGenerator == null)
            {
                throw new ArgumentNullException("languageGenerator");
            }

            OsmSharp.Routing.ArcAggregation.ArcAggregator aggregator =
                new OsmSharp.Routing.ArcAggregation.ArcAggregator(interpreter);
            AggregatedPoint point =
                aggregator.Aggregate(route);

            return(InstructionGenerator.Generate(point, interpreter, languageGenerator));
        }
        public void InstructionGenerationAFewTurns()
        {
            // create new interpreter.
            var interpreter = new OsmRoutingInterpreter();

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

            // calculate the route.
            OsmSharpRoute route = this.Calculate(
                new GeoCoordinate(51.089900970459, 3.44386267662048),
                new GeoCoordinate(51.0862655639648, 3.44465517997742));

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

            // test the results in the language generator.
            Assert.AreEqual(6, instructions.Count);
            Assert.AreEqual("GeneratePoi:1", instructions[0].Text);
            Assert.AreEqual("GenerateDirectTurn:0_Right_0", instructions[1].Text);
            Assert.AreEqual("GenerateDirectTurn:0_Left_0", instructions[2].Text);
            Assert.AreEqual("GenerateDirectTurn:0_Left_0", instructions[3].Text);
            Assert.AreEqual("GenerateDirectTurn:0_Right_0", instructions[4].Text);
            Assert.AreEqual("GeneratePoi:1", instructions[5].Text);
        }
Пример #3
0
        /// <summary>
        /// Generates instructions.
        /// </summary>
        /// <param name="route"></param>
        /// <param name="interpreter"></param>
        /// <param name="languageGenerator"></param>
        /// <returns></returns>
        public static List <Instruction> Generate(Route route, IRoutingInterpreter interpreter, ILanguageGenerator languageGenerator)
        {
            OsmSharp.Routing.ArcAggregation.ArcAggregator aggregator =
                new OsmSharp.Routing.ArcAggregation.ArcAggregator(interpreter);
            AggregatedPoint point =
                aggregator.Aggregate(route);

            return(InstructionGenerator.Generate(point, interpreter, languageGenerator));
        }
Пример #4
0
        /// <summary>
        /// Generates instructions.
        /// </summary>
        /// <param name="planner"></param>
        /// <param name="route"></param>
        /// <returns></returns>
        public static List <Instruction> Generate(MicroPlanner planner, Route route)
        {
            if (route == null)
            {
                throw new ArgumentNullException("route");
            }

            var aggregator = new ArcAggregator(planner.Interpreter);
            var point      = aggregator.Aggregate(route);

            if (point == null)
            { // returns an empty list because of an empty route.
                return(new List <Instruction>());
            }
            return(InstructionGenerator.Generate(planner, route, point));
        }
Пример #5
0
        /// <summary>
        /// Generates instructions.
        /// </summary>
        /// <param name="route"></param>
        /// <param name="point"></param>
        /// <param name="interpreter"></param>
        /// <param name="languageGenerator"></param>
        /// <returns></returns>
        public static List <Instruction> Generate(Route route, AggregatedPoint point, IRoutingInterpreter interpreter, ILanguageGenerator languageGenerator)
        {
            if (point == null)
            {
                throw new ArgumentNullException("route");
            }
            if (interpreter == null)
            {
                throw new ArgumentNullException("interpreter");
            }
            if (languageGenerator == null)
            {
                throw new ArgumentNullException("languageGenerator");
            }

            return(InstructionGenerator.Generate(new MicroPlanner(languageGenerator, interpreter), route, point));
        }
        public void InstructionGenerationNoTurns()
        {
            // create new interpreter.
            var interpreter = new OsmRoutingInterpreter();

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

            // calculate the route.
            OsmSharpRoute route = this.Calculate(
                new GeoCoordinate(51.09002, 3.44380),
                new GeoCoordinate(51.089900970459, 3.44386267662048));

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

            // test the results in the language generator.
            Assert.AreEqual(2, instructions.Count);
            Assert.AreEqual("GeneratePoi:1", instructions[0].Text);
            Assert.AreEqual("GeneratePoi:1", instructions[1].Text);
        }
        public void InstructionGenerationSimpleTurnSameStreet()
        {
            // create new interpreter.
            var interpreter = new OsmRoutingInterpreter();

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

            // calculate the route.
            OsmSharpRoute route = this.Calculate(
                new GeoCoordinate(51.09030, 3.44391),
                new GeoCoordinate(51.09002, 3.44380));

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

            // test the results in the language generator.
            Assert.AreEqual(3, instructions.Count);
            Assert.AreEqual("GeneratePoi:1", instructions[0].Text);
            Assert.AreEqual("GenerateDirectTurn:0_Left_0", instructions[1].Text);
            Assert.AreEqual("GeneratePoi:1", instructions[2].Text);
        }
Пример #8
0
 /// <summary>
 /// Generates instructions.
 /// </summary>
 /// <param name="aggregatePoint"></param>
 /// <param name="interpreter"></param>
 /// <returns></returns>
 public static List <Instruction> Generate(AggregatedPoint aggregatePoint, IRoutingInterpreter interpreter)
 {
     return(InstructionGenerator.Generate(aggregatePoint, interpreter,
                                          new OsmSharp.Routing.Instructions.LanguageGeneration.Defaults.SimpleEnglishLanguageGenerator()));
 }
Пример #9
0
 /// <summary>
 /// Generates instructions.
 /// </summary>
 /// <param name="route"></param>
 /// <param name="interpreter"></param>
 /// <returns></returns>
 public static List <Instruction> Generate(Route route, IRoutingInterpreter interpreter)
 {
     return(InstructionGenerator.Generate(route, interpreter,
                                          new OsmSharp.Routing.Instructions.LanguageGeneration.Defaults.EnglishLanguageGenerator()));
 }
Пример #10
0
        /// <summary>
        /// Calculates the route.
        /// </summary>
        /// <param name="transportMode">The transport mode.</param>
        /// <param name="start">The start point.</param>
        /// <param name="end">The end point.</param>
        /// <returns>
        /// A new <see cref="RouteModel" /> with the route details.
        /// </returns>
        public RouteModel CalculatePointToPoint(VehicleEnum transportMode, GeoCoordinate start, GeoCoordinate end)
        {
            // calculate route.
            var startPoint = router.Resolve(transportMode, start);
            var endPoint = router.Resolve(transportMode, end);
            var route = router.Calculate(transportMode, startPoint, endPoint);

            if (route == null)
            {
                throw new RoutingException("No matching route found.");
            }

            var coordinates = route.Entries
                .Select(x => new Coordinate(x.Latitude, x.Longitude))
                .ToList();

            var lineString = new LineString(coordinates);

            var feature = new Feature(
                lineString,
                new Dictionary<string, object>
                    {
                        { "name", "Test route result." },
                        { "distance", route.TotalDistance },
                        { "journeytime", route.TotalTime },
                    });

            var generator = new InstructionGenerator();
            var instructions = generator.Generate(route, interpreter, new SimpleEnglishLanguageGenerator());

            return new RouteModel
                       {
                           Results = new ResultSet(feature)
                       };
        }