📄 属性查询.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 属性查询
Dim sqlfilter As String
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = TextBox1.Text + Button2.Text
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
TextBox1.Text = TextBox1.Text + Button3.Text
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
TextBox1.Text = TextBox1.Text + Button4.Text
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
TextBox1.Text = TextBox1.Text + Button5.Text
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
TextBox1.Text = TextBox1.Text + Button6.Text
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
TextBox1.Text = TextBox1.Text + ListBox1.Text
End Sub
Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged
TextBox1.Text = TextBox1.Text + ListBox2.Text
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
TextBox1.Text = TextBox1.Text + Button8.Text
End Sub
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
选择集显示.Show()
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
TextBox1.Text = TextBox1.Text + Button9.Text
End Sub
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
TextBox1.Text = TextBox1.Text + Button14.Text
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
TextBox1.Text = TextBox1.Text + Button10.Text
End Sub
Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox1.Text = TextBox1.Text + Button3.Text
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
TextBox1.Text = TextBox1.Text + Button11.Text
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
TextBox1.Text = TextBox1.Text + Button12.Text
End Sub
Private Sub Button8_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
TextBox1.Text = TextBox1.Text + Button8.Text
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
TextBox1.Text = TextBox1.Text + Button10.Text
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ComboBox1.Text = "" Then
MsgBox("必须选择一个图层")
Else
Dim pFeatLyr As IFeatureLayer
'Dim mycollection As IGeometryCollection
If ComboBox1.Text = "cities" Then
pFeatLyr = Form1.AxMapControl1.Map.Layer(0)
'mycollection = New Point
ElseIf ComboBox1.Text = "roads" Then
pFeatLyr = Form1.AxMapControl1.Map.Layer(1)
'mycollection = New Polyline
Else
pFeatLyr = Form1.AxMapControl1.Map.Layer(2)
'mycollection = New Polygon
End If
Dim pFilter As IQueryFilter
pFilter = New QueryFilter
sqlfilter = TextBox1.Text
pFilter.WhereClause = sqlfilter
Dim pFeatCursor As IFeatureCursor
pFeatCursor = pFeatLyr.Search(pFilter, True)
Dim pFeat As IFeature
pFeat = pFeatCursor.NextFeature
'''''''''''''''''''''''''.
Dim pFeatureClass As IFeatureClass
pFeatureClass = pFeatLyr.FeatureClass
Dim pDataTable As DataTable
pDataTable = New DataTable(pFeatureClass.AliasName)
Dim pDataColumn As DataColumn
Dim count As Integer
For count = 0 To pFeatureClass.Fields.FieldCount - 1
pDataColumn = New DataColumn(pFeatureClass.Fields.Field(count).Name)
pDataTable.Columns.Add(pDataColumn)
pDataColumn.Dispose()
Next count
'''''''''''''''''''''''''.
Do Until pFeat Is Nothing
If Not pFeat Is Nothing Then
Form1.AxMapControl1.DrawShape(pFeat.Shape)
'mycollection.AddGeometry(pFeat.Shape)
End If
Dim pDataRow As DataRow
pDataRow = pDataTable.NewRow
Dim count2 As Integer
For count2 = 0 To pFeatureClass.Fields.FieldCount - 1
If pFeatureClass.Fields.FindField(pFeatureClass.ShapeFieldName) = count2 Then '不懂
pDataRow(count2) = pFeatureClass.ShapeType.ToString()
Else
pDataRow(count2) = pFeat.Value(count2).ToString()
End If
Next count2
pDataTable.Rows.Add(pDataRow)
pFeat = pFeatCursor.NextFeature
Loop
Select Case ComboBox1.Text
Case "cities"
选择集显示.DataGridView1.DataSource = pDataTable
Case "roads"
选择集显示.DataGridView2.DataSource = pDataTable
Case "states"
选择集显示.DataGridView3.DataSource = pDataTable
End Select
End If
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim pFeatlayer As IFeatureLayer
If ComboBox1.Text = "cities" Then
pFeatlayer = Form1.AxMapControl1.Map.Layer(0)
ElseIf ComboBox1.Text = "roads" Then
pFeatlayer = Form1.AxMapControl1.Map.Layer(1)
Else
pFeatlayer = Form1.AxMapControl1.Map.Layer(2)
End If
Dim pFeatureCursor As IFeatureCursor
pFeatureCursor = pFeatlayer.Search(Nothing, False)
'''''''''''''''''''''''''''''''''''''''''''''''''
Dim count As Integer
Dim myFieldsname As String
ListBox1.Items.Clear()
For count = 0 To pFeatureCursor.Fields.FieldCount - 1
myFieldsname = pFeatureCursor.Fields.Field(count).Name
If myFieldsname = "Shape" Then
'do nothing
Else
ListBox1.Items.Add(myFieldsname)
End If
Next count
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If ComboBox1.Text = "" Then
MsgBox("必须选择一个图层")
Else
Dim pFeatlayer As IFeatureLayer
If ComboBox1.Text = "cities" Then
pFeatlayer = Form1.AxMapControl1.Map.Layer(0)
ElseIf ComboBox1.Text = "roads" Then
pFeatlayer = Form1.AxMapControl1.Map.Layer(1)
Else
pFeatlayer = Form1.AxMapControl1.Map.Layer(2)
End If
Dim pFeatureCursor As IFeatureCursor
pFeatureCursor = pFeatlayer.Search(Nothing, False)
Dim pFeat As IFeature
pFeat = pFeatureCursor.NextFeature
ListBox2.Items.Clear()
If ListBox1.Text = "" Then
MsgBox("必须选择一个字段")
Else
Do Until pFeat Is Nothing
Dim myFieldsname As String
myFieldsname = Convert.ToString(pFeat.Value(pFeatureCursor.Fields.FindField(ListBox1.Text)))
Dim can As Boolean
can = True
Dim count As Integer
For count = 0 To ListBox2.Items.Count - 1
If myFieldsname = ListBox2.Items.Item(count).ToString() Then
can = False
End If
Next count
If can = True Then
ListBox2.Items.Add(myFieldsname)
End If
pFeat = pFeatureCursor.NextFeature
Loop
Dim count2 As Integer
For count2 = 0 To ListBox2.Items.Count - 1
If Not IsNumeric(ListBox2.Items.Item(count2)) Then
ListBox2.Items.Item(count2) = "'" + ListBox2.Items.Item(count2) + "'"
End If
Next count2
End If
End If
End Sub
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
TextBox1.Clear()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -