ネットワーク解析レイヤにネットワークロケーションを設定する方法

//クリックしたポイント
IPoint pPoint = new PointClass();
pPoint.X = e.mapX;
pPoint.Y = e.mapY;

//NALayer
INALayer pNALayer = (INALayer)axMapControl1.Map.get_Layer(0);

//Stop FeatureClass
IFeatureLayer pFeatureLayer = (IFeatureLayer)pNALayer.get_LayerByNAClassName("Stops");
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;

INALocator pNALocator = pNALayer.Context.Locator;

//出力用
IPoint pOutPoint = new PointClass();
double dblDisToLoc = 99999;


//Gets the closeset point on the network features, returns the locator object, the point and the distance
INALocation pNALocation = (INALocation)new NALocationClass();
pNALocator.QueryLocationByPoint(pPoint,ref pNALocation,ref pOutPoint,ref dblDisToLoc);

if(pOutPoint == null)
{
    pOutPoint = pPoint;
}

int iNameField = pFeatureClass.FindField("Name");
int iStatusField = pFeatureClass.FindField("Status");
int iSeqField = pFeatureClass.FindField("Sequence");

IFeature pFeature = pFeatureClass.CreateFeature();
INALocationObject pNALocationObject = (INALocationObject)pFeature;
pNALocationObject.NALocation = pNALocation;


pFeature.Shape = pOutPoint;         //Point
pFeature.set_Value(iNameField, pOutPoint.X + "," + pOutPoint.Y) ;   //Name

//Status
if (pNALocation.IsLocated)
{
    pFeature.set_Value(iStatusField, esriNAObjectStatus.esriNAObjectStatusOK) ;
}
Else
{
    pFeature.set_Value(iStatusField, esriNAObjectStatus.esriNAObjectStatusElementNotLocated) ;
}

//Sequence
if (iSeqField > 0)
{
    ITable pTable = (ITable)pFeatureClass;
    pFeature.set_Value(iSeqField, pTable.RowCount(null)) ;
}

pFeature.Store();


//■Creating NALocationFeatures 
//ms-help://ESRI.EDNv9.2J/esriNetworkAnalyst/html/Creating_NALocationFeatures.htm
Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)
    
    Dim pMxApplication As IMxApplication
    Set pMxApplication = Application
    
    Dim pPoint As IPoint
    Set pPoint = pMxApplication.Display.DisplayTransformation.ToMapPoint(x, y)
    
    
    Dim pMxDocument As IMxDocument
    Set pMxDocument = ThisDocument
    
    Dim pNALayer As INALayer
    Set pNALayer = pMxDocument.FocusMap.Layer(0)
    
    Dim pFeatureLayer As IFeatureLayer
    Set pFeatureLayer = pNALayer.LayerByNAClassName("Facilities")
    
    Dim pFeatureClass As IFeatureClass
    Set pFeatureClass = pFeatureLayer.FeatureClass
    
    
    Dim pNALocator As INALocator
    Set pNALocator = pNALayer.Context.Locator

    'Gets the closeset point on the network features, returns the locator object, the point and the distance
    Dim pNALocation As INALocation
    Set pNALocation = New NALocation
    
    Dim dblDisToLoc  As Double
    Dim pOutPoint       As IPoint

    pNALocator.QueryLocationByPoint pPoint, pNALocation, pOutPoint, dblDisToLoc
    
    'If not located, use input point
    If pOutPoint Is Nothing Then
      Set pOutPoint = pPoint
    End If


    Dim pFeature As IFeature
    Set pFeature = pFeatureClass.CreateFeature
    
    Dim pNALocationObject As INALocationObject
    Set pNALocationObject = pFeature
    pNALocationObject.NALocation = pNALocation


    Set pFeature.Shape = pOutPoint
    pFeature.Value(pFeature.Fields.FindField("Name")) = pOutPoint.x & "," & pOutPoint.y
    
    pFeature.Store
    
    pMxDocument.ActiveView.Refresh
    
End Sub