Community of VE/MapPoint Users and Developers
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 ...
| |||||||
| Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| Distance/Time between Waypoints 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;
}
Need an easy way, i hate this code |
| |||
| 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 } |
| |||
| 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.
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
| |||
| 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! |
| |||
| 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);
}
Note that you also can use for each.
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
| |||
| 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! |
| |||
| 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();
}
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
![]() |
| ||||
| Posted By | For | Type | Date | |
| MapPoint User Community - MP2K Magazine | This thread | Refback | 08-15-2007 09:54 PM | |
| MapPoint Download - MP2K Magazine | This thread | Refback | 08-14-2007 02:34 PM | |
| Microsoft MapPoint 2006 - MP2K Magazine | This thread | Refback | 08-14-2007 02:34 PM | |
| MapPoint Help - MP2K Magazine | This thread | Refback | 08-13-2007 04:20 AM | |
| MapPoint Forums | This thread | Refback | 08-12-2007 07:51 PM | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| 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 03:52 PM |
| Distance calculation time (MP 2006) - HELP | dsia | MapPoint 2006/2009 Discussion | 3 | 06-04-2007 02:16 AM |
| Distance/Drive Time | stwilber | MapPoint 2006/2009 Discussion | 1 | 11-10-2006 10:13 AM |
| Automate large list of drive time & distance calculation | onegalacticwino | MapPoint 2006/2009 Discussion | 1 | 12-13-2004 01:14 PM |
| My calculations on distance and time appear to be wrong | Anonymous | MapPoint 2006/2009 Discussion | 0 | 11-27-2004 05:58 PM |
MyTravel Flights
Book MyTravel Holidays At Holiday Hypermarket. MyTravel arranges flights and accommodation for great value to great destinations.
Cruise Travel Agent
Book your cruise with Travel Counsellors. We are an award winning travel agent and can help plan your perfect cruise.
Cuba Holiday
A Cuba Holiday has so much to offer with numerous different cultures affecting the sights, sounds and tastes. Visit this fascinating country with dealchecker.co.uk.
Bahamas Holidays
Bahamas Holidays offer pure blue skies, soft white beaches and the holiday of a lifetime. Visit us for a great deal to the Bahamas.
Cheap Greece Holidays
For cheap Greece holidays make sure you know when to book and who to book with. Visit ulookubook.com to get help with doing both of those things. Why not time your visit with a Greek festival?
Compare Holidays
Compare holidays online where you can see all the amazing possibilities at Travel.co.uk
Holidays to Florida
Sun and sea! Get info on holidays to Florida, only at On The Beach.