IProximityOperator でポリゴンとポイントの近接点を取得

 2016/9/1 (木)    

'IProximityOperator でポリゴンとポイントの近接点の取得
Sub GetQueryNearestPoint()
     
    Dim pPoint(3) As IPoint
    Set pPoint(0) = New Point
    Set pPoint(1) = New Point
    Set pPoint(2) = New Point
    Set pPoint(3) = New Point
     
    Dim pInPoint As IPoint
    Set pInPoint = New Point
     
    Call pPoint(0).PutCoords(0, 0)
    Call pPoint(1).PutCoords(0, 100)
    Call pPoint(2).PutCoords(100, 100)
    Call pPoint(3).PutCoords(100, 0)
    Call pInPoint.PutCoords(300, 50)
     
     
    Dim pPointCollection As IPointCollection
    Set pPointCollection = New Polygon
    Call pPointCollection.AddPoint(pPoint(0))
    Call pPointCollection.AddPoint(pPoint(1))
    Call pPointCollection.AddPoint(pPoint(2))
    Call pPointCollection.AddPoint(pPoint(3))
    Call pPointCollection.AddPoint(pPoint(0))
     
     
    Dim pProximityOperator As IProximityOperator
    Set pProximityOperator = pPointCollection
     
    '近接点の取得(ReturnNearestPoint)
    Dim pNearestPoint As IPoint
    'Set pNearestPoint = pProximityOperator.ReturnNearestPoint(pInPoint, esriNoExtension)
     
    '近接点の取得(QueryNearestPoint)
    Set pNearestPoint = New Point  '事前に空の Point オブジェクトを作成
    Call pProximityOperator.QueryNearestPoint(pInPoint, esriNoExtension, pNearestPoint)
     
    Dim dblNearestDistance As Double
    dblNearestDistance = pProximityOperator.ReturnDistance(pInPoint)
     
    Debug.Print dblNearestDistance, pNearestPoint.X, pNearestPoint.Y
 
End Sub

Copyright© WINGFIELD since1981 , 2018 All Rights Reserved.