图层属性操作(一)
加载MXD地图后,添加2个Combox,其中comboBoxLayer用于显示地图Layer,comboBoxField用于显示图层字段。一个Listbox,用于获得字段的值。
获得地图Layer的函数代码:
获得字段函数代码:
获得字段全部属性值函数代码:
函数返回了属性值的个数,并将属性值添加到ListBox。其中第一个参数是comboBoxLayer中当前选中图层,第二个参数为comboBoxField当前选中字段,第三个参数为需要显示属性值的Listbox。
这样就可以获得了类似于ArcMap中属性表查询中获得字段全部属性值(Get Unique Value)的功能,为后面的属性查询奠定基础。
属性查询可以通过IQueryFilter接口实现,日后在贴
获得地图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 }
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 }
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 }
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接口实现,日后在贴
posted on 2008-06-07 21:05 duckweeds 阅读(1715) 评论(3) 编辑 收藏 举报