ThinkGeo.com    |     Documentation    |     Premium Support

How to get endpoint on route

Hi I have the following function that takes a list of destinations and find the one with the shortest route.
Is it possible to mark the start and end point on the result?
I have the start point but is there any method on the routingresult to get first and last point? (endpoint) 
On the addRouteToMap i need to show the destination.
 
 
public static RoutingResult GetShortestRoute(PointShape startPoint, List<Feature> pointDestinationList)
{
    var _route = new RoutingResult();
    double dist = -1;            
        foreach (var item in pointDestinationList)
        {
            var endPoint = item.GetShape().GetCenterPoint();
            var tmpRoute = GetRoute(startPoint, endPoint);
            if (tmpRoute.Distance < dist || dist == -1)
            {
                dist = _route.Distance;
                _route = tmpRoute;
            }
        }                        
    return _route;
}
 
public void AddRouteToMap(RoutingResult request, PointShape startPoint)
{            
    LayerOverlay routingOverlay = new LayerOverlay();
    var routingLayer = new RoutingLayer();
    routingLayer.Routes.Add(request.Route);
    
    routingLayer.StartPoint = startPoint;
    //routingLayer.EndPoint = ???;         
 
    routingOverlay.Layers.Add("RoutingExtentLayer", routingLayer);    
    winformsMap1.Overlays.Add("RoutingOverlay", routingOverlay);       
    winformsMap1.Refresh();
}
 
- Niels

Hello Niels, 
  
 Once you get the RoutingResult in your method AddRouteToMap, and you know the start point, you can simply get the first features and the last features in the RoutingResult.Features, because start point and end point are always the first point and the last point, so compare with your startpoint, you can get the end point. 
  
 Regards, 
  
 Gary

 Hi Gary, I can't find the right data in the feature set.


Here is my get route function, but looking in the routingResult.Features i don't see any usefull x,y ??
 
 
public RoutingResult GetRoute(PointShape startPoint, PointShape endPoint)
{
    RoutingResult routingResult = new RoutingResult();
    ShapeFileFeatureLayer dkRoadsLayer = new ShapeFileFeatureLayer(dkRoads);
    dkRoadsLayer.Open();
    RoutingSource routingSource = new RtgRoutingSource(dkRoadsIndex);
    var algorithm = new DijkstraRoutingAlgorithm();
    RoutingEngine routingEngine = new RoutingEngine(routingSource, algorithm, dkRoadsLayer.FeatureSource);
    routingEngine.RoutingResultsType = RoutingResultsType.RouteSegmentsAndFeatures;
    routingResult = routingEngine.GetRoute(startPoint, endPoint);
    dkRoadsLayer.Close();
    
    //using servicestack.text to write .Dump()
    Console.WriteLine(routingResult.Dump());
    
    return routingResult;
}
 
 
 
