helenak

distance between two features (point and line)

Discussion created by helenak on Jul 30, 2010
Hello,

I would like to measure the distances between a group of grid centroids to the coastlines of islands and landmasses
(origin geographic coordinate sys: WGS 84,
currently converted to projection coordinate sys: Behrmann)

Kirk's code was found but seems to be suitable for point-point distance.
Please kindly advise if modification is possible for the current need.
Thanks.



code
kkeywords twopointprojection
Option Explicit
Const MILESPERMETER = 0.000621371192
Sub Test()

    ' use a two point equidistant projection with points
    ' based on the middle left & middle right of the dataset's
    ' extent
   
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    Dim pFLayer As IFeatureLayer
    Set pFLayer = pMxDoc.FocusMap.Layer(0)
   
    Dim pGDS As IGeoDataset
    Set pGDS = pFLayer.FeatureClass
   
    Dim pSRF As ISpatialReferenceFactory2
    Set pSRF = New SpatialReferenceEnvironment
    Dim pPCS As IProjectedCoordinateSystem
   
    Set pPCS = pSRF.CreateProjectedCoordinateSystem(esriSRProjCS_World_TwoPointEquidistant)
    With pGDS.Extent
        pPCS.LatitudeOf1st = (.LowerLeft.Y + .UpperRight.Y) / 2#
        pPCS.LongitudeOf1st = .LowerLeft.X
        pPCS.LatitudeOf2nd = (.LowerLeft.Y + .UpperRight.Y) / 2#
        pPCS.LongitudeOf2nd = .UpperRight.X
    End With
   
    Dim pFCur As IFeatureCursor
    Set pFCur = pFLayer.FeatureClass.Search(Nothing, False)
    Dim pFeat As IFeature
    Set pFeat = pFCur.NextFeature
    Do Until pFeat Is Nothing
        Dim pPolyline As IPolyline
        Set pPolyline = pFeat.ShapeCopy
        pPolyline.Project pPCS
        Dim dMeters As Double
        dMeters = pPolyline.Length * pPCS.CoordinateUnit.MetersPerUnit
        Debug.Print dMeters * MILESPERMETER & " miles long"
        Set pFeat = pFCur.NextFeature
    Loop
End Sub


Kirk Kuykendall
AmberGIS Programming Services & Sales
Now Answering questions at:
http://stackoverflow.com/questions/tagged/arcobjects

Outcomes