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


How to load data into a network analysis problem (ArcObjects .NET 10.5 SDK)

How to load data into a network analysis problem


Summary
This topic describes how to load data into a network analysis problem in a stand-alone application using ArcObjects.

The recommended way to load data into a network analysis problem is using the Add Locations geoprocessing tool.

In this topic


NAClassLoader

If your input data is stored in a feature class, use NAClassLoader (LoadFromAFeatureClass method). If your input is a single geometry, then add that geometry to an in-memory feature class (or an feature class stored in a geodatabase).  Then, use the following code to load your locations.
The reason the class loader is used instead of manually creating features and setting values is that the loader takes care of details that could otherwise be missed.  For example, polygon and polyline barrier features are not defined by the feature geometry, but by the values stored in the Locations field.  The class loader will populate this field correctly for you.
Pass the feature class containing the input data, the name of the destination network analysis class (NAClass), and the destination network analysis context (NAContext) as shown in the following code:
[C#]
public void LoadAnalysisObjectsByGeometry(ESRI.ArcGIS.Geodatabase.IFeatureClass
    inputFeatureClass, string naClassName, ESRI.ArcGIS.NetworkAnalyst.INAContext
    naContext)
{
    // Both Initialize and Load take a cursor from the input feature class
    ESRI.ArcGIS.Geodatabase.ICursor cursor=inputFeatureClass.Search(null, false)as
        ESRI.ArcGIS.Geodatabase.ICursor;

    // Initialize the default field mappings.
    // If you want to specify field mappings beyond the default ones, use naClassLoader.FieldMap to retrieve
    //  and edit the mappings between the input class and the naclass.
    ESRI.ArcGIS.NetworkAnalyst.INAClassLoader2 naClassLoader=new
        ESRI.ArcGIS.NetworkAnalyst.NAClassLoaderClass();
    naClassLoader.Initialize(naContext, naClassName, cursor);

    // Use ExcludeRestrictedElements and CacheRestrictedElements to prevent locations from being placed on restricted elements.
    // Some ways to restrict elements include restriction barriers and restriction attributes.
    // If you are loading barriers into barrier classes, or not loading locations (for example, seedpoints)
    //  then you should not exclude the restricted elements.  Also, if you do have barriers in your analysis problem,
    //  then you should load those first, to make sure the restricted elements are established before loading 
    //  non-barrier classes.
    ESRI.ArcGIS.NetworkAnalyst.INALocator3 naLocator3=naClassLoader.Locator as
        ESRI.ArcGIS.NetworkAnalyst.INALocator3;
    naLocator3.ExcludeRestrictedElements=true;
    naLocator3.CacheRestrictedElements(naContext);

    // After Loading is complete, the rowsIn and rowsLocated variable can be used to verify
    //  that every row from the input feature class has been loaded into the network analysis class
    int rowsIn=0;
    int rowsLocated=0;
    naClassLoader.Load(cursor, null, ref rowsIn, ref rowsLocated);
}
[VB.NET]
Public Sub LoadAnalysisObjectsByGeometry(ByVal inputFeatureClass As ESRI.ArcGIS.Geodatabase.IFeatureClass, ByVal naClassName As String, ByVal naContext As ESRI.ArcGIS.NetworkAnalyst.INAContext)
    ' Both Initialize and Load take a cursor from the input feature class
    Dim cursor As ESRI.ArcGIS.Geodatabase.ICursor=TryCast(inputFeatureClass.Search(Nothing, False), ESRI.ArcGIS.Geodatabase.ICursor)
    
    ' Initialize the default field mappings.
    ' If you want to specify field mappings beyond the default ones, use naClassLoader.FieldMap to retrieve
    ' and edit the mappings between the input class and the naclass.
    Dim naClassLoader As ESRI.ArcGIS.NetworkAnalyst.INAClassLoader2=New ESRI.ArcGIS.NetworkAnalyst.NAClassLoaderClass()
    naClassLoader.Initialize(naContext, naClassName, cursor)
    
    ' Use ExcludeRestrictedElements and CacheRestrictedElements to prevent locations from being placed on restricted elements.
    ' Some ways to restrict elements include restriction barriers and restriction attributes.
    ' If you are loading barriers into barrier classes, or not loading locations (for example, seedpoints)
    ' then you should not exclude the restricted elements. Also, if you do have barriers in your analysis problem,
    ' then you should load those first, to make sure the restricted elements are established before loading
    ' non-barrier classes.
    Dim naLocator3 As ESRI.ArcGIS.NetworkAnalyst.INALocator3=TryCast(naClassLoader.Locator, ESRI.ArcGIS.NetworkAnalyst.INALocator3)
    naLocator3.ExcludeRestrictedElements=True
    naLocator3.CacheRestrictedElements(naContext)
    
    ' After Loading is complete, the rowsIn and rowsLocated variable can be used to verify
    ' that every row from the input feature class has been loaded into the network analysis class
    Dim rowsIn As Integer=0
    Dim rowsLocated As Integer=0
    naClassLoader.Load(cursor, Nothing, rowsIn, rowsLocated)
End Sub
[C#]
public void LoadAnalysisObjectsByField(ESRI.ArcGIS.Geodatabase.ITable inputClass,
    string naClassName, ESRI.ArcGIS.NetworkAnalyst.INAContext naContext)
{
    // Both Initialize and Load take a cursor from the input class
    ESRI.ArcGIS.Geodatabase.ICursor cursor=inputClass.Search(null, false)as
        ESRI.ArcGIS.Geodatabase.ICursor;
    ESRI.ArcGIS.NetworkAnalyst.INAClassLoader2 naClassLoader=new
        ESRI.ArcGIS.NetworkAnalyst.NAClassLoaderClass();
    naClassLoader.Initialize(naContext, naClassName, cursor);

    // Store the current set of locator agents, so they can be added back later
    int agentCount=naContext.Locator.LocatorAgentCount;
    var listOfAgents=new System.Collections.Generic.List <
        ESRI.ArcGIS.NetworkAnalyst.INALocatorAgent > ();
    for (int locIndex=0; locIndex < agentCount; locIndex++)
        listOfAgents.Add(naContext.Locator.get_LocatorAgent(locIndex));

    // Remove the existing locator agents from the locator
    // This for loop is done in reverse order, because agents are being removed as the loop executes
    for (int locIndex=agentCount - 1; locIndex >= 0; locIndex--)
        naContext.Locator.RemoveLocatorAgent(locIndex);

    // Create and add a fields agent
    var fieldsAgent=new
        ESRI.ArcGIS.NetworkAnalyst.NALocatorLocationFieldsAgentClass()as
        ESRI.ArcGIS.NetworkAnalyst.INALocatorLocationFieldsAgent2;

    // Set the field names appropriately based on input data and NAClass
    var naClass=naContext.NAClasses.get_ItemByName(naClassName)as
        ESRI.ArcGIS.NetworkAnalyst.INAClass;
    var naFeatureClass=naClass as ESRI.ArcGIS.Geodatabase.IFeatureClass;

    // Check to see if the NAClass is of type NALocation or NALocationRanges
    ESRI.ArcGIS.esriSystem.UID naLocationFeatureUID=new
        ESRI.ArcGIS.esriSystem.UIDClass();
    naLocationFeatureUID.Value="esriNetworkAnalyst.NALocationFeature";
    ESRI.ArcGIS.esriSystem.UID naLocationFeatureRangesUID=new
        ESRI.ArcGIS.esriSystem.UIDClass();
    naLocationFeatureRangesUID.Value="esriNetworkAnalyst.NALocationRangesFeature";
    if (naFeatureClass.CLSID.Compare(naLocationFeatureUID))
    {
        // The field names listed below are the names used in ArcGIS Network Analyst extension classes to represent NALocations.
        //  These are also the names of fields added by the CalculateLocations geoprocessing tool
        fieldsAgent.OIDFieldName="SourceOID";
        fieldsAgent.SourceIDFieldName="SourceID";
        fieldsAgent.PositionFieldName="PosAlong";
        fieldsAgent.SideFieldName="SideOfEdge";
    }
    else if (naFeatureClass.CLSID.Compare(naLocationFeatureRangesUID))
    {
        // The location ranges input field must be of type BLOB
        fieldsAgent.LocationRangesFieldName="Locations";
        var blobField=inputClass.Fields.get_Field(inputClass.FindField
            (fieldsAgent.LocationRangesFieldName));
        if (blobField.Type !=
            ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeBlob)
        {
            System.Windows.Forms.MessageBox.Show(
                "Loading location ranges by field requires a blob field");
            return ;
        }
    }
    naContext.Locator.AddLocatorAgent(fieldsAgent as
        ESRI.ArcGIS.NetworkAnalyst.INALocatorAgent);

    // After Loading is complete, the rowsIn and rowsLocated variable can be used to verify
    //  that every row from the input feature class has been loaded into the network analysis class
    int rowsIn=0;
    int rowsLocated=0;
    naClassLoader.Load(cursor, null, ref rowsIn, ref rowsLocated);

    // Now remove the custom fields agent and add back the stored agents
    naContext.Locator.RemoveLocatorAgent(0);
    foreach (var agent in listOfAgents)
        naContext.Locator.AddLocatorAgent(agent);
}
[VB.NET]
Public Sub LoadAnalysisObjectsByField(ByVal inputClass As ESRI.ArcGIS.Geodatabase.ITable, ByVal naClassName As String, ByVal naContext As ESRI.ArcGIS.NetworkAnalyst.INAContext)
    ' Both Initialize and Load take a cursor from the input class
    Dim cursor As ESRI.ArcGIS.Geodatabase.ICursor=TryCast(inputClass.Search(Nothing, False), ESRI.ArcGIS.Geodatabase.ICursor)
    Dim naClassLoader As ESRI.ArcGIS.NetworkAnalyst.INAClassLoader2=New ESRI.ArcGIS.NetworkAnalyst.NAClassLoaderClass()
    naClassLoader.Initialize(naContext, naClassName, cursor)
    
    ' Store the current set of locator agents, so they can be added back later
    Dim agentCount As Integer=naContext.Locator.LocatorAgentCount
    Dim listOfAgents=New System.Collections.Generic.List(Of ESRI.ArcGIS.NetworkAnalyst.INALocatorAgent)()
    For locIndex As Integer=0 To agentCount - 1
        listOfAgents.Add(naContext.Locator.get_LocatorAgent(locIndex))
    Next
    
    ' Remove the existing locator agents from the locator
    ' This for loop is done in reverse order, because agents are being removed as the loop executes
    For locIndex As Integer=agentCount - 1 To 0 Step -1
        naContext.Locator.RemoveLocatorAgent(locIndex)
    Next
    
    ' Create and add a fields agent
    Dim fieldsAgent=TryCast(New ESRI.ArcGIS.NetworkAnalyst.NALocatorLocationFieldsAgentClass(), ESRI.ArcGIS.NetworkAnalyst.INALocatorLocationFieldsAgent2)
    
    ' Set the field names appropriately based on input data and NAClass
    Dim naClass=TryCast(naContext.NAClasses.get_ItemByName(naClassName), ESRI.ArcGIS.NetworkAnalyst.INAClass)
    Dim naFeatureClass=TryCast(naClass, ESRI.ArcGIS.Geodatabase.IFeatureClass)
    
    ' Check to see if the NAClass is of type NALocation or NALocationRanges
    Dim naLocationFeatureUID As ESRI.ArcGIS.esriSystem.UID=New ESRI.ArcGIS.esriSystem.UIDClass()
    naLocationFeatureUID.Value="esriNetworkAnalyst.NALocationFeature"
    Dim naLocationFeatureRangesUID As ESRI.ArcGIS.esriSystem.UID=New ESRI.ArcGIS.esriSystem.UIDClass()
    naLocationFeatureRangesUID.Value="esriNetworkAnalyst.NALocationRangesFeature"
    
    If naFeatureClass.CLSID.Compare(naLocationFeatureUID) Then
        ' The field names listed below are the names used in ArcGIS Network Analyst extension classes to represent NALocations.
        ' These are also the names of fields added by the CalculateLocations geoprocessing tool
        fieldsAgent.OIDFieldName="SourceOID"
        fieldsAgent.SourceIDFieldName="SourceID"
        fieldsAgent.PositionFieldName="PosAlong"
        fieldsAgent.SideFieldName="SideOfEdge"
    ElseIf naFeatureClass.CLSID.Compare(naLocationFeatureRangesUID) Then
        ' The location ranges input field must be of type BLOB
        fieldsAgent.LocationRangesFieldName="Locations"
        Dim blobField=inputClass.Fields.get_Field(inputClass.FindField(fieldsAgent.LocationRangesFieldName))
        If blobField.Type <> ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeBlob Then
            System.Windows.Forms.MessageBox.Show("Loading location ranges by field requires a blob field")
            Exit Sub
        End If
    End If
    
    naContext.Locator.AddLocatorAgent(TryCast(fieldsAgent, ESRI.ArcGIS.NetworkAnalyst.INALocatorAgent))
    
    ' After Loading is complete, the rowsIn and rowsLocated variable can be used to verify
    ' that every row from the input feature class has been loaded into the network analysis class
    Dim rowsIn As Integer=0
    Dim rowsLocated As Integer=0
    naClassLoader.Load(cursor, Nothing, rowsIn, rowsLocated)
    
    ' Now remove the custom fields agent and add back the stored agents
    naContext.Locator.RemoveLocatorAgent(0)
    For Each agent In listOfAgents
        naContext.Locator.AddLocatorAgent(agent)
    Next
End Sub
Note: When loading into the Stops class of a Route analysis, you must set a valid Sequence value in order for the analysis to solve correctly.

In ArcMap

If you do your loading inside of ArcMap, you need to concern yourself with undo/redo, as well as refreshing the NAWindow.  This is all covered in the code below:
[C#]
public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
    // This assumes a desktop application.
    ESRI.ArcGIS.Framework.IApplication app=m_pHookHelper.Hook as
        ESRI.ArcGIS.Framework.IApplication;
    ESRI.ArcGIS.NetworkAnalystUI.INetworkAnalystExtension naExt=
        (ESRI.ArcGIS.NetworkAnalystUI.INetworkAnalystExtension)
        app.FindExtensionByName("Network Analyst");
    ESRI.ArcGIS.NetworkAnalystUI.INAWindow naWindow=naExt.NAWindow;
    if (naWindow.ActiveAnalysis == null || naWindow.ActiveCategory == null)
    {
        System.Windows.Forms.MessageBox.Show(
            "There must be an active analysis layer and an active category");
        return ;
    }
    ESRI.ArcGIS.NetworkAnalyst.INALayer naLayer=naWindow.ActiveAnalysis;
    ESRI.ArcGIS.NetworkAnalyst.INAContext naContext=naLayer.Context;
    ESRI.ArcGIS.NetworkAnalyst.INALocator naLocator=naContext.Locator;
    ESRI.ArcGIS.Geodatabase.IFeatureClass naFeatureClass=
        (ESRI.ArcGIS.Geodatabase.IFeatureClass)naWindow.ActiveCategory.NAClass;
    var naClassDef=naFeatureClass as ESRI.ArcGIS.NetworkAnalyst.INAClassDefinition;
    if (!naClassDef.IsInput || naFeatureClass.ShapeType !=
        ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint)
    {
        System.Windows.Forms.MessageBox.Show(
            "The NAClass must be an input class of geometry type Point");
        return ;
    }
    // Gets the closeset point on the network features to where the user clicked
    ESRI.ArcGIS.ArcMapUI.IMxDocument mxDoc=(ESRI.ArcGIS.ArcMapUI.IMxDocument)
        app.Document;
    ESRI.ArcGIS.Geometry.IPoint inputPoint=mxDoc.CurrentLocation;
    // Start an edit operation (for undo/redo)
    naWindow.StartOperation(naContext);
    // Create a feature and QI to INALocationObject
    ESRI.ArcGIS.Geodatabase.IFeature feature=naFeatureClass.CreateFeature();
    ((ESRI.ArcGIS.Geodatabase.IRowSubtypes)feature).InitDefaultValues();
    // The NALocation information only needs to be set for NALocation classes
    ESRI.ArcGIS.esriSystem.UID naLocationFeatureUID=new
        ESRI.ArcGIS.esriSystem.UIDClass();
    naLocationFeatureUID.Value="esriNetworkAnalyst.NALocationFeature";
    ESRI.ArcGIS.NetworkAnalyst.INALocation naLocation=new
        ESRI.ArcGIS.NetworkAnalyst.NALocationClass();
    if (naFeatureClass.CLSID.Compare(naLocationFeatureUID))
    {
        // Returns the locator object, the point and the distance
        ESRI.ArcGIS.Geometry.IPoint queriedPoint=new
            ESRI.ArcGIS.Geometry.PointClass();
        double distanceToLocation= - 1;
        naLocator.QueryLocationByPoint(inputPoint, ref naLocation, ref queriedPoint,
            ref distanceToLocation);
        // If not located, use input point
        if (naLocation == null || !naLocation.IsLocated)
            queriedPoint=inputPoint;
        ESRI.ArcGIS.NetworkAnalyst.INALocationObject naLocationObject=
            (ESRI.ArcGIS.NetworkAnalyst.INALocationObject)feature;
        // Set the NALocation
        naLocationObject.NALocation=naLocation;
        inputPoint=queriedPoint;
    }
    // Set the Shape
    feature.Shape=inputPoint;

    // Set the name of the new analysis object.
    // If a display expression is set, then determine what the expression is and set
    //  the appropriate fields to get the name you want.
    var featureLayer=naWindow.ActiveCategory.Layer as
        ESRI.ArcGIS.Carto.IFeatureLayer;
    // If the display expression is not set, then use the display field as the name.
    // You can check the display expression via the ExpressionProperties of the
    //  IDisplayString interface of the FeatureLayer
    int displayFieldIndex=naFeatureClass.FindField(featureLayer.DisplayField);
    // Only set this display value if the display field is of type string
    if (naFeatureClass.Fields.get_Field(displayFieldIndex).Type ==
        ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString)
        feature.set_Value(displayFieldIndex, inputPoint.X.ToString() + "," +
            inputPoint.Y.ToString());
    // Set the Status Field
    int statusFieldIndex=naFeatureClass.FindField("Status");
    if (statusFieldIndex > 0)
    {
        if (naLocation.IsLocated)
            feature.set_Value(statusFieldIndex,
                ESRI.ArcGIS.NetworkAnalyst.esriNAObjectStatus.esriNAObjectStatusOK);
        else
            feature.set_Value(statusFieldIndex,
                ESRI.ArcGIS.NetworkAnalyst.esriNAObjectStatus.esriNAObjectStatusNotLocated);
    }
    // Set the sequence field (Only on stops)
    // If you wish to insert a stop somewhere in the middle of other stops, you will need to 
    //  redo the sequence values for all of the stops after the one you insert.
    int sequenceFieldIndex=naFeatureClass.FindField("Sequence");
    if (sequenceFieldIndex > 0)
        feature.set_Value(sequenceFieldIndex, ((ESRI.ArcGIS.Geodatabase.ITable)
            naFeatureClass).RowCount(null));
    // Store the geometry
    feature.Store();
    // Stop the edit operation
    naWindow.StopOperation(naContext, "Add " + naWindow.ActiveCategory.Layer.Name);
    // Refresh map
    mxDoc.ActiveView.Refresh();
}
[VB.NET]
Public Overloads Overrides Sub OnMouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Integer, ByVal Y As Integer)
' This assumes a desktop application.
Dim app As ESRI.ArcGIS.Framework.IApplication=TryCast(m_pHookHelper.Hook, ESRI.ArcGIS.Framework.IApplication)
Dim naExt As ESRI.ArcGIS.NetworkAnalystUI.INetworkAnalystExtension=DirectCast(app.FindExtensionByName("Network Analyst"), ESRI.ArcGIS.NetworkAnalystUI.INetworkAnalystExtension)
Dim naWindow As ESRI.ArcGIS.NetworkAnalystUI.INAWindow=naExt.NAWindow
If naWindow.ActiveAnalysis Is Nothing OrElse naWindow.ActiveCategory Is Nothing Then
    System.Windows.Forms.MessageBox.Show("There must be an active analysis layer and an active category")
    Exit Sub
End If

Dim naLayer As ESRI.ArcGIS.NetworkAnalyst.INALayer=naWindow.ActiveAnalysis
Dim naContext As ESRI.ArcGIS.NetworkAnalyst.INAContext=naLayer.Context
Dim naLocator As ESRI.ArcGIS.NetworkAnalyst.INALocator=naContext.Locator
Dim naFeatureClass As ESRI.ArcGIS.Geodatabase.IFeatureClass=DirectCast(naWindow.ActiveCategory.NAClass, ESRI.ArcGIS.Geodatabase.IFeatureClass)
Dim naClassDef=TryCast(naFeatureClass, ESRI.ArcGIS.NetworkAnalyst.INAClassDefinition)
If Not naClassDef.IsInput OrElse naFeatureClass.ShapeType <> ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint Then
    System.Windows.Forms.MessageBox.Show("The NAClass must be an input class of geometry type Point")
    Exit Sub
End If

' Gets the closeset point on the network features to where the user clicked
Dim mxDoc As ESRI.ArcGIS.ArcMapUI.IMxDocument=DirectCast(app.Document, ESRI.ArcGIS.ArcMapUI.IMxDocument)
Dim inputPoint As ESRI.ArcGIS.Geometry.IPoint=mxDoc.CurrentLocation

' Start an edit operation (for undo/redo)
naWindow.StartOperation(naContext)

' Create a feature and QI to INALocationObject
Dim feature As ESRI.ArcGIS.Geodatabase.IFeature=naFeatureClass.CreateFeature()
DirectCast(feature, ESRI.ArcGIS.Geodatabase.IRowSubtypes).InitDefaultValues()

' The NALocation information only needs to be set for NALocation classes
Dim naLocationFeatureUID As ESRI.ArcGIS.esriSystem.UID=New ESRI.ArcGIS.esriSystem.UIDClass()
naLocationFeatureUID.Value="esriNetworkAnalyst.NALocationFeature"
Dim naLocation As ESRI.ArcGIS.NetworkAnalyst.INALocation=New ESRI.ArcGIS.NetworkAnalyst.NALocationClass()
If naFeatureClass.CLSID.Compare(naLocationFeatureUID) Then
    ' Returns the locator object, the point and the distance
    Dim queriedPoint As ESRI.ArcGIS.Geometry.IPoint=New ESRI.ArcGIS.Geometry.PointClass()
    Dim distanceToLocation As Double=-1
    naLocator.QueryLocationByPoint(inputPoint, naLocation, queriedPoint, distanceToLocation)
    
    ' If not located, use input point
    If naLocation Is Nothing OrElse Not naLocation.IsLocated Then
        queriedPoint=inputPoint
    End If
    
    Dim naLocationObject As ESRI.ArcGIS.NetworkAnalyst.INALocationObject=DirectCast(feature, ESRI.ArcGIS.NetworkAnalyst.INALocationObject)
    
    ' Set the NALocation
    naLocationObject.NALocation=naLocation
    inputPoint=queriedPoint
End If

' Set the Shape
feature.Shape=inputPoint

' Set the name of the new analysis object.
' If a display expression is set, then determine what the expression is and set
' the appropriate fields to get the name you want.
Dim featureLayer=TryCast(naWindow.ActiveCategory.Layer, ESRI.ArcGIS.Carto.IFeatureLayer)

' If the display expression is not set, then use the display field as the name.
' You can check the display expression via the ExpressionProperties of the
' IDisplayString interface of the FeatureLayer
Dim displayFieldIndex As Integer=naFeatureClass.FindField(featureLayer.DisplayField)

' Only set this display value if the display field is of type string
If naFeatureClass.Fields.get_Field(displayFieldIndex).Type=ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString Then
    feature.set_Value(displayFieldIndex, (inputPoint.X.ToString() & ",") + inputPoint.Y.ToString())
End If

' Set the Status Field
Dim statusFieldIndex As Integer=naFeatureClass.FindField("Status")
If statusFieldIndex > 0 Then
    If naLocation.IsLocated Then
        feature.set_Value(statusFieldIndex, ESRI.ArcGIS.NetworkAnalyst.esriNAObjectStatus.esriNAObjectStatusOK)
    Else
        feature.set_Value(statusFieldIndex, ESRI.ArcGIS.NetworkAnalyst.esriNAObjectStatus.esriNAObjectStatusNotLocated)
    End If
End If

' Set the sequence field (Only on stops)
' If you wish to insert a stop somewhere in the middle of other stops, you will need to
' redo the sequence values for all of the stops after the one you insert.
Dim sequenceFieldIndex As Integer=naFeatureClass.FindField("Sequence")
If sequenceFieldIndex > 0 Then
    feature.set_Value(sequenceFieldIndex, DirectCast(naFeatureClass, ESRI.ArcGIS.Geodatabase.ITable).RowCount(Nothing))
End If

' Store the geometry
feature.Store()

' Stop the edit operation
naWindow.StopOperation(naContext, "Add " & naWindow.ActiveCategory.Layer.Name)

' Refresh map
mxDoc.ActiveView.Refresh()
End Sub


See Also:

What is ArcGIS Network Analyst extension?
About the ArcGIS Network Analyst extension Tutorial
Essential ArcGIS Network Analyst extension vocabulary
NetworkAnalyst
ArcGIS Network Analyst extension Object Model Diagram




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):

Development licensing Deployment licensing
Engine Developer Kit Engine: Network Analyst
ArcGIS Desktop Advanced: Network Analyst ArcGIS Desktop Advanced: Network Analyst
ArcGIS Desktop Standard: Network Analyst ArcGIS Desktop Standard: Network Analyst
ArcGIS Desktop Basic: Network Analyst ArcGIS Desktop Basic: Network Analyst