{
osm_id: 25783817,
lastchange: "1970-01-01T00:00:00",
code: 5114,
fclass: secondary,
name: Hvalsøvej,
ref: 255,
oneway: F,
maxspeed: ,
layer: 0,
bridge: F,
tunnel: F
}
{
osm_id: 25783817,
lastchange: "1970-01-01T00:00:00",
code: 5114,
fclass: secondary,
name: Hvalsøvej,
ref: 255,
oneway: F,
maxspeed: ,
layer: 0,
bridge: F,
tunnel: F
}
{
osm_id: 25783817,
lastchange: "1970-01-01T00:00:00",
code: 5114,
fclass: secondary,
name: Hvalsøvej,
ref: 255,
oneway: F,
maxspeed: ,
layer: 0,
bridge: F,
tunnel: F
}
{
osm_id: 25783817,
lastchange: "1970-01-01T00:00:00",
code: 5114,
fclass: secondary,
name: Hvalsøvej,
ref: 255,
oneway: F,
maxspeed: ,
layer: 0,
bridge: F,
tunnel: F
}
{
osm_id: 25783817,
lastchange: "1970-01-01T00:00:00",
code: 5114,
fclass: secondary,
name: Hvalsøvej,
ref: 255,
oneway: F,
maxspeed: ,
layer: 0,
bridge: F,
tunnel: F
}
{
osm_id: 29233465,
lastchange: "1970-01-01T00:00:00",
code: 5122,
fclass: residential,
name: Bygaden,
ref: ,
oneway: F,
maxspeed: ,
layer: 0,
bridge: F,
tunnel: F
}
{
osm_id: 29233465,
lastchange: "1970-01-01T00:00:00The thread '<No Name>' (0x450) has exited with code 0 (0x0).
",
code: 5122,
fclass: residential,
name: Bygaden,
ref: ,
oneway: F,
maxspeed: ,
layer: 0,
bridge: F,
tunnel: F
}
{
osm_id: 29233465,
lastchange: "1970-01-01T00:00:00",
code: 5122,
fclass: residential,
name: Bygaden,
ref: ,
oneway: F,
maxspeed: ,
layer: 0,
bridge: F,
tunnel: F
}
{
osm_id: 29233465,
lastchange: "1970-01-01T00:00:00",
code: 5122,
fclass: residential,
name: Bygaden,
ref: ,
oneway: F,
maxspeed: ,
layer: 0,
bridge: F,
tunnel: F
}
{
osm_id: 29233465,
lastchange: "1970-01-01T00:00:00",
code: 5122,
fclass: residential,
name: Bygaden,
ref: ,
oneway: F,
maxspeed: ,
layer: 0,
bridge: F,
tunnel: F
}
{
osm_id: 29233465,
lastchange: "1970-01-01T00:00:00",
code: 5122,
fclass: residential,
name: Bygaden,
ref: ,
oneway: F,
maxspeed: ,
layer: 0,
bridge: F,
tunnel: F
}
{
osm_id: 29233465,
lastchange: "1970-01-01T00:00:00",
code: 5122,
fclass: residential,
name: Bygaden,
ref: ,
oneway: F,
maxspeed: ,
layer: 0,
bridge: F,
tunnel: F
}
{
osm_id: 29233465,
lastchange: "1970-01-01T00:00:00",
code: 5122,
fclass: residential,
name: Bygaden,
ref: ,
oneway: F,
maxspeed: ,
layer: 0,
bridge: F,
tunnel: F
}
{
osm_id: 29233465,
lastchange: "1970-01-01T00:00:00",
code: 5122,
fclass: residential,
name: Bygaden,
ref: ,
oneway: F,
maxspeed: ,
layer: 0,
bridge: F,
tunnel: F
}
{
osm_id: 29233465,
lastchange: "1970-01-01T00:00:00",
code: 5122,
fclass: residential,
name: Bygaden,
ref: ,
oneway: F,
maxspeed: ,
layer: 0,
bridge: F,
tunnel: F
}
{
osm_id: 28093098,
lastchange: "1970-01-01T00:00:00",
code: 5114,
fclass: secondary,
name: Bonderupvej,
ref: 255,
oneway: F,
maxspeed: ,
layer: 0,
bridge: F,
tunnel: F
}
{
osm_id: 28085249,
lastchange: "1970-01-01T00:00:00",
code: 5114,
fclass: secondary,
name: Bonderupvej,
ref: 215,
oneway: F,
maxspeed: ,
layer: 0,
bridge: F,
tunnel: F
}
 
 
 
{
OrderedStops: [],
Route: 
{
Lines: 
[
{
Vertices: 
[
"X:  11.7476; Y: 55.5510",
"X:  11.7494; Y: 55.5515",
"X:  11.7558; Y: 55.5535",
"X:  11.7566; Y: 55.5538",
"X:  11.7591; Y: 55.5549"
],
CanRotate: True,
Id: 77c005f0-d48c-4061-a56b-b25e2414656c
},
{
Vertices: 
[
"X:  11.7473; Y: 55.5509",
"X:  11.7476; Y: 55.5510"
],
CanRotate: True,
Id: 98243
},
{
Vertices: 
[
"X:  11.7465; Y: 55.5506",
"X:  11.7473; Y: 55.5509"
],
CanRotate: True,
Id: 98242
},
{
Vertices: 
[
"X:  11.7231; Y: 55.5438",
"X:  11.7326; Y: 55.5466",
"X:  11.7420; Y: 55.5493",
"X:  11.7465; Y: 55.5506"
],
CanRotate: True,
Id: 98241
},
{
Vertices: 
[
"X:  11.7196; Y: 55.5428",
"X:  11.7231; Y: 55.5438"
],
CanRotate: True,
Id: 98240
},
{
Vertices: 
[
"X:  11.7170; Y: 55.5435",
"X:  11.7177; Y: 55.5436",
"X:  11.7182; Y: 55.5435",
"X:  11.7189; Y: 55.5433",
"X:  11.7194; Y: 55.5430",
"X:  11.7196; Y: 55.5428"
],
CanRotate: True,
Id: 161984
},
{
Vertices: 
[
"X:  11.7169; Y: 55.5435",
"X:  11.7170; Y: 55.5435"
],
CanRotate: True,
Id: 161983
},
{
Vertices: 
[
"X:  11.7161; Y: 55.5434",
"X:  11.7169; Y: 55.5435"
],
CanRotate: True,
Id: 161982
},
{
Vertices: 
[
"X:  11.7153; Y: 55.5433",
"X:  11.7161; Y: 55.5434"
],
CanRotate: True,
Id: 161981
},
{
Vertices: 
[
"X:  11.7151; Y: 55.5433",
"X:  11.7153; Y: 55.5433"
],
CanRotate: True,
Id: 161980
},
{
Vertices: 
[
"X:  11.7138; Y: 55.5434",
"X:  11.7142; Y: 55.5433",
"X:  11.7151; Y: 55.5433"
],
CanRotate: True,
Id: 161979
},
{
Vertices: 
[
"X:  11.7113; Y: 55.5437",
"X:  11.7120; Y: 55.5436",
"X:  11.7133; Y: 55.5435",
"X:  11.7138; Y: 55.5434"
],
CanRotate: True,
Id: 161978
},
{
Vertices: 
[
"X:  11.7096; Y: 55.5438",
"X:  11.7104; Y: 55.5438",
"X:  11.7113; Y: 55.5437",
"X:  11.7113; Y: 55.5437"
],
CanRotate: True,
Id: 161977
},
{
Vertices: 
[
"X:  11.7093; Y: 55.5438",
"X:  11.7096; Y: 55.5438"
],
CanRotate: True,
Id: 161976
},
{
Vertices: 
[
"X:  11.7087; Y: 55.5437",
"X:  11.7093; Y: 55.5438"
],
CanRotate: True,
Id: 161975
},
{
Vertices: 
[
"X:  11.7087; Y: 55.5437",
"X:  11.7085; Y: 55.5438",
"X:  11.7082; Y: 55.5438"
],
CanRotate: True,
Id: 147406
},
{
Vertices: 
[
"X:  11.7082; Y: 55.5438",
"X:  11.7080; Y: 55.5441"
],
CanRotate: True,
Id: fca31345-6d80-418d-901c-0f6c99a405cf
}
],
CanRotate: True,
Id: 77b026ad-145c-4083-a7be-85ec67069490
},
Distance: 4055.57418166185,
Weight: 0,
Features: 
[
ThinkGeo.MapSuite.Core.Feature,
ThinkGeo.MapSuite.Core.Feature,
ThinkGeo.MapSuite.Core.Feature,
ThinkGeo.MapSuite.Core.Feature,
ThinkGeo.MapSuite.Core.Feature,
ThinkGeo.MapSuite.Core.Feature,
ThinkGeo.MapSuite.Core.Feature,
ThinkGeo.MapSuite.Core.Feature,
ThinkGeo.MapSuite.Core.Feature,
ThinkGeo.MapSuite.Core.Feature,
ThinkGeo.MapSuite.Core.Feature,
ThinkGeo.MapSuite.Core.Feature,
ThinkGeo.MapSuite.Core.Feature,
ThinkGeo.MapSuite.Core.Feature,
ThinkGeo.MapSuite.Core.Feature,
ThinkGeo.MapSuite.Core.Feature,
ThinkGeo.MapSuite.Core.Feature
],
RouteSegments: 
[
{
Weight: 848.1918,
RouteSegmentType: 0,
StartPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: bdf26750-de4c-4405-9f2a-762ac5d54b34
},
StartPointAdjacentIds: 
[
98243,
617162
],
EndPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 09610b34-a2ef-4f49-af88-a8232dfd0ab4
},
EndPointAdjacentIds: 
[
98245,
465203
],
FeatureId: 98244,
DrivingDirection: Forward
},
{
Weight: 19.89538,
RouteSegmentType: 0,
StartPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 4c5b8c88-3ecc-4c1d-a36b-df9bcec1b1bf
},
StartPointAdjacentIds: 
[
98242,
600547
],
EndPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 1f50590c-1a4a-4fd3-b090-37d70228c68d
},
EndPointAdjacentIds: 
[
98244,
617162
],
FeatureId: 98243,
DrivingDirection: Forward
},
{
Weight: 56.41431,
RouteSegmentType: 0,
StartPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 545fbd79-2209-485c-a44f-5b333926ce33
},
StartPointAdjacentIds: 
[
98241,
465207
],
EndPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 8a58446e-3c66-45fb-b7f1-efb3c187ca32
},
EndPointAdjacentIds: 
[
98243,
600547
],
FeatureId: 98242,
DrivingDirection: Forward
},
{
Weight: 1652.494,
RouteSegmentType: 0,
StartPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: f850543f-07ed-495c-a82d-ba655a56dde1
},
StartPointAdjacentIds: 
[
98240,
144145
],
EndPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: a43da3a0-0089-494d-a4c8-fb81d57c86af
},
EndPointAdjacentIds: 
[
98242,
465207
],
FeatureId: 98241,
DrivingDirection: Forward
},
{
Weight: 250.0562,
RouteSegmentType: 0,
StartPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 000aa29d-6854-4f19-a9e2-5e674cad6cdb
},
StartPointAdjacentIds: 
[
98239,
161984
],
EndPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 5084767e-b3df-45c9-b126-6c70d5299a8a
},
EndPointAdjacentIds: 
[
98241,
144145
],
FeatureId: 98240,
DrivingDirection: Forward
},
{
Weight: 204.5791,
RouteSegmentType: 0,
StartPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 57d63798-7c08-4593-981a-8971564e95fb
},
StartPointAdjacentIds: 
[
161983,
333128
],
EndPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: ff7de062-dfc1-453b-b7f3-900f86cd5969
},
EndPointAdjacentIds: 
[
98239,
98240
],
FeatureId: 161984,
DrivingDirection: RightForward
},
{
Weight: 8.356613,
RouteSegmentType: 0,
StartPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 62ea1eed-02e9-456a-a267-7ad7511dfa4a
},
StartPointAdjacentIds: 
[
161982,
617044
],
EndPoint: 
{
X: 0,
Y: 0,
Z: 0,
 
CanRotate: True,
Id: 59110f48-1cff-481d-b0d9-0d3558a6325b
},
EndPointAdjacentIds: 
[
161984,
333128
],
FeatureId: 161983,
DrivingDirection: Forward
},
{
Weight: 47.82912,
RouteSegmentType: 0,
StartPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 4d5bd1aa-7720-4334-b70f-2ae9d87c2f61
},
StartPointAdjacentIds: 
[
161981,
637949
],
EndPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 1a69ce40-0aaf-447a-91b3-eb3bb7ddff07
},
EndPointAdjacentIds: 
[
161983,
617044
],
FeatureId: 161982,
DrivingDirection: Forward
},
{
Weight: 55.38148,
RouteSegmentType: 0,
StartPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 43fb8261-13d5-4e3a-a5f0-96e2a6d74df2
},
StartPointAdjacentIds: 
[
161980,
571462
],
EndPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 15c77f47-da64-48ef-abc5-3d1dbfd93644
},
EndPointAdjacentIds: 
[
161982,
637949
],
FeatureId: 161981,
DrivingDirection: Forward
},
{
Weight: 7.922089,
RouteSegmentType: 0,
StartPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 69bb7247-e038-46e3-8e3c-6874faac7098
},
StartPointAdjacentIds: 
[
161979,
637944
],
EndPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 8c377657-2a01-44d5-94d9-34925f8e89ae
},
EndPointAdjacentIds: 
[
161981,
571462
],
FeatureId: 161980,
DrivingDirection: Forward
},
{
Weight: 86.52647,
RouteSegmentType: 0,
StartPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: c756cdea-98f1-42f8-83d1-56ecfa022da3
},
StartPointAdjacentIds: 
[
161978,
571470
],
EndPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 9414e0ce-448b-48f2-b4ce-0e9107043737
},
EndPointAdjacentIds: 
[
161980,
637944
],
FeatureId: 161979,
DrivingDirection: Forward
},
{
Weight: 161.6161,
RouteSegmentType: 0,
StartPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 7fb67787-df71-4602-a9d3-8807563ac3ad
},
StartPointAdjacentIds: 
[
161977,
571466
],
EndPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: c0bb56f4-7f38-4b93-8bc6-31c7ca4ab472
},
EndPointAdjacentIds: 
[
161979,
571470
],
FeatureId: 161978,
DrivingDirection: Forward
},
{
Weight: 109.0097,
RouteSegmentType: 0,
StartPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: c97a6dde-333b-4abb-aa38-d43aeb45cbf9
},
StartPointAdjacentIds: 
[
161976,
333121
],
EndPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 03acf659-f345-44a1-b15a-7a3f735cf450
},
EndPointAdjacentIds: 
[
161978,
571466
],
FeatureId: 161977,
DrivingDirection: Forward
},
{
Weight: 16.31941,
RouteSegmentType: 0,
StartPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 8bd664a6-f54b-4fb6-8b71-7b58344ce6bb
},
StartPointAdjacentIds: 
[
161975,
177744
],
EndPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 20bc0def-4c2e-42cd-9fb1-be95af5e7dd7
},
EndPointAdjacentIds: 
[
161977,
333121
],
FeatureId: 161976,
DrivingDirection: Forward
},
{
Weight: 40.54268,
RouteSegmentType: 0,
StartPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 7da0836d-edf8-457c-9e44-8eae2227fb47
},
StartPointAdjacentIds: 
[
147405,
147406
],
EndPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 89427676-7b02-4e47-92e2-17a9ee8419cd
},
EndPointAdjacentIds: 
[
161976,
177744
],
FeatureId: 161975,
DrivingDirection: Forward
},
{
Weight: 36.42773,
RouteSegmentType: 0,
StartPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: f84dcca6-efc4-43f4-a0d6-63300ffa784b
},
StartPointAdjacentIds: 
[
147405,
161975
],
EndPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 67f24692-2044-449a-ae99-191b39e08141
},
EndPointAdjacentIds: 
[
147249,
147407
],
FeatureId: 147406,
DrivingDirection: RightForward
},
{
Weight: 454.0123,
RouteSegmentType: 0,
StartPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: 315de705-cd6e-43de-8e60-3787b7dba979
},
StartPointAdjacentIds: 
[
147406,
147407
],
EndPoint: 
{
X: 0,
Y: 0,
Z: 0,
CanRotate: True,
Id: da14830d-4423-4ba9-884c-816468152d03
},
EndPointAdjacentIds: 
[
147250,
600286
],
FeatureId: 147249,
DrivingDirection: RightForward
}
]
}
 

Hello Niels, 
  
 My apologize, it’s not Features, you should get: 
  
     routingResult.Route.Lines 
  
 then get the first line and the last line, check it’s vertices, remove the vertex which connect with second line and last but one line, then you will get what you want. 
  
 Regards, 
  
 Gary