ThinkGeo.com    |     Blog    |     Wiki    |     Support

Routing failing

Is there a way to figure out why a route fails? All I get back from RoutingEngine.GetRoute is a RoutingResult with nothing in it. I’d like to figure out why it might be failing, but need more information. 

Hi Clay,



I think there are some reasons, I just list them as following:



1. The searching range is out of the routing files, as we know the routing engine works based on the routing files: *.rtg, routable file(*.shp).
2. The searching radius is too small to find out the routes, and you can change the searching radius: routingEngine.SearchRadiusInMeters = xx.
3. The GeographyUnit property of routing engine is incorrect.
4. The start point and end point are far away from the road. The following code shows how to select the closest start point.


routingFeatureLayer.Open();
Collection<Feature> nearestFeatures = routingFeatureLayer.FeatureSource.GetFeaturesNearestTo(clickedMouseWorldPoint, mapControl.MapUnit, 1, new string[] { roadColumnName });
routingFeatureLayer.Close();
var selectFeature = nearestFeatures[0];
LineBaseShape line = selectFeature.GetShape() as LineBaseShape;
PointShape point = line.GetClosestPointTo(clickedMouseWorldPoint, mapControl.MapUnit);
routingLayer.StartPoint = point; //Set StartPoint or EndPoint here.




Please let me know if you have any questions.



Thanks,
Peter

I’ve already got it set to the closest point on the road, and the routing does work when the start point is at a different point. I checked the routable shapefile and it includes this road. I changed the SearchRadius to 100 and still nothing. What I need is something to tell me where it fails at. Do the streets not connect, is there a speed limit missing, what is causing it to find nothing. If I could see the step by step of what streets it is trying to route down, I could troubleshoot it myself. Is there a way I can get to that information?

Hi Clay, 
  
 We provider a MapSuiteRoutingExplorer tools which in the [InstallerPath]\ThinkGeo\Map Suite 9.0\Map Suite Routing\Current Version\Managed Assemblies, please try using the tools to find the route based on your files. If it still doesn’t find any routes, please attach a sample here, so that we can find out the reason. 
  
 Thanks, 
 Peter

In fact, code that returns nearest point on road should look like this :



    Private Function GetNearistRoadPointFrom(ByVal pRawPoint As PointShape) As PointShape
        routingEngine.FeatureSource.Open()
        Dim nearestFeatures = routingEngine.FeatureSource.GetFeaturesNearestTo(pRawPoint, Map1.MapUnit, 1, New List(Of String)().AsEnumerable())
        routingEngine.FeatureSource.Close()
        Dim pointOnRoad As PointShape = nearestFeatures(0).GetShape().GetClosestPointTo(pRawPoint, Map1.MapUnit)
        Return pointOnRoad
    End Function


This works like a charm, you can easily test in on map. But it does not solve my problem :|.

Hi Dragan, 
  
 It looks this is your first post in our forum, so I am not very sure about your question, could you please describe more detail about your problem? 
  
 Regards, 
  
 Don

My problem is pretty similar to Clay’s : routing method does not execute well, and I can get no info about the problem. In my case it also throws exception, but it is usually a System.NullReferenceException  which does not tell me anything about actual problem.



For example, now I have following stack trace

       at 0BM=.DxU=.ExU=(Feature lineFeature)
       at 0BM=.DxU=.HBQ=(RoutingResultsType routingResultsType, Collection`1 roads, RoutingSource routingSource, FeatureSource featureSource, GeographyUnit geographyUnit, DistanceUnit distanceUnit)
       at ThinkGeo.MapSuite.Routing.RoutingEngine.AxU=(Object args)
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)



but I can not conclude anything from it. Meanwhile I have realized that most common scenario for such problem is when some of points are outside of territory covered by shp file. 

I would also like to see custom exception instance (some RoutingException or PointNotCoveredException for example) which could tell me more about problem. For example - coordinates of problematic point.



Hi Dragan, 
  
 It it’s a common exception and it thrown from the function GetLineShapeFromBaseShape in class RoutingHelper. It’s a simple function so I think that’s maybe the input feature invalid. 
  
 But the information is not enough for solve that because I hadn’t reproduced that by use some outside points, so could you please paste your test code with a very simple test data? You can directly modify our HowDoISample, so we can easily work for that. 
  
 Regards, 
  
 Don

Today I am dealing with different exception : 

 

System.NullReferenceException occurred 

HResult=-2147467261 

Message=Object reference not set to an instance of an object. 

Source=MapSuiteRouting 

StackTrace: 

at 0BM=.XhQ=.CxQ=() 

at 0BM=.VBQ=.IxQ=() 

at 0BM=.VBQ=.HhQ=() 

at 0BM=.VBQ=.GetRouteCore(RoutingSource routingSource, String startFeatureId, String endFeatureId) 

at ThinkGeo.MapSuite.Routing.RoutingAlgorithm.GetRoute(RoutingSource routingSource, String startFeatureId, String endFeatureId) 

at ThinkGeo.MapSuite.Routing.RoutingEngine.ChU=(RoutingResult[,] routeMatrix, String endFeatureId, IEnumerable`1 stopFeatureIds, Int32 iterations) 

at ThinkGeo.MapSuite.Routing.RoutingEngine.GetRouteCoreWithPoints(PointShape startPoint, PointShape endPoint, IEnumerable`1 stops, Int32 iterations) 

at ThinkGeo.MapSuite.Routing.RoutingEngine.GetRoute(PointShape startPoint, IEnumerable`1 stops, Int32 iterations) 

at VB_Samples.TravelingSalesmansProblem.Map1_Click(Object sender, MapClickedEventArgs e) in E:\servSuite\routing optimisation\TSP sample\WebEdition_HowDoI_VB\Samples\ScreenWorldCoordinates\TravelingSalesmansProblem.aspx.vb:line 138 

InnerException:  

 (innerException is obviously empty)



and it’s not about outside points this time. Here is my source code : 





<%@ Page Language=“vb” AutoEventWireup=“true” CodeBehind=“TravelingSalesmansProblem.aspx.vb”
Inherits=“VB_Samples.TravelingSalesmansProblem” %>



<%@ Register Assembly=“WebEdition” Namespace=“ThinkGeo.MapSuite.WebEdition” TagPrefix=“cc1” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=“w3.org/1999/xhtml”>
<head id=“Head1” runat=“server”>
<link href="~/theme/default/samplepic/style.css" rel=“stylesheet” type=“text/css” />
<title>Traveling Salesman problem</title>
</head>
<body>
<form> id=“form1” runat=“server”>
<asp:ScriptManager ID=“Map1_Script” runat=“server”>
</asp:ScriptManager>
<asp:UpdatePanel ID=“UpdatePanel1” runat=“server”>
<ContentTemplate>
<cc1:Map ID=“Map1” runat=“server” Width=“100%” Height=“100%” OnClick=“Map1_Click”>
</cc1:Map>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>






Imports Microsoft.VisualBasic
Imports System
Imports ThinkGeo.MapSuite.Core
Imports ThinkGeo.MapSuite.WebEdition
Imports ThinkGeo.MapSuite.Routing
Partial Public Class TravelingSalesmansProblem : Inherits System.Web.UI.Page
Private Shared routingEngine As RoutingEngine
Private Shared routingSource As RoutingSource
Private ITERATIONS_COUNT As Integer = 50
Private DATA_FILE_NAME As String
Private DATA_PATH As String
Public Shared LEFT, TOP, RIGHT, BOTTOM As Double
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If (Not Page.IsPostBack) Then
PrepareRoutingData()
RenderMap()
End If
End Sub
Private Sub PrepareDataForAustin()
DATA_FILE_NAME = “Austinstreets"
DATA_PATH = “…\App_Data&#34;
LEFT = -97.7319606824951
TOP = 30.2922109418945
RIGHT = -97.7002033277588
BOTTOM = 30.269551640136
End Sub
Private Sub PrepareRoutingData()
PrepareDataForAustin()
Dim path As String = Server.MapPath(DATA_PATH & DATA_FILE_NAME & “.shp”)
Dim featureSource As ShapeFileFeatureSource = New ShapeFileFeatureSource(path)
Dim rtgPath = Server.MapPath(DATA_PATH & DATA_FILE_NAME & “.rtg”)
routingSource = New RtgRoutingSource(rtgPath)
routingEngine = New RoutingEngine(routingSource, New AStarRoutingAlgorithm(), featureSource)
End Sub
Private Sub RenderMap()
Map1.MapUnit = GeographyUnit.DecimalDegree
Map1.MapBackground.BackgroundBrush = New GeoSolidBrush(GeoColor.FromHtml(”#E5E3DF”))
Map1.CurrentExtent = New RectangleShape(LEFT, TOP, RIGHT, BOTTOM)
Dim worldMapKitOverlay As WorldMapKitWmsWebOverlay = New WorldMapKitWmsWebOverlay()
Map1.BackgroundOverlay = worldMapKitOverlay
Dim routingLayer As RoutingLayer = New RoutingLayer()
Map1.DynamicOverlay.Layers.Add(“RoutingLayer”, routingLayer)
AddFixedStopPointsTo(routingLayer)
routingLayer.ShowStopOrder = False
Dim routingExtentLayer As InMemoryFeatureLayer = New InMemoryFeatureLayer()
routingExtentLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = New AreaStyle(New GeoPen(GeoColor.SimpleColors.Green))
routingExtentLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
routingExtentLayer.InternalFeatures.Add(New Feature(New RectangleShape(LEFT, TOP, RIGHT, BOTTOM)))
Map1.DynamicOverlay.Layers.Add(“RoutingExtentLayer”, routingExtentLayer)
End Sub
Private Sub AddFixedStopPointsTo(ByRef pRoutingLayer As RoutingLayer)
pRoutingLayer.StartPoint = GetNearistRoadPointFrom(New PointShape(-97.7186, 30.2899))
pRoutingLayer.StopPoints.Add(GetNearistRoadPointFrom(New PointShape(-97.7556, 30.2225)))
pRoutingLayer.StopPoints.Add(GetNearistRoadPointFrom(New PointShape(-97.7756, 30.3425)))
pRoutingLayer.StopPoints.Add(GetNearistRoadPointFrom(New PointShape(-97.8056, 30.2735)))
End Sub
Private Function GetNearistRoadPointFrom(ByVal pRawPoint As PointShape) As PointShape
routingEngine.FeatureSource.Open()
Dim nearestFeatures = routingEngine.FeatureSource.GetFeaturesNearestTo(pRawPoint, Map1.MapUnit, 1, New List(Of String)().AsEnumerable())
routingEngine.FeatureSource.Close()
Dim pointOnRoad As PointShape = nearestFeatures(0).GetShape().GetClosestPointTo(pRawPoint, Map1.MapUnit)
Return pointOnRoad
End Function
Protected Sub Map1_Click(ByVal sender As Object, ByVal e As MapClickedEventArgs)
Dim routingLayer As RoutingLayer = Map1.DynamicOverlay.Layers(“RoutingLayer”) ‘As RoutingLayer
Dim watch As Stopwatch = New Stopwatch()
watch.Start()
Dim routingResult As RoutingResult = routingEngine.GetRoute(routingLayer.StartPoint, routingLayer.StopPoints, ITERATIONS_COUNT)
watch.Stop()
’ Render the route
routingLayer.Routes.Clear()
routingLayer.Routes.Add(routingResult.Route)
routingLayer.StopPoints.Clear()
’ Show the visit sequence
For Each stopp As PointShape In routingResult.OrderedStops
routingLayer.StopPoints.Add(stopp)
Next
routingLayer.ShowStopOrder = True
Map1.DynamicOverlay.Redraw()
End Sub
End Class






Thanks.

Sorry. My previous comment is a mess, and forum does not allow me to edit or delete it. Gonna try it again :



Today I am dealing with different exception : 



System.NullReferenceException occurred 
HResult=-2147467261 
Message=Object reference not set to an instance of an object. 
Source=MapSuiteRouting 
StackTrace: 
at 0BM=.XhQ=.CxQ=() 
at 0BM=.VBQ=.IxQ=() 
at 0BM=.VBQ=.HhQ=() 
at 0BM=.VBQ=.GetRouteCore(RoutingSource routingSource, String startFeatureId, String endFeatureId) 
at ThinkGeo.MapSuite.Routing.RoutingAlgorithm.GetRoute(RoutingSource routingSource, String startFeatureId, String endFeatureId) 
at ThinkGeo.MapSuite.Routing.RoutingEngine.ChU=(RoutingResult[,] routeMatrix, String endFeatureId, IEnumerable`1 stopFeatureIds, Int32 iterations) 
at ThinkGeo.MapSuite.Routing.RoutingEngine.GetRouteCoreWithPoints(PointShape startPoint, PointShape endPoint, IEnumerable`1 stops, Int32 iterations) 
at ThinkGeo.MapSuite.Routing.RoutingEngine.GetRoute(PointShape startPoint, IEnumerable`1 stops, Int32 iterations) 
at VB_Samples.TravelingSalesmansProblem.Map1_Click(Object sender, MapClickedEventArgs e) in E:\servSuite\routing optimisation\TSP sample\WebEdition_HowDoI_VB\Samples\ScreenWorldCoordinates\TravelingSalesmansProblem.aspx.vb:line 138
InnerException: 




(innerException is obviously empty)



and it’s not about outside points this time. Here is my source code : 



Imports Microsoft.VisualBasic
Imports System
Imports ThinkGeo.MapSuite.Core
Imports ThinkGeo.MapSuite.WebEdition
Imports ThinkGeo.MapSuite.Routing



Partial Public Class TravelingSalesmansProblem : Inherits System.Web.UI.Page
    Private Shared routingEngine As RoutingEngine
    Private Shared routingSource As RoutingSource
    Private pointsView As DataView



    Private ITERATIONS_COUNT As Integer = 50



    Private DATA_FILE_NAME As String
    Private DATA_PATH As String
    Public Shared LEFT, TOP, RIGHT, BOTTOM As Double



    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If (Not Page.IsPostBack) Then
            PrepareRoutingData()
            RenderMap()
        End If
    End Sub



    Private Sub PrepareDataForAustin()
        DATA_FILE_NAME = “Austinstreets”
        DATA_PATH = “…\App_Data&#34;
        LEFT = -97.7319606824951
        TOP = 30.2922109418945
        RIGHT = -97.7002033277588
        BOTTOM = 30.269551640136
    End Sub
    Private Sub PrepareRoutingData()
        PrepareDataForAustin()
        Dim path As String = Server.MapPath(DATA_PATH & DATA_FILE_NAME & “.shp”)
        Dim featureSource As ShapeFileFeatureSource = New ShapeFileFeatureSource(path)
        Dim rtgPath = Server.MapPath(DATA_PATH & DATA_FILE_NAME & “.rtg”)
        routingSource = New RtgRoutingSource(rtgPath)
        routingEngine = New RoutingEngine(routingSource, New AStarRoutingAlgorithm(), featureSource)
    End Sub



    Private Sub RenderMap()
        Map1.MapUnit = GeographyUnit.DecimalDegree
        Map1.MapBackground.BackgroundBrush = New GeoSolidBrush(GeoColor.FromHtml(”#E5E3DF"))
        Map1.CurrentExtent = New RectangleShape(LEFT, TOP, RIGHT, BOTTOM)



        Dim worldMapKitOverlay As WorldMapKitWmsWebOverlay = New WorldMapKitWmsWebOverlay()
        Map1.BackgroundOverlay = worldMapKitOverlay



        Dim routingLayer As RoutingLayer = New RoutingLayer()
        Map1.DynamicOverlay.Layers.Add(“RoutingLayer”, routingLayer)
        AddFixedStopPointsTo(routingLayer)
        routingLayer.ShowStopOrder = False



        Dim routingExtentLayer As InMemoryFeatureLayer = New InMemoryFeatureLayer()
        routingExtentLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = New AreaStyle(New GeoPen(GeoColor.SimpleColors.Green))
        routingExtentLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
        routingExtentLayer.InternalFeatures.Add(New Feature(New RectangleShape(LEFT, TOP, RIGHT, BOTTOM)))



        Map1.DynamicOverlay.Layers.Add(“RoutingExtentLayer”, routingExtentLayer)
    End Sub



    Private Sub AddFixedStopPointsTo(ByRef pRoutingLayer As RoutingLayer)
        pRoutingLayer.StartPoint = GetNearistRoadPointFrom(New PointShape(-97.7186, 30.2899))



        pRoutingLayer.StopPoints.Add(GetNearistRoadPointFrom(New PointShape(-97.7556, 30.2225)))
        pRoutingLayer.StopPoints.Add(GetNearistRoadPointFrom(New PointShape(-97.7756, 30.3425)))
        pRoutingLayer.StopPoints.Add(GetNearistRoadPointFrom(New PointShape(-97.8056, 30.2735)))
    End Sub
    Private Function GetNearistRoadPointFrom(ByVal pRawPoint As PointShape) As PointShape
        routingEngine.FeatureSource.Open()
        Dim nearestFeatures = routingEngine.FeatureSource.GetFeaturesNearestTo(pRawPoint, Map1.MapUnit, 1, New List(Of String)().AsEnumerable())
        routingEngine.FeatureSource.Close()
        Dim pointOnRoad As PointShape = nearestFeatures(0).GetShape().GetClosestPointTo(pRawPoint, Map1.MapUnit)
        Return pointOnRoad
    End Function



    Protected Sub Map1_Click(ByVal sender As Object, ByVal e As MapClickedEventArgs)
        Dim routingLayer As RoutingLayer = Map1.DynamicOverlay.Layers(“RoutingLayer”) 'As RoutingLayer



        Dim watch As Stopwatch = New Stopwatch()
        watch.Start()
        Dim routingResult As RoutingResult = routingEngine.GetRoute(routingLayer.StartPoint, routingLayer.StopPoints, ITERATIONS_COUNT)
        watch.Stop()



        ’ Render the route  
        routingLayer.Routes.Clear()
        routingLayer.Routes.Add(routingResult.Route)



        routingLayer.StopPoints.Clear()
        ’ Show the visit sequence  
        For Each stopp As PointShape In routingResult.OrderedStops
            routingLayer.StopPoints.Add(stopp)
        Next
        routingLayer.ShowStopOrder = True
        Map1.DynamicOverlay.Redraw()
    End Sub
End Class





Hi Dragan, 
  
 Thanks for your code, I reproduced that succeed.  
  
 And found the reason should be the routing between StartPoint and StopPoints[0] cannot be routing succeed. 
  
 I tested that like this: 
 Dim routingResult As RoutingResult = routingEngine.GetRoute(routingLayer.StartPoint, routingLayer.StopPoints(0))   // Cannot routing succeed 
 Dim routingResult As RoutingResult = routingEngine.GetRoute(routingLayer.StartPoint, routingLayer.StopPoints(1))   // Succeed 
 Dim routingResult As RoutingResult = routingEngine.GetRoute(routingLayer.StartPoint, routingLayer.StopPoints(2))   // Succeed 
  
 So when I commented this line in function AddFixedStopPointsTo like this: 
 'pRoutingLayer.StopPoints.Add(GetNearistRoadPointFrom(New PointShape(-97.7556, 30.2225))) 
  
 I get a result. 
  
 I am not sure whether it’s an issue, but I will let our developer know this and any update I will let you know. 
  
 Regards, 
  
 Don