Greetings,
I have:
I've come across 2two options, both of which I'm having issues with.
I couldn't figure out how to get the coloring right on the code below...
Thanks so much,
DR
Private Sub NHD_Prep_Click()
'Set general variables
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap
'Set variables for the line layer of interest
Dim pNhdLayer As ILayer
Set pNhdLayer = pMap.Layer(0)
Dim pNhdFLayer As IFeatureLayer
Set pNhdFLayer = pNhdLayer
Dim pNhdFClass As IFeatureClass
Set pNhdFClass = pNhdFLayer.FeatureClass
Dim pNhdFeatureIndex As IFeatureIndex
Set pNhdFeatureIndex = New FeatureIndex
Set pNhdFeatureIndex.FeatureClass = pNhdFClass
Dim pNhdIndexQuery As IIndexQuery2
Set pNhdIndexQuery = pNhdFeatureIndex
'Set variables for the point layer of interest
Dim pLayer As ILayer
Set pLayer = pMap.Layer(1)
Dim pFLayer As IFeatureLayer
Set pFLayer = pLayer
Dim pFClass As IFeatureClass
Set pFClass = pFLayer.FeatureClass
'Set number variables
Dim nearReachFID As Long
Dim distance As Double
Dim strReach As String
Dim dblmeas As Double
'Check to make sure the layer of interest is on top
If pMxDoc.FocusMap.Layer(0).Name <> "NHD Flowline" Then
MsgBox "Please place NHD Flowline on the top spot of the TOC..."
Exit Sub
End If
'Start Cursor on point layer features
Dim pFCursor As IFeatureCursor
Set pFCursor = pFClass.Search(Nothing, True)
Dim pFeature As IFeature
Set pFeature = pFCursor.NextFeature
Do Until pFeature Is Nothing
'Use nearest point method to find the line FID and distance to it
Dim pPointFeature As IPoint
Set pPointFeature = pFeature.Shape
pNhdIndexQuery.NearestFeature pPointFeature, nearReachFID, distance
MsgBox "This is the " & pFeature.Value(pFeature.Fields.FindField("Name")) & " feature. " _
& "The distance from this point to the nearest line, " & nearReachFID & ", is " & distance
Set pFeature = pFCursor.NextFeature
Loop
End Sub
End Sub