Dim pNhdIndexQuery As IIndexQuery2
Dim pEnvelope As IEnvelope Set pEnvelope = New Envelope pNhdFeatureIndex.Index Nothing, pEnvelope
Set pNhdIndexQuery = pNhdFeatureIndex
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
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.