Arc Engine二次开发——弹窗进行属性查询
在Arcmap中使用Sapefile格式的矢量数据时,经常会用到其属性查询的功能,弹出窗体然后用户鼠标点击或手动输入查询条件,进而查询到感兴趣的要素。在AE二次开发中也经常需要这个功能,于是在此记录整个开发过程。
首先当然是需要构建一个Visual C# Windows窗体应用程序,然后添加axMapControl等控件,这些过程不再赘述。
然后新建一个名为FormQueryAttr.cs的窗体,用于属性查询时弹出,其界面设置为如下:

其中要素为:一个ComboBox(cboLayer);两个ListBox(listBoxField和listBoxValue);一个GroupBox;一个TextBox(textBoxSql)
21个Button,表达式所需的19个button的名称如下:
btnequal、btnunequal、btnis、btnlike、btnmore、btnless、btnmoe、btnloe、btnor、btnnull、btnnot、btnand、btnin、btnunderline、btnpercent、btncharacter、btnbetween、btnspace、btnempty
点击查看代码,添加以下变量并在构造函数中添加以下语句:
//地图数据
private AxMapControl mMapControl;
//选中的图层
private IFeatureLayer mFeatureLayer;
//根据所选择的图层查询得到的特征类
private IFeatureClass pFeatureClass = null; public FormQueryAttr(AxMapControl mapControl)
{
InitializeComponent();
this.mMapControl = mapControl;
}
接着回到程序主界面,添加属性查询的Button按钮,在其点击响应函数中添加如下代码:
//属性查询
private void barButtonItem13_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
FormQueryAttr formqueryattr = new FormQueryAttr(this.axMapControl1);
formqueryattr.Show();
}
至此,程序运行且用户点击“属性查询”按钮时,会初始化FormQueryAttr.cs窗体,将整个axMapControl作为参数传入,并显示窗体。
然后再回到FormQueryAttr.cs窗体的代码中,做以下更改:
在其Load函数中为cboLayer添加所有图层名称,代码如下:
private void FormQueryAttr_Load(object sender, EventArgs e)
{
//MapControl中没有图层时返回
if (this.mMapControl.LayerCount <= )
return;
//获取MapControl中的全部图层名称,并加入ComboBox
ILayer pLayer;
//图层名称
string strLayerName;
for (int i = ; i < this.mMapControl.LayerCount; i++)
{
pLayer = this.mMapControl.get_Layer(i);
strLayerName = pLayer.Name;
//图层名称加入cboLayer
this.cboLayer.Items.Add(strLayerName);
}
//默认显示第一个选项
this.cboLayer.SelectedIndex = ;
}
为cboLayer添加SelectedIndexChanged响应事件,其中代码如下:
private void cboLayer_SelectedIndexChanged(object sender, EventArgs e)
{
this.listBoxField.Items.Clear();
//获取cboLayer中选中的图层
mFeatureLayer = mMapControl.get_Layer(cboLayer.SelectedIndex) as IFeatureLayer;
pFeatureClass = mFeatureLayer.FeatureClass;
string strFldName;
for (int i = ; i < pFeatureClass.Fields.FieldCount; i++)
{
strFldName = pFeatureClass.Fields.get_Field(i).Name;
this.listBoxField.Items.Add(strFldName);
}
this.listBoxField.SelectedIndex = ;
this.label8.Text = mFeatureLayer.Name;
}
为listBoxField添加SelectedIndexChanged和DoubleClick响应事件,其中代码如下:
private void listBoxField_SelectedIndexChanged(object sender, EventArgs e)
{
string sFieldName = listBoxField.Text;
listBoxValue.Items.Clear();
int iFieldIndex = ;
IField pField = null;
IFeatureCursor pFeatCursor = pFeatureClass.Search(null, true);
IFeature pFeat = pFeatCursor.NextFeature();
iFieldIndex = pFeatureClass.FindField(sFieldName);
pField = pFeatureClass.Fields.get_Field(iFieldIndex);
while (pFeat != null)
{
listBoxValue.Items.Add(pFeat.get_Value(iFieldIndex));
pFeat = pFeatCursor.NextFeature();
} }
private void listBoxField_DoubleClick(object sender, EventArgs e)
{
textBoxSql.SelectedText = listBoxField.SelectedItem.ToString() + " ";
}
为listBoxValue添加DoubleClick响应事件,其中代码如下:
private void listBoxValue_DoubleClick(object sender, EventArgs e)
{
textBoxSql.SelectedText = listBoxValue.SelectedItem.ToString() + " ";
}
然后对“表达式”中的按钮添加对应的点击响应函数,具体代码如下:
private void btnequal_Click(object sender, EventArgs e)
{
textBoxSql.SelectedText = "= ";
} private void btnis_Click(object sender, EventArgs e)
{
textBoxSql.SelectedText = "is ";
} private void btncharacter_Click(object sender, EventArgs e)
{
textBoxSql.SelectedText = "'' ";
} private void btnempty_Click(object sender, EventArgs e)
{
this.textBoxSql.Text = "";
} private void btnunequal_Click(object sender, EventArgs e)
{
textBoxSql.SelectedText = "!= ";
} private void btnlike_Click(object sender, EventArgs e)
{
textBoxSql.SelectedText = "like ";
} private void btnmore_Click(object sender, EventArgs e)
{
textBoxSql.SelectedText = "> ";
} private void btnmoe_Click(object sender, EventArgs e)
{
textBoxSql.SelectedText = ">= ";
} private void btnloe_Click(object sender, EventArgs e)
{
textBoxSql.SelectedText = "<= ";
} private void btnor_Click(object sender, EventArgs e)
{
textBoxSql.SelectedText = " or ";
} private void btnnull_Click(object sender, EventArgs e)
{
textBoxSql.SelectedText = "Null ";
} private void btnless_Click(object sender, EventArgs e)
{
textBoxSql.SelectedText = "< ";
} private void btnnot_Click(object sender, EventArgs e)
{
textBoxSql.SelectedText = " Not ";
} private void btnand_Click(object sender, EventArgs e)
{
textBoxSql.SelectedText = " And ";
} private void btnin_Click(object sender, EventArgs e)
{
textBoxSql.SelectedText = " In ";
} private void btnunderline_Click(object sender, EventArgs e)
{
textBoxSql.SelectedText = "_";
} private void btnpercent_Click(object sender, EventArgs e)
{
textBoxSql.SelectedText = "% ";
} private void btnbetween_Click(object sender, EventArgs e)
{
textBoxSql.SelectedText = " Between ";
} private void btnspace_Click(object sender, EventArgs e)
{
textBoxSql.SelectedText = " ";
}
最后对按钮“查找”和“取消”添加点击响应函数,代码如下:
private void button1_Click(object sender, EventArgs e)
{
try
{
mMapControl.Map.ClearSelection(); //清除上次查询结果
IActiveView pActiveView = mMapControl.Map as IActiveView;
//pQueryFilter的实例化
IQueryFilter pQueryFilter = new QueryFilterClass();
//设置查询过滤条件
pQueryFilter.WhereClause = textBoxSql.Text;
//search的参数第一个为过滤条件,第二个为是否重复执行
IFeatureCursor pFeatureCursor = mFeatureLayer.Search(pQueryFilter, false);
//获取查询到的要素
IFeature pFeature = pFeatureCursor.NextFeature();
//判断是否获取到要素
while (pFeature != null)
{
mMapControl.Map.SelectFeature(mFeatureLayer, pFeature); //选择要素
pFeature = pFeatureCursor.NextFeature();
}
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
pActiveView.Refresh();//刷新图层
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
} } private void button2_Click(object sender, EventArgs e)
{
this.Hide();
}
到此为止,所有属性查询的工作已经完成,使用效果如下图所示:


如果需要清除所选要素,则添加按钮,并在其点击响应函数中添加如下代码即可:
//清空查询
private void barButtonItem14_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
axMapControl1.Map.ClearSelection();
axMapControl1.Refresh();
}
Arc Engine二次开发——弹窗进行属性查询的更多相关文章
- 基于Java的Arc Engine二次开发的环境的配置
1.软件准备 ArcGIS for Desktop 10.2, Arc engine, jdk-7u60-windows-i586,Eclipse Mar2 2.软件的安装 2.1 ArcGIS fo ...
- 【UG二次开发】创建、查询、编辑成型特征的函数
创建成型特征函数UF_MODL_create_boss 通过设置凸台的参数建立凸台特征UF_MODL_create_rect_pad 通过设置矩形凸垫的参数建立矩形凸垫特征UF_MODL_create ...
- 【读书笔记】《基于UG NX系统的二次开发》笔记
我有几本二次开发的书,但是从头到尾读下来的却没有几本.有时候遇到困难发帖求助,好不容易得到答案.后来却发现在书上的前几章就有详细介绍.读书笔记不仅是一种记录,更是一种督促自己读书的方法.还有一个原因是 ...
- SVN二次开发——让SVN、TSVN(TortoiseSVN)支持windows的访问控制模型、NTFS ADS(可选数据流、NTFS的安全属性)
SVN二次开发 ——让SVN.TSVN(TortoiseSVN)支持windows的访问控制模型.NTFS ADS (可选数据流.NTFS的安全属性) SVN secondary developmen ...
- AE二次开发中几个功能速成归纳(符号设计器、创建要素、图形编辑、属性表编辑、缓冲区分析)
/* * 实习课上讲进阶功能所用文档,因为赶时间从网上抄抄改改,凑合能用,记录一下以备个人后用. * * ----------------------------------------------- ...
- Qt+QGIS二次开发:自定义类实现查询矢量数据的属性字段值(图查属性)
在GIS领域,有两种重要的查询操作,图查属性和属性查图. 本文主要介绍如何在QGIS中通过从QgsMapToolIdentify中派生自定义类实现查询矢量数据的属性字段值(图查属性). 重点参考资料: ...
- ArcGIS Engine开发之属性查询
属性查询即基于空间数据的属性数据的查询,通过用户提交SQL语言中的where语句定义的查询条件,对属性数据进行搜索,从而得到查询结果的操作. 相关的类与接口 与属性查询功能相关的类主要有QureyFi ...
- [ArcEngine二次开发]为Feature的属性赋值
在创建FeatureClass之后,需要为FeatureClass添加Features,在为Feature的字段赋值时,代码大致如下: 在这里赋值的时候,出现了一个错误: The operation ...
- WeCenter二次开发教程(一):熟悉模板结构
<1>程序文件目录介绍: app – 应用目录 models – 模型目录 plugins – 插件目录 static – 静态文件 system – 系统目录 views – 模板目录 ...
随机推荐
- realsense SDK编译 debug
1>------ 已启动全部重新生成: 项目: ZERO_CHECK, 配置: Debug x64 ------1> Checking Build System1> CMake do ...
- 用easymock来mock数据
昨天学习微信小程序了解了一个模拟数据的工具EasyMock,一早到公司就使用试试. 1.创建项目: 创建好如下所示: 2.创建接口: 点击右下角+号按钮即可. 操作栏依次是:预览,编辑,链接,更多操作 ...
- mac 下mongo的启动和关闭以及启动问题解决
原文地址:https://www.cnblogs.com/leinov/p/7341139.html mac 下mongo的启动和关闭以及启动问题解决 mongo的安装在这:http://www.cn ...
- 【ARM-Linux开发】ctrl-xxx的对应的signal含义
ctrl-c 发送 SIGINT 信号给前台进程组中的所有进程.常用于终止正在运行的程序.ctrl-z 发送 SIGTSTP 信号给前台进程组中的所有进程,常用于挂起一个进程.ctrl-d 不是发送信 ...
- samtools获取uniq reads
参考地址: https://www.biostars.org/p/56246/ -q INT only include reads with mapping quality >= INT [0] ...
- [bzoj5483][Usaco2018 Dec]Balance Beam_凸包_概率期望
bzoj5483 Usaco2018Dec Balance Beam 题目链接:https://lydsy.com/JudgeOnline/problem.php?id=5483 数据范围:略. 题解 ...
- .NET开发的一些积累
ASP.NET项目开发一些琐碎的积累 1.过滤危险的字符串,诸如“=”.“>”等可能会诸如数据库的危险字符串,我看过很多人做的网页仅仅进行客户端脚本验证是不够的.必须在服务器段的后台代码里面也进 ...
- LeetCode 896. 单调数列(Monotonic Array)
896. 单调数列 896. Monotonic Array 题目描述 如果数组是单调递增或单调递减的,那么它是单调的. 如果对于所有 i<=j,A[i]<=A[j],那么数组 A 是单调 ...
- EFCore 调试远程SqlServer数据库提示信号灯超时时间已到
背景 最近在使用EFCore去连接阿里云上面的数据库进行开发的时候,当自己在Debug模式下总是提示下面的报错信息,然后找了好久都没有解决,报错信息如下: an exception has been ...
- win10改装win7
参考链接: https://jingyan.baidu.com/article/3ea51489d0f3c852e61bba01.html 1. 制作win7 U盘启动盘 2. 设置BIOS 1:OS ...