Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 8 of 8

Distance/Time between Waypoints

This is a discussion on Distance/Time between Waypoints within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hi there, i need the distance and time between the waypoints an save it in a table in which each ...

  1. #1
    jasanite is offline Member Yellow Belt
    Join Date
    Jul 2007
    Posts
    45

    Distance/Time between Waypoints

    Hi there,
    i need the distance and time between the waypoints an save it
    in a table in which each row represents a waypoint. First waypoint
    hast 0 distance an 0 time, 2cnd has distance/time from 1to2, 3rd
    has distance/time from 2to3 ... etc.. The ids of the Rows are in
    the name property of the waypoint.

    Hmm, i paste my algo, my comment is that it is quite dirty, is there
    an easier way to get those informations in one flush.

    Code:
     
    private void FillSegments(RoutingSet.WaypointDataTable waypointTable)
    {
    bool move = true;
     
    RoutingSet.WaypointRow waypointRow;
    MapPoint.Direction direction;
    string currentId = "";
    double segmentDistance = 0.0;
    DateTime startTime = DateTime.Today;
    double segmentTime = 0.0;
     
    MapPoint.Directions directions = CurrentRoute.Directions;
    IEnumerator items = directions.GetEnumerator();
    items.Reset();
    move = items.MoveNext();
    while (move)
    {
    direction = ((MapPoint.Direction)items.Current);
    currentId = direction.Waypoint.Name;
    segmentDistance = direction.Distance;
    startTime = direction.StartTime;
    segmentTime = 0.0;
     
    move = items.MoveNext();
    direction = ((MapPoint.Direction)items.Current);
    while (move && (currentId == direction.Waypoint.Name))
    {
    segmentDistance += direction.Distance;
     
    move = items.MoveNext();
    direction = ((MapPoint.Direction)items.Current);
    if (move)
    {
    segmentTime = GetDurationHours(startTime, direction.StartTime);
    }
    }
     
    if (move && currentId != direction.Waypoint.Name)
    {
    waypointRow = waypointTable.FindByWaypointId(direction.Waypoint.Name);
    waypointRow.ElapsedTime = segmentTime;
    waypointRow.Mileage = segmentDistance;
    }
    }
     
    // the id of the last waypoint is not shown in the list so i need to
    look for it
    IEnumerator waypoints = CurrentRoute.Waypoints.GetEnumerator();
    waypoints.Reset();
    waypoints.MoveNext();
    MapPoint.Waypoint waypoint = ((MapPoint.Waypoint)waypoints.Current);
    while (waypoints.MoveNext())
    {
    waypoint = ((MapPoint.Waypoint)waypoints.Current);
    }
    waypointRow = waypointTable.FindByWaypointId(waypoint.Name);
    waypointRow.ElapsedTime = segmentTime;
    waypointRow.Mileage = segmentDistance;
    }
    The Code is just to confuse you, but it works...

    Need an easy way, i hate this code

  2. #2
    jasanite is offline Member Yellow Belt
    Join Date
    Jul 2007
    Posts
    45

    Re: Distance/Time between Waypoints

    how can i make the code-parts ... can't find them

    forgot a function i use inside:

    private double GetDurationHours(DateTime start, DateTime end)
    {
    TimeSpan diff = new TimeSpan(end.Ticks - start.Ticks);
    return diff.TotalDays; //mp point gives me days in the Route.TripTime prop so i chose it here to, but i use partial funtions in my DataSet so it doesn't matter
    }

  3. #3
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    Re: Distance/Time between Waypoints

    Hi,

    Your code is difficult to read. Please put it in between [ code ] [ /code] tags. But it seems ok. You step to all points to read the results so has it to be done if I do have understeand the question right.

  4. #4
    jasanite is offline Member Yellow Belt
    Join Date
    Jul 2007
    Posts
    45

    Re: Distance/Time between Waypoints

    ok, so you got to do the iteration by yourself
    but ...
    why has the last segment, which distance=0,
    the wrong id, it always carries the 2cnd last
    id, why is that
    i use the directions of the route, logically it
    should have the waypoint with the last id in
    it .... or maybe not, do me!

  5. #5
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    Re: Distance/Time between Waypoints

    Hi,

    Probably some error in the logic ? I don't see it immediately in your code, but if I try the code below I have all waypoints listed:

    Code:
    for (int i = 1; i <= route.Directions.Count; i++) {
    	object o = i;
    	Direction direction = route.Directions.get_Item(ref o);
    }
    If you need total distance and total driving time, they are also properties of the Route object.

    Note that you also can use for each.

  6. #6
    jasanite is offline Member Yellow Belt
    Join Date
    Jul 2007
    Posts
    45

    Re: Distance/Time between Waypoints

    Hi,
    personally i like your iteration way.
    Question: If i go through all of the direction elements ...
    Answer: I use the IEnumerator until .MoveNext() returns
    false, so i think i iterate all elements. Inspected the
    code already step by step and in the last segment the
    distance is 0, like expected, but the name of the waypoint
    isn't the last one. direction.waypoint is not the last
    waypoint.
    Is it normal that the last waypoint isn't referenced?
    (Tell me, yes, the direction items reference all waypoints,
    no, the last waypoint isn't referenced because it isn't
    necessary)

    To test i use 6 points. startpoint = endpoint... do me!

  7. #7
    jasanite is offline Member Yellow Belt
    Join Date
    Jul 2007
    Posts
    45

    Re: Distance/Time between Waypoints

    Code:
    MapPoint.Directions items = route.Directions.GetEnumerator();
    items.Reset();
    while(items.MoveNext())
    {
        MapPoint.Direction item = (MapPoint.Direction)items.Current;
    }

  8. #8
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    Re: Distance/Time between Waypoints

    Hi,

    I did not try. But maybe the MoveNext returns false if positioned on the last record ? In that case you will not have the last one listed in your loop. You can also use the EOF property if the recordset, something like this:

    Code:
    while (!items.EOF) {
       // here read the item
       items.MoveNext();
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How do you create a time to distance map?
    By Integraoligist in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 08-01-2007, 04:52 PM
  2. Distance calculation time (MP 2006) - HELP
    By dsia in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 06-04-2007, 03:16 AM
  3. Distance/Drive Time
    By stwilber in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 11-10-2006, 11:13 AM
  4. Automate large list of drive time & distance calculation
    By onegalacticwino in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 12-13-2004, 02:14 PM
  5. My calculations on distance and time appear to be wrong
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 11-27-2004, 06:58 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36