07
11
selection code test
作者:独木舟 日期:2008-07-11
The code of one button which will perform the function of select by attribute.
using the map that arcgis provided :world
test1:
Dim selectstr As String
selectstr = """CITY_NAME"" ='Nanchang'"
Dim gp As Geoprocessor = New Geoprocessor
''利用SelectLayerByAttribute
Dim SelectByAttribute As SelectLayerByAttribute = New SelectLayerByAttribute
SelectByAttribute.in_layer_or_view = Form1.AxMapControl1.Map.Layer(0)
SelectByAttribute.selection_type = "NEW_SelectION"
SelectByAttribute.where_clause = selectstr
gp.Execute(SelectByAttribute, Nothing)
''temp##########################
''测试搜索结果
Dim Count As Integer
If gp.MessageCount > 0 Then
For Count = 0 To gp.MessageCount - 1
MsgBox(gp.GetMessage(Count))
Next
End If
'无效的查询表达式已解决
'存在问题:1.如何通知选择结果已获取 2.如何利用此结果并高亮显示??? ''################################
test2:
Dim selectstr As String
selectstr = """CITY_NAME"" ='Nanchang'"
Dim pFeatureLayer As IFeatureLayer = Form1.AxMapControl1.Map.Layer(0)
Dim pFeatureClass As IFeatureClass
Dim pQueryFilter As IQueryFilter '查询过滤器
Dim pFeatureCursor As IFeatureCursor
pFeatureClass = pFeatureLayer.FeatureClass '从要素层获取要素类
pQueryFilter = New QueryFilter '创建一个新的查询过滤器
pQueryFilter.WhereClause = selectstr
pFeatureCursor = pFeatureClass.Search(pQueryFilter, False) '获取查询到的要素对象
Dim pFeature As IFeature '要素
pFeature = pFeatureCursor.NextFeature '获取查询结果的下一个要素
If pFeature Is Nothing Then '如果该要素不存在
MsgBox("Nothing") '提示 没有查到结果
Else
MsgBox("get") '提示 获得符合条件的要素
End If
'############## 问题 ##########
'如何获取结果数目
'######################
test3:
Dim selectstr As String
selectstr = """CITY_NAME"" ='Nanchang'"
' '###################### symbol ##############
Dim fillsymbol As ISimpleFillSymbol = New SimpleFillSymbol
Dim rgbcolor As IRgbColor = New RgbColor
rgbcolor.Red = 255
rgbcolor.Blue = 0
rgbcolor.Green = 0
fillsymbol.Color = rgbcolor
' '###############################
Dim pMap As IMap
Dim featuresel As IFeatureSelection
Dim selectset As ISelectionSet
Dim pqueryfilter As IQueryFilter = New QueryFilter
pMap = Form1.AxMapControl1.Map
featuresel = pMap.Layer(0)
pqueryfilter.WhereClause = selectstr
' perform selection
featuresel.SelectFeatures(pqueryfilter, esriSelectionResultEnum.esriSelectionResultNew, False)
featuresel.SelectionSymbol = fillsymbol
featuresel.SelectionChanged()
Form1.AxMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, Nothing, Nothing)
' report number of selected features
selectset = featuresel.SelectionSet
MsgBox("共查到符合条件的要素" & selectset.Count & "个", MsgBoxStyle.OkOnly, "查询结束")
the basic information about GIS encoding.
转自:http://hi.baidu.com/gisfaq/blog/item/82fb91c2ff1ff21a0ef47715.html
请教下,arcmap中的select by location在arcmap中如何实现啊?
谢谢哦