07

11

selection code test

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




文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: GIS
相关日志:
评论: 1 | 引用: 0 | 查看次数: -
回复回复xiaoxue[2008-09-24 09:38 PM | del]
test1中SelectLayerByAttribute 不是类对象吧?这段代码在vba中无法运行,为什么啊?
请教下,arcmap中的select by location在arcmap中如何实现啊?
谢谢哦
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.