/// <summary>
        /// Calculates the relative direction.
        /// </summary>
        /// <param name="from"></param>
        /// <param name="along"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public static RelativeDirection Calculate(GeoCoordinate from, GeoCoordinate along, GeoCoordinate to)
        {
            RelativeDirection direction = new RelativeDirection();

            double margin = 65;
            double straight_on = 10;
            double turn_back = 5;

            GeoCoordinateLine line_from = new GeoCoordinateLine(from, along);
            GeoCoordinateLine line_to = new GeoCoordinateLine(along, to);

            Degree angle = line_from.Direction.Angle(line_to.Direction);

            if (angle >= new Degree(360 - straight_on)
                || angle < new Degree(straight_on))
            {
                direction.Direction = RelativeDirectionEnum.StraightOn;
            }
            else if (angle >= new Degree(straight_on)
                && angle < new Degree(90 - margin))
            {
                direction.Direction = RelativeDirectionEnum.SlightlyLeft;
            }
            else if (angle >= new Degree(90 - margin)
                && angle < new Degree(90 + margin))
            {
                direction.Direction = RelativeDirectionEnum.Left;
            }
            else if (angle >= new Degree(90 + margin)
                && angle < new Degree(180 - turn_back))
            {
                direction.Direction = RelativeDirectionEnum.SharpLeft;
            }
            else if (angle >= new Degree(180 - turn_back)
                && angle < new Degree(180 + turn_back))
            {
                direction.Direction = RelativeDirectionEnum.TurnBack;
            }
            else if (angle >= new Degree(180 + turn_back)
                && angle < new Degree(270-margin))
            {
                direction.Direction = RelativeDirectionEnum.SharpRight;
            }
            else if (angle >= new Degree(270 - margin)
                && angle < new Degree(270 + margin))
            {
                direction.Direction = RelativeDirectionEnum.Right;
            }
            else if (angle >= new Degree(270 + margin)
                && angle < new Degree(360- straight_on))
            {
                direction.Direction = RelativeDirectionEnum.SlightlyRight;
            }
            //direction.Direction = RelativeDirectionEnum.StraightOn;
            direction.Angle = angle;

            return direction;
        }
 /// <summary>
 /// Generates an immidiate turn.
 /// </summary>
 /// <param name="instruction"></param>
 /// <param name="firstStreetCountTo"></param>
 /// <param name="firstStreetTo"></param>
 /// <param name="firstDirection"></param>
 /// <param name="secondStreetTo"></param>
 /// <param name="secondDirection"></param>
 /// <returns></returns>
 public Instruction GenerateImmidiateTurn(Instruction instruction, 
     int firstStreetCountTo, 
     List<KeyValuePair<string, string>> firstStreetTo, 
     OsmSharp.Tools.Math.Geo.Meta.RelativeDirection firstDirection, 
     List<KeyValuePair<string, string>> secondStreetTo, 
     RelativeDirection secondDirection)
 {
     instruction.Text = string.Format("GenerateImmidiateTurn:{0}_{1}_{2}_{3}",
                                      firstStreetCountTo, firstDirection,
                                      firstDirection.ToString(),
                                      secondDirection.ToString());
     return instruction;
 }
Exemple #3
0
        internal void GenerateImmidiateTurn(GeoCoordinateBox box,
            List<KeyValuePair<string, string>> before_name, RelativeDirection first_direction, int first_street_count_to,
            RelativeDirection second_direction, List<KeyValuePair<string, string>> first_street_to, List<KeyValuePair<string, string>> second_street_to, List<PointPoi> list)
        {
            // create a new instruction first.
            Instruction instruction = new Instruction(box);

            // pass the instruction to the language generator.
            instruction = _generator.GenerateImmidiateTurn(
                instruction, first_street_count_to, first_street_to, first_direction, second_street_to, second_direction);

            // add the instruction to the instructions list.
            _instructions.Add(instruction);
        }
        /// <summary>
        /// Generates an instruction for an immidiate turn.
        /// </summary>
        /// <param name="instruction"></param>
        /// <param name="firstStreetCountTo"></param>
        /// <param name="firstStreetTo"></param>
        /// <param name="firstDirection"></param>
        /// <param name="secondStreetTo"></param>
        /// <param name="secondDirection"></param>
        /// <returns></returns>
        public Instruction GenerateImmidiateTurn(Instruction instruction, int firstStreetCountTo, List<KeyValuePair<string, string>> firstStreetTo,
            RelativeDirection firstDirection, List<KeyValuePair<string, string>> secondStreetTo, RelativeDirection secondDirection)
        {
            if (firstStreetCountTo == 1)
            {
                instruction.Text = string.Format("Neem de 1ste afslag {0}, de {1} op, en ga onmiddellijk {2} op de {3}.",
                    TurnDirection(firstDirection.Direction),
                    this.GetName("nl", firstStreetTo),
                    TurnDirection(secondDirection.Direction),
                    this.GetName("nl", secondStreetTo));
            }
            else
            {
                instruction.Text = string.Format("Neem de {4}de afslag {0}, de {1} op, en ga onmiddellijk {2} op de {3}.",
                    TurnDirection(firstDirection.Direction),
                    this.GetName("nl", firstStreetTo),
                    TurnDirection(secondDirection.Direction),
                    this.GetName("nl", secondStreetTo),
                    firstStreetCountTo);
            }

            // returns the instruction with text.
            return instruction;
        }
