MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




Distance/Time between Waypoints

This is a discussion on Distance/Time between Waypoints within the MapPoint 2006/2009 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 ...


Go Back   MapPoint Forums > Map Forums > MapPoint 2006/2009 Discussion

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read



Click here to register

Reply

 

LinkBack (5) Thread Tools Display Modes
  5 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 08-10-2007
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 08-10-2007
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
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 08-11-2007
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,122
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 08-13-2007
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 08-14-2007
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,122
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 08-14-2007
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 08-14-2007
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;
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8 (permalink)  
Old 08-18-2007
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,122
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();
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
distance or time, waypoints


LinkBacks (?)
LinkBack to this Thread: http://www.mapforums.com/distance-time-between-waypoints-6157.html

Posted By For Type Date
MapPoint User Community - MP2K Magazine This thread Refback 08-15-2007 10:54 PM
MapPoint Download - MP2K Magazine This thread Refback 08-14-2007 03:34 PM
Microsoft MapPoint 2006 - MP2K Magazine This thread Refback 08-14-2007 03:34 PM
MapPoint Help - MP2K Magazine This thread Refback 08-13-2007 05:20 AM
MapPoint Forums This thread Refback 08-12-2007 08:51 PM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

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


All times are GMT -5. The time now is 12:23 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
MP2K Magazine
Visitor Map


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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55