📄 邻近点查询.vb
字号:
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Controls
Imports ESRI.ArcGIS.Display
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Output
Imports ESRI.ArcGIS.SystemUI
Public Class 邻近点查询
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim pFeatLyr0 As IFeatureLayer
Dim pFeatLyr1 As IFeatureLayer
Dim pFeatLyr2 As IFeatureLayer
pFeatLyr0 = Form1.AxMapControl1.Map.Layer(0)
pFeatLyr1 = Form1.AxMapControl1.Map.Layer(1)
pFeatLyr2 = Form1.AxMapControl1.Map.Layer(2)
Dim pFeatureSel As IFeatureSelection
If ComboBox1.Text = "roads" Then
pFeatureSel = pFeatLyr1
Else
pFeatureSel = pFeatLyr2
End If
Dim pSelectionSet As ISelectionSet
pSelectionSet = pFeatureSel.SelectionSet
Dim pFeatureCursor As IFeatureCursor
pSelectionSet.Search(Nothing, False, pFeatureCursor)
If pSelectionSet.Count > 1 Then
MsgBox("框选不得超过两个要素")
Else
Dim pFeature As IFeature
pFeature = pFeatureCursor.NextFeature
'''''''''''''''''''''''''''''''
Dim pPoint As IPoint
pPoint = New Point
pPoint.PutCoords(Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text))
If Not pFeature Is Nothing Then
Dim pProximityOper As IProximityOperator
pProximityOper = pFeature.Shape
Dim pNearestPoint As IPoint
pNearestPoint = New Point
pProximityOper.QueryNearestPoint(pPoint, esriSegmentExtension.esriNoExtension, pNearestPoint)
Form1.AxMapControl1.DrawShape(pPoint)
Label4.Text = Convert.ToString(pProximityOper.ReturnDistance(pPoint))
Form1.AxMapControl1.DrawShape(pNearestPoint)
End If
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim pFeatLyr0 As IFeatureLayer
Dim pFeatLyr1 As IFeatureLayer
Dim pFeatLyr2 As IFeatureLayer
pFeatLyr0 = Form1.AxMapControl1.Map.Layer(0)
pFeatLyr1 = Form1.AxMapControl1.Map.Layer(1)
pFeatLyr2 = Form1.AxMapControl1.Map.Layer(2)
Dim pFeatureSel As IFeatureSelection
If ComboBox1.Text = "roads" Then
pFeatureSel = pFeatLyr1
Else
pFeatureSel = pFeatLyr2
End If
Dim pSelectionSet As ISelectionSet
pSelectionSet = pFeatureSel.SelectionSet
Dim pFeatureCursor As IFeatureCursor
pSelectionSet.Search(Nothing, False, pFeatureCursor)
If pSelectionSet.Count > 1 Then
MsgBox("框选不得超过两个要素")
Else
Dim pFeature As IFeature
pFeature = pFeatureCursor.NextFeature
'''''''''''''''''''''''''''''''
Dim pPoint As IPoint
pPoint = New Point
Dim pFeatureSel2 As IFeatureSelection
pFeatureSel2 = pFeatLyr0
Dim pSelectionSet2 As ISelectionSet
pSelectionSet2 = pFeatureSel2.SelectionSet
Dim pFeatureCursor2 As IFeatureCursor
pSelectionSet2.Search(Nothing, False, pFeatureCursor2)
Dim pFeature2 As IFeature
pFeature2 = pFeatureCursor2.NextFeature
If pSelectionSet2.Count > 1 Then
MsgBox("框选不得超过两个要素")
Else
pPoint = pFeature2.Shape
End If
If Not pFeature Is Nothing Then
Dim pProximityOper As IProximityOperator
pProximityOper = pFeature.Shape
Dim pNearestPoint As IPoint
pNearestPoint = New Point
pProximityOper.QueryNearestPoint(pPoint, esriSegmentExtension.esriNoExtension, pNearestPoint)
Form1.AxMapControl1.DrawShape(pPoint)
MsgBox(pProximityOper.ReturnDistance(pPoint))
Form1.AxMapControl1.DrawShape(pNearestPoint)
End If
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -