IProximityOperator::ReturnNearestPoint で最近接点を取得

 2016/9/1 (木)    

private void proximity()
{
    IFeatureLayer pFeatureLayer = (IFeatureLayer)axMapControl1.Map.get_Layer(0);    //対象レイヤ
    IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
 
    //検索元フィーチャの取得
    IProximityOperator pProximityOperator = (IProximityOperator)pFeatureClass.GetFeature(1).Shape;   //フィーチャのOIDを指定
     
    //検索対象フィーチャの取得
    IGeometry pGeometry = pFeatureClass.GetFeature(2).Shape;  //フィーチャのOIDを指定
    IPointCollection pPointCollection = (IPointCollection)pGeometry;
 
    double dblDistance = pProximityOperator.ReturnDistance(pGeometry); //ジオメトリ間の最短距離(端点上に頂点が無い場合も考慮)
    MessageBox.Show("最短距離:" + dblDistance.ToString());                 
    Console.WriteLine(dblDistance.ToString());
 
    IPoint pPoint = null;               //検索元フィーチャの近接点候補
    double dblGap = dblDistance * 10;   //現在判明している最短距離の近似値を取得
    ILine pLine = new LineClass();      //頂点間を結んだ近接線候補
    IPoint pFromPoint = null;           //頂点間による検索元フィーチャの近接点候補
    IPoint pToPoint = null;             //頂点間による検索先フィーチャの近接点候補
 
 
    for (int i = 0; i <= pPointCollection.PointCount -1; i++)
    {
        pPoint = pProximityOperator.ReturnNearestPoint(pPointCollection.get_Point(i), esriSegmentExtension.esriNoExtension);
         
        pLine.FromPoint = pPoint;                       //このポイントは線分上を返す場合もある
        pLine.ToPoint = pPointCollection.get_Point(i);  //このポイントはポリゴンの頂点となる
 
        //より短い近接線が見つかった場合
        if (dblGap > pLine.Length)
        {
            dblGap = pLine.Length;
            pFromPoint = pLine.FromPoint;
            pToPoint = pLine.ToPoint;
        }
    }
 
    //ポリゴンの頂点間に限定した再近接点
    pLine.FromPoint = pFromPoint;
    pLine.ToPoint = pToPoint;
    MessageBox.Show("頂点間に限定した再近接距離:" + pLine.Length.ToString());
 
}

Copyright© WINGFIELD since1981 , 2018 All Rights Reserved.