AE+C#:实现ArcMap中打开图层属性表后按属性选择的功能

更新时间:2024-01-27 21:42:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

AE+C#:实现ArcMap中打开图层属性表后按属性选择的功能

此文档仅按以下界面实现按属性选择的主要功能,作为初学者的尝试,代码有很多不完善的地方,在此发出来和大家交流学习。

1、从主窗口的MapControl中获取Map的各个图层

2、从ComboBox中选择图层后,在listBox1中显示该图层所有的字段

3、从listBox1选择字段并单击获取唯一值后,将该字段所有唯一值显示到listBox2中

4、双击listBox中的项会添加到下面的textBox中,单击应用后将SQL语句返回到主窗口中

1、新建窗体,设置属性如下: 属性 属性值 Name frmQueryFeat Text 按属性查询 MaximizeBox False MinimizeBox False FormBorderStyle FixedSingle

2、设置好窗体后,如上图所示在窗口上添加各类控件: 控件 Name属性 Text属性 ComboBox featCls_comboBox - ListBox field_listBox - ListBox uniqueValue_listBox - Button UniqueValue_button 获取唯一值 Button apply_button 应用 Button close_button 关闭 Button clear_button 清除 TextBox textBox1 - Label数个(用于显示提示) - - Button数个(用于添加SQL语句的=,- - <>,>,<,and ,or等)

3、添加一个类,对项目单击右键→添加→类,设置类的名称为FeatureClassInfo: ///

/// 表示要素类及其所在图层的图层名、图层索引 ///

public class FeatureClassInfo {

private int _lyrIndex; private string _lyrName;

private IFeatureClass _featCls;

public Int32 LayerIndex { get { return _lyrIndex; } } public String LayerName { get { return _lyrName; } }

public IFeatureClass FeatureClass { get { return _featCls; } }

public FeatureClassInfo(int lyrIndex,string lyrName,IFeatureClass featCls) {

this._lyrIndex = lyrIndex; this._lyrName = lyrName; this._featCls = featCls; } }

4、在frmQueryFeat窗口中输入以下代码: using System;

using System.Collections;

using System.Collections.Generic; using System.Windows.Forms; using ESRI.ArcGIS.Geodatabase;

namespace GISsys {

public partial class frmQueryFeat : Form {

private List _fInfoList = new List(); private FeatureClassInfo _fInfo = null;

public frmQueryFeat(FeatureClassInfo[] featClsesInfo) {

InitializeComponent();

foreach (var f in featClsesInfo) {

this.featCls_comboBox.Items.Add(f.LayerName); _fInfoList.Add(f); }

if (featClsesInfo.Length > 0) {

_fInfo = _fInfoList[0];

this.featCls_comboBox.SelectedIndex = 0; sql_textBox.Focus(); //_featureClass (IFeatureClass)this.featCls_comboBox.SelectedItem; } }

#region 各÷类え?函ˉ数簓

///

/// 返う?回?通?过y属?性?查é询ˉ要癮素?的?SQL语?句? ///

/// public string SQL() {

return this.sql_textBox.Text.Trim(); }

///

/// 返う?回?要癮执′行D查é询ˉ的?图?层?索÷引皔 ///

/// public int LayerIndex() {

return this.featCls_comboBox.SelectedIndex;

= }

#endregion

#region 符?号?按恪?钮¥事?件t

private void button1_Click(object sender, EventArgs e) {

sql_textBox.Text += \; }

private void button2_Click(object sender, EventArgs e) {

sql_textBox.Text += \; }

private void button3_Click(object sender, EventArgs e) {

sql_textBox.Text += \; }

private void button5_Click(object sender, EventArgs e) {

sql_textBox.Text += \; }

private void button4_Click(object sender, EventArgs e) {

sql_textBox.Text += \; }

private void button6_Click(object sender, EventArgs e) {

sql_textBox.Text += \; }

private void button7_Click(object sender, EventArgs e) {

sql_textBox.Text += \; }

private void button9_Click(object sender, EventArgs e)

{

sql_textBox.Text += \; }

private void button8_Click(object sender, EventArgs e) {

sql_textBox.Text += \; }

private void button10_Click(object sender, EventArgs e) {

sql_textBox.Text += \; }

#endregion

private void featCls_comboBox_SelectedIndexChanged(object sender, EventArgs e) {

this.field_listBox.Items.Clear();

this.uniqueValue_listBox.Items.Clear();

int index = featCls_comboBox.SelectedIndex; _fInfo = _fInfoList[index];

int flds_cnt = _fInfo.FeatureClass .Fields.FieldCount;

for (int i = 0; i < flds_cnt; i++) {

IField field = _fInfo.FeatureClass.Fields.get_Field(i); //if (field.Editable) //{

// _Valuefields.Add(new ValueField(field)); //}

field_listBox.Items.Add(field.Name); }

}

private void UniqueValue_button_Click(object sender, EventArgs e) {

int index = this.featCls_comboBox.SelectedIndex; FeatureClassInfo featClsInfo = _fInfoList[index]; ArrayList list = new ArrayList();

if (this.field_listBox.SelectedIndex != -1) {

UniqueValueClass uniqueVaueCls = new UniqueValueClass();

list = uniqueVaueCls.GetLayerUniqueFieldValueByDataStatistics( featClsInfo.FeatureClass, this.field_listBox.SelectedItem.ToString());

this.uniqueValue_listBox.Items.Clear(); foreach (var f in list) {

this.uniqueValue_listBox.Items.Add(f); } } }

private void field_DoubleClick(object sender, EventArgs e) {

sql_textBox.Text += field_listBox.SelectedItem.ToString(); }

private void uniqueValue_DoubleClick(object sender, EventArgs e) {

IField field = _fInfo.FeatureClass.Fields.get_Field(field_listBox.SelectedIndex); if (field.Type == esriFieldType.esriFieldTypeString) {

sql_textBox.Text += \+uniqueValue_listBox.SelectedItem.ToString()+\; } else {

sql_textBox.Text += uniqueValue_listBox.SelectedItem.ToString(); } }

private void clear_button_Click(object sender, EventArgs e) {

sql_textBox.Text = \; }

private void apply_button_Click(object sender, EventArgs e) {

this.DialogResult = DialogResult.OK; this.Close();

}

private void close_button_Click(object sender, EventArgs e) {

this.DialogResult = DialogResult.Cancel; this.Close(); }

} }

5、在主窗口事件中调用:

List featClsInfoList = findFeatureLayer();

if (featClsInfoList.Count > 0) {

//打洙?开a查é询ˉ窗洹?口ú frmQueryFeat queryFeatForm = new frmQueryFeat(featClsInfoList.ToArray());

if (queryFeatForm.ShowDialog() == DialogResult.OK) {

int lyrindex = queryFeatForm.LayerIndex();//要癮查é询ˉ的?图?层?

string sql = queryFeatForm.SQL();//查é询ˉ语?句?

IFeatureLayer featureLyr =

axMapControl1.Map.get_Layer(lyrindex) as IFeatureLayer;

searchSelection(sql, featureLyr);//执′行D查é询ˉ } } else {

MessageBox.Show(\缺ā?少Θ?要癮素?图?层?!?\, \提?示?\, MessageBoxButtons.OK, MessageBoxIcon.Information); } }

本文来源:https://www.bwwdw.com/article/tnnw.html

Top