Exemple #5
0
        internal void GeneratePoi(GeoCoordinateBox box, 
            List<PointPoi> list,
            RelativeDirection direction)
        {
            // create a new instruction first.
            Instruction instruction = new Instruction(box, list);
            Instruction direction_instruction = null;

            // pass the instruction to the languate generator.
            if (direction == null)
            {
                instruction = _generator.GeneratePoi(instruction, list, null);
            }
            else
            {
                // create a direction instruction.
                if (direction.Direction == RelativeDirectionEnum.TurnBack)
                {
                    direction_instruction = new Instruction(box, list);
                    direction_instruction = _generator.GenerateSimpleTurn(direction_instruction, direction.Direction);
                }

                // generates the instructions.
                instruction = _generator.GeneratePoi(instruction, list, null);
            }

            // add the instruction to the instructions list.
            _instructions.Add(instruction);

            // add the direction instruction.
            if (direction_instruction != null)
            {
                _instructions.Add(direction_instruction);
            }
        }
Exemple #6
0
        internal void GenerateTurn(GeoCoordinateBox box,
            RelativeDirection direction, 
            int street_count_turn,
            int street_count_before_turn, 
            List<KeyValuePair<string, string>> street_from,
            List<KeyValuePair<string, string>> street_to, 
            List<PointPoi> list)
        {
            // create a new instruction first.
            Instruction instruction = new Instruction(box, list);

            // pass the instruction to the languate generator.
            // test if the street is the same but a turn needs to be taken anyway.
            if (street_from == street_to)
            {
                if (street_count_turn == 0)
                {// there are no other streets between the one being turned into and the street coming from in the same
                    // direction as the turn.
                    instruction = _generator.GenerateDirectFollowTurn(
                        instruction, street_count_before_turn, street_to, direction.Direction, list);
                }
                else
                { // there is another street; this is tricky to explain.
                    instruction = _generator.GenerateIndirectFollowTurn(
                        instruction, street_count_turn, street_count_before_turn, street_to, direction.Direction, list);
                }
            }
            else
            {
                if (street_count_turn == 0)
                { // there are no other streets between the one being turned into and the street coming from in the same
                    // direction as the turn.
                    instruction = _generator.GenerateDirectTurn(
                        instruction, street_count_before_turn, street_to, direction.Direction, list);
                }
                else
                { // there is another street; this is tricky to explain.
                    instruction = _generator.GenerateIndirectTurn(
                        instruction, street_count_turn, street_count_before_turn, street_to, direction.Direction, list);
                }
            }

            // add the instruction to the instructions list.
            _instructions.Add(instruction);
        }
        /// <summary>
        /// Generates an instruction for an immidiate turn.
        /// </summary>
        /// <param name="instruction"></param>
        /// <param name="first_street_count_to"></param>
        /// <param name="first_street_to"></param>
        /// <param name="first_direction"></param>
        /// <param name="second_street_to"></param>
        /// <param name="second_direction"></param>
        /// <returns></returns>
        public Instruction GenerateImmidiateTurn(Instruction instruction, int first_street_count_to, List<KeyValuePair<string, string>> first_street_to,
            RelativeDirection first_direction, List<KeyValuePair<string, string>> second_street_to, RelativeDirection second_direction)
        {
            if (first_street_count_to == 1)
            {
                instruction.Text = string.Format("Take the first turn {0}, on the {1}, and turn immidiately {2} on the {3}.",
                    this.TurnDirection(first_direction.Direction),
                    this.GetName("en", first_street_to),
                    this.TurnDirection(second_direction.Direction),
                    this.GetName("en", second_street_to));
            }
            else
            {
                instruction.Text = string.Format("Take the {4} turn {0}, on the {1}, and turn immidiately {2} on the {3}.",
                    this.TurnDirection(first_direction.Direction),
                    this.GetName("en", first_street_to),
                    this.TurnDirection(second_direction.Direction),
                    this.GetName("en", second_street_to),
                    AddOrdinal(first_street_count_to));
            }

            // returns the instruction with text.
            return instruction;
        }