This document is archived and information here might be outdated.  Recommended version.


Set Route Properties Snippet (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference

Set Route Properties Snippet

Set route solver parameters, including settings.

[C#]
///<summary>Set route solver parameters, including settings.</summary>
/// 
///<param name="naSolver">An INASolver interface.</param>
/// 
///<returns>An INARouteSolver2 with default parameters set.</returns>
/// 
///<remarks></remarks>
public ESRI.ArcGIS.NetworkAnalyst.INARouteSolver2 SetRouteProperties(ESRI.ArcGIS.NetworkAnalyst.INASolver naSolver)
{

  // Set route solver parameters, including settings for...
  ESRI.ArcGIS.NetworkAnalyst.INARouteSolver2 naRouteSolver=(ESRI.ArcGIS.NetworkAnalyst.INARouteSolver2)naSolver;

  // ...sequencing
  naRouteSolver.FindBestSequence=false;
  naRouteSolver.PreserveFirstStop=true;
  naRouteSolver.PreserveLastStop=true;

  // ...time constraints
  naRouteSolver.UseTimeWindows=false;
  naRouteSolver.UseStartTime=false;

  // Note the default date value used by the solver is (1/1/1901 8:00:00AM). 
  // This is the earliest date that any routes can start from.
  naRouteSolver.StartTime=new System.DateTime(1901, 1, 1, 8, 0, 0);

  // ...output
  naRouteSolver.CreateTraversalResult=true;
  naRouteSolver.OutputLines=ESRI.ArcGIS.NetworkAnalyst.esriNAOutputLineType.esriNAOutputLineTrueShape;

  return naRouteSolver;

}
[Visual Basic .NET]
'''<summary>Set route solver parameters, including settings.</summary>
''' 
'''<param name="naSolver">An INASolver interface.</param>
''' 
'''<returns>An INARouteSolver2 with default parameters set.</returns>
''' 
'''<remarks></remarks>
Public Function SetRouteProperties(ByVal naSolver As ESRI.ArcGIS.NetworkAnalyst.INASolver) As ESRI.ArcGIS.NetworkAnalyst.INARouteSolver2

  ' Set route solver parameters, including settings for...
  Dim naRouteSolver As ESRI.ArcGIS.NetworkAnalyst.INARouteSolver2=CType(naSolver, ESRI.ArcGIS.NetworkAnalyst.INARouteSolver2)

  ' ...sequencing
  naRouteSolver.FindBestSequence=False
  naRouteSolver.PreserveFirstStop=True
  naRouteSolver.PreserveLastStop=True

  ' ...time constraints
  naRouteSolver.UseTimeWindows=False
  naRouteSolver.UseStartTime=False

  ' Note the default date value used by the solver is (1/1/1901 8:00:00AM). 
  ' This is the earliest date that any routes can start from.
  naRouteSolver.StartTime=New System.DateTime(1901, 1, 1, 8, 0, 0)

  ' ...output
  naRouteSolver.CreateTraversalResult=True
  naRouteSolver.OutputLines=ESRI.ArcGIS.NetworkAnalyst.esriNAOutputLineType.esriNAOutputLineTrueShape

  Return naRouteSolver

End Function

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.NetworkAnalyst
  • System