YouTube | Facebook | X(Twitter) | RSS

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

2016/9/1 (木)

//クリックしたポイント
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
  • この記事を書いた人

羽田 康祐

伊達と酔狂のGISエンジニア。GIS上級技術者、Esri認定インストラクター、CompTIA CTT+ Classroom Trainer、潜水士、PADIダイブマスター、四アマ。WordPress は 2.1 からのユーザーで歴だけは長い。 代表著書『"地図リテラシー入門―地図の正しい読み方・描き方がわかる』 GIS を使った自己紹介はこちら。ESRIジャパン(株)所属、元青山学院大学非常勤講師を兼務。日本地図学会第31期常任委員。発言は個人の見解です。

-プログラミング, ArcGIS
-, ,