C#+AE实现类似IDentify功能及对高亮显示相关接口的总结
kenika 原文C#+AE实现类似IDentify功能及对高亮显示相关接口的总结
ArcMap中的Identify功能是有目的查看要素(Feature)属性信息经常使用的工具。ArcMap中的Identify功能有以下几个特征:
第一, 鼠标点击具有“穿透力”,可以同时对多个图层的要素实现选择;
第二, 同一图层可以选择多个要素;
第三, 被选中要素并不高亮显示,而是以绿色闪烁一次;
第四, 所有选中要素列于弹出的信息窗口中。
今天用C#和AE也试着写了一个类似于Identify功能的工具,有如下要求:
第一, 鼠标具有“穿透力”,可以同时对多个图层进行选择(点选);
第二, 每一图层最多只能选中一个要素,这与ArcMap中不同;
第三, 被选中要素需要高亮显示,而不是闪烁一次,也与ArcMap不同;
第四, 按下工具后,在地图上单击弹出属性信息窗口,再次单击,仍有该窗口显示属性信息,即不可打开多个属性信息窗口。

private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEvent e)
{
if(this.blnIsIdentifyEnable)
{
//如果查询比较频繁,此类变量可以设置成类级别
IFeatureLayer pFL;
IFeatureSelection pFeatureSelection;
IEnvelope pEnv;
IGeometry pGeometry;
ISpatialFilter pSpatialFilter;
ISelectionSet pSelectionSet;
IEnumIDs pEnumIDs;
IFeature pFeature;
// ImageList imageList = new ImageList();
// imageList. //用于查询的矩形(相当于点的缓冲区,这样比生成缓冲区节省资源),
//envelope的大小根据实际情况设定,以方便使用为准
pEnv = new EnvelopeClass();
pEnv.PutCoords(e.mapX-,e.mapY-,e.mapX+,e.mapY+);
pGeometry = pEnv as IGeometry;
pSpatialFilter = new SpatialFilterClass();
pSpatialFilter.Geometry = pGeometry;
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; //运用singleton模式设计窗体,只允许存在一个ShowAttributeTable实例
ShowAttributeTable frmShowAttribute = ShowAttributeTable.CreateForm();
frmShowAttribute.Show();
frmShowAttribute.AttributeTreeView.Nodes.Clear();//首先清除上次结果
frmShowAttribute.AttributeTreeView.ShowLines = true;
frmShowAttribute.AttributeTreeView.ShowPlusMinus = true; TreeNode rootNode = new TreeNode();
rootNode.Text = "属性信息";
// rootNode.ImageIndex Font font = new Font("黑体",);
rootNode.NodeFont = font;
//添加根节点“属性信息”
frmShowAttribute.AttributeTreeView.Nodes.Add(rootNode); //没有必要将地图上的高亮选择清除,因为下面对每个图层的选择都用esriSelectionResultNew,会自动清除上次的高亮显示,
//而不同图层之间的高亮选择不会有任何影响,因为IFeatureSelection接口的一切属性和方法都是针对一个图层
// this.axMapControl1.Map.ClearSelection();
for(int i=;i<this.axMapControl1.LayerCount;i++)
{
pFL = this.axMapControl1.get_Layer(i) as IFeatureLayer;
if(pFL.Visible && pFL.Selectable)
{
pFeatureSelection = pFL as IFeatureSelection;
//选择之前先清除,这是个好习惯(除非是用Add方式)
pFeatureSelection.Clear();
pFeatureSelection.SelectFeatures(pSpatialFilter,esriSelectionResultEnum.esriSelectionResultNew,true);
pSelectionSet = pFeatureSelection.SelectionSet;
//如果选择集内有Feature
if(pSelectionSet.Count>)
{
//构建图层节点并添加到根节点
TreeNode layerNameNode = new TreeNode();
layerNameNode.ForeColor = Color.Green;
layerNameNode.Text = "图层名:" + pFL.Name; rootNode.Nodes.Add(layerNameNode); //通过pEnumIDs获得该SelectionSet中的Feature的id值,再用FeatureClass.GetFeature()方法获得该Feature对象
//这里为了学习新接口而使用了IEnumIDs,为了获得SelectionSet中的Feature,可以使用其Search()方法
//获得ICursor,再使用循环获得Feature,如下注释选定行
// pSelectionSet.Search(null,false,out pCursor);
// pRow = pCursor.NextRow();
// if(pRow!=null)
// {
// }
pEnumIDs = pSelectionSet.IDs;
long id = pEnumIDs.Next();
while(id!=-)
{
pFeature = pFL.FeatureClass.GetFeature((int)id);
for(int j=;j<pFeature.Fields.FieldCount;j++)
{
if(j!=)
{
//构建字段值节点并添加到图层节点下
TreeNode fieldInfoNode = new TreeNode();
fieldInfoNode.Text = pFeature.Fields.get_Field(j).Name + ": " + pFeature.get_Value(j).ToString();
layerNameNode.Nodes.Add(fieldInfoNode);
}
//如果是shape字段就显示GeometryType
else
{
TreeNode fieldInfoNode = new TreeNode();
fieldInfoNode.Text = pFeature.Fields.get_Field(j).Name + ": " + pFeature.Shape.GeometryType.ToString();
layerNameNode.Nodes.Add(fieldInfoNode);
}
frmShowAttribute.AttributeTreeView.ExpandAll();
} id = pEnumIDs.Next();
}
} }
} }
属性信息窗体ShowAttributeTable的设计的关键代码:
public class ShowAttributeTable : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.TreeView treeView1;
public TreeView AttributeTreeView//设置treeView1的属性
{
get{return this.treeView1;}
set{this.treeView1 = value;}
}
private static ShowAttributeTable frm;
public static ShowAttributeTable CreateForm()
{
if(frm==null)
frm = new ShowAttributeTable();
return frm;
}
private ShowAttributeTable()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.treeView1 = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// treeView1
//
this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeView1.ImageIndex = -;
this.treeView1.Location = new System.Drawing.Point(, );
this.treeView1.Name = "treeView1";
this.treeView1.SelectedImageIndex = -;
this.treeView1.Size = new System.Drawing.Size(, );
this.treeView1.TabIndex = ;
//
// ShowAttributeTable
//
this.AutoScaleBaseSize = new System.Drawing.Size(, );
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.treeView1);
this.Name = "ShowAttributeTable";
this.Text = "属性信息";
this.TopMost = true;
this.Closed += new System.EventHandler(this.ShowAttributeTable_Closed);
this.ResumeLayout(false);
}
#endregion
private void ShowAttributeTable_Closed(object sender, System.EventArgs e)
{
frm = null;
}
}
IEnumFeatureSetup pEnumFeatureSetup = this.axMapControl1.Map.FeatureSelection as IEnumFeatureSetup;
pEnumFeatureSetup.AllFields = true;
IEnumFeature pEnumFeature = pEnumFeatureSetup as IEnumFeature;
IFeature pFeature = pEnumFeature.Next();
while(pFeature!=null)
{
MessageBox.Show(pFeature.get_value().toString());
pFeature = pEnumFeature.Next();
}
C#+AE实现类似IDentify功能及对高亮显示相关接口的总结的更多相关文章
- 扩展 delphi 泛型 以实现类似lambda功能 , C#中的any count first last 等扩展方法
扩展 delphi 泛型 以实现类似lambda功能 , C#中的any count first last 等扩展方法 在C#中对泛型的扩展,输入参数是泛型本身的内容,返回值则是bool.基于这一点, ...
- 用setTimeout实现与setInteval类似的功能
用setTimeout实现与setInteval类似的功能,代码如下: (function(){ var self = arguments.callee; //获取函数本身 count++; if ( ...
- 【转载】ASP.NET以Post方式抓取远程网页内容类似爬虫功能
使用HttpWebRequest等Http相关类,可以在应用程序中或者网站中模拟浏览器发送Post请求,在请求带入相应的Post参数值,而后请求回远程网页信息.实现这一功能也很简单,主要是依靠Http ...
- 在vue项目中使用codemirror插件实现代码编辑器功能(代码高亮显示及自动提示
在vue项目中使用codemirror插件实现代码编辑器功能(代码高亮显示及自动提示) 1.使用npm安装依赖 npm install --save codemirror; 2.在页面中放入如下代码 ...
- NVR硬件录像机web无插件播放方案功能实现之相关接口注意事项说明
该篇博文主要用来说明EasyNVR硬件录像回放版本的相关接口说明和调用的demo: 方便用户的二次开发和集成. 软件根目录会包含接口文档的,因此,本文主要是对一些特定接口的说明和接口实现功能的讲解以及 ...
- 使用Typescript重构axios(二十一)——请求取消功能:添加axios.isCancel接口
0. 系列文章 1.使用Typescript重构axios(一)--写在最前面 2.使用Typescript重构axios(二)--项目起手,跑通流程 3.使用Typescript重构axios(三) ...
- asp.net + Jquery 实现类似Gridview功能 (一)
不知不觉2015年就过去一半了,由于过年前后公司人员陆续离职(这个...),项目忙不过来,从过年来上班就一直在忙,最近项目终于告一段落,开始步入正轨(不用天天赶项目了).所以最近才有时间写这个东西,可 ...
- Python不同电脑之间传输文件实现类似scp功能不输密码
SCP vs SFTP 通过paramiko还可以传输文件,如何通过paramiko在计算机之间传输文件,通过阅读官方文档,发现有如下两种方式: sftp = paramiko.SFTPClient. ...
- c++ 连接两个字符串实现代码 实现类似strcat功能(转)
想实现strcat功能,直接网上找一个. 第一种: #include "stdafx.h" #include<iostream> using namespace std ...
随机推荐
- linux6.0系统如何安装portmap
因为在6.0的系统里,portmap已经改名了.在Redhat或CentOS5中可以使用 service portmap start启动服务,然后在启动nfs服务,实现挂载. 6里面可是试试 serv ...
- 一起talk C栗子吧(第三十四回:C语言实例--巧用溢出计算最值)
各位看官们.大家好,上一回中咱们说的是巧用移位的样例,这一回咱们说的样例是:巧用溢出计算最值. 闲话休提,言归正转.让我们一起talk C栗子吧! 大家都知道,程序中的变量都有一个取值范围,这个范围也 ...
- STL_算法_查找算法(search、find_end)
C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) search //从左往右找第一个符合条件的子区间 全部容器适用 find_end //从右往左找 ...
- A. Keyboard Codeforces Round #271(div2)
A. Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- 有关cascade的结构体
/* internal cascade classifier */ typedef struct CvCascadeHaarClassifier { CV_INT_HAAR_CLASSIFIER_FI ...
- activity 接回返回值
activity 接回返回值 今天做订单列表显示 点击某一项显示订单详细信息,在详细activity中用户可以选择取消订单(未支付的状态下)当用户取消订单后订单列表也要改变状态,原来最初做法是所加载绑 ...
- Django快速搭建博客
准备工作: 1.Python 2.Django 3.Git 安装Python: 官网下载 安装Django: #安装最新版本的Django $ pip install django #或者指定安装版本 ...
- 安装Mysql最新版本mysql-5.7.10-winx64出现的几个问题解决
电脑是64位的安装不了Windows (x86, 32-bit),Mysql installer MSI ,然后下载了Windows (x86, 32-bit), ZIP Archive 这种是免安装 ...
- 洛谷 P2873 [USACO07DEC]泥水坑Mud Puddles
P2873 [USACO07DEC]泥水坑Mud Puddles 题目描述 Farmer John is leaving his house promptly at 6 AM for his dail ...
- 如何让Apache不显示服务器信息
如何让Apache不显示服务器信息 Apache的默认配置是会显示服务器信息的,比如访问一个服务器上不存在的页面,Apache会返回"Not Found"的错误,这个错误页面的最下 ...