添加属性查询工具-ArcObject-学习

时间:2024-05-14 14:16:24
【文件属性】:

文件名称:添加属性查询工具-ArcObject-学习

文件大小:5.77MB

文件格式:PPT

更新时间:2024-05-14 14:16:24

ArcObject

添加属性查询工具 1. 在窗体中添加Label和Textbox控件 2. 在Textbox的KeyPress事件中添加代码 If KeyAscii = vbKeyReturn Then ' Find the States layer Dim i As Integer Dim pFeatLyr As IFeatureLayer For i = 0 To MapControl1.LayerCount - 1 Set pFeatLyr = MapControl1.Layer(i) If pFeatLyr.Name = "states" Then ' Found it and exit loop Exit For End If Next i ' Create a string to use in the query Dim queryStr As String queryStr = "STATE_NAME = '" & Text1.Text & "'" ' Create the query filter Dim pQueryFltr As IQueryFilter Set pQueryFltr = New QueryFilter pQueryFltr.WhereClause = queryStr ' Perform the selection Dim pFeatSeln As IFeatureSelection ' QI for IFeatureSelection from the ' IFeatureLayer Set pFeatSeln = pFeatLyr pFeatSeln.SelectFeatures _ pQueryFltr, esriSelectionResultNew, False ' Get the selection set Dim pSelSet As ISelectionSet Set pSelSet = pFeatSeln.SelectionSet ' Get the cursor from the selection set Dim pFeatCursor As IFeatureCursor pSelSet.Search Nothing, True, pFeatCursor ' Assume only one feature Dim pFeature As IFeature Set pFeature = pFeatCursor.NextFeature If Not pFeature Is Nothing Then ' Get the extent of the selected feature Dim pExtent As IEnvelope Set pExtent = pFeature.Shape.Envelope ' And set the Map control's extent MapControl1.Extent = pFeature.Shape.Envelope End If End If End Sub


网友评论