图层属性操作(一)

加载MXD地图后,添加2个Combox,其中 comboBoxLayer用于显示地图Layer, comboBoxField用于显示图层字段。一个Listbox,用于获得字段的值。

获得地图Layer的函数代码:
 1           // 加载Layer函数
 2           private   void  AddLayerToCombox(ComboBox comboxLayer)
 3          {
 4               int  LyrCount  =  axMapControl1.LayerCount;
 5               for  ( int  i  =   0 ; i  <=  LyrCount  -   1 ; i ++ )
 6              {
 7                  comboBoxLayer.Items.Add(axMapControl1.get_Layer(i).Name);
 8                   // 亦或 comboBoxLayer.Items.Insert(i, axMapControl1.get_Layer(i).Name);
 9              }
10          }

获得字段函数代码:
 1           private   void  AddFieldToCombox(ComboBox ComboxLayer,ComboBox ComboxField)
 2          {
 3               if  (comboBoxLayer.Items.Count  ==   0 return ;
 4               else
 5              {
 6                  IFeatureLayer pFeatureLayer = axMapControl1.get_Layer(comboBoxLayer.SelectedIndex)  as  IFeatureLayer; // 或者通过名称来定位到图层
 7                  IFeatureClass pFeatureClass  =  pFeatureLayer.FeatureClass;
 8                   int  FieldCount  =  pFeatureClass.Fields.FieldCount;
 9                   for  ( int  i  =   0 ; i  <=  FieldCount  -   1 ;i ++  )
10                  {
11                      IField pField  =  pFeatureClass.Fields.get_Field(i); // 或者将IFeatureLayer转化为 ILayerFields类,进行字段查询
12                      comboBoxField.Items.Add(pField.Name);
13                  }
14              }
15          }

获得字段全部属性值函数代码:
 1           private   int  FindFieldValue(IFeatureLayer pFeatureLayer, string  pFieldName,ListBox ListBox)
 2          {
 3               int  FieldCount = 0 ;
 4              IFeatureClass pFeatureClass  =  pFeatureLayer.FeatureClass;
 5              IFeatureCursor pFeatureCursor  =  pFeatureClass.Search( null , true );
 6              IFeature pFeature  =  pFeatureCursor.NextFeature();
 7               int  index  =  pFeatureClass.FindField(pFieldName);
 8             
 9               while (pFeature != null )
10              {
11                   string  strValue  =  pFeature.get_Value(index).ToString();
12                  ListBox.Items.Add(strValue);
13                  pFeature  =  pFeatureCursor.NextFeature();
14              }
15              FieldCount = ListBox.Items.Count;
16               return  FieldCount;
17          }

函数返回了属性值的个数,并将属性值添加到ListBox。其中第一个参数是 comboBoxLayer中当前选中图层,第二个参数为 comboBoxField当前选中字段,第三个参数为需要显示属性值的Listbox。
这样就可以获得了类似于ArcMap中属性表查询中获得字段全部属性值(Get Unique Value)的功能,为后面的属性查询奠定基础。
属性查询可以通过 IQueryFilter接口实现,日后在贴

转载于:https://www.cnblogs.com/secenes/archive/2008/06/07/1215743.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值