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 ...
随机推荐
- layui动态无限极菜单
ajax加jQuery实现 效果图 参考文章:https://www.wanpishe.top/detail?blogId=644aa177-9795-456a-8090-ee1264bf5d9d
- 禁止input输入空格
仅适用于PC端:$("input").attr("onKeypress","javascript:if(event.keyCode == 32)eve ...
- ST和LCA和无根树连接
#include <stdio.h> #include <iostream> #include <string.h> #include <algorithm& ...
- onvif开发实战1--总结框架搭建
Gsoap及开发框架生成: 一:gsoap下载和编译 1.下载Gsoap:地址:http://sourceforge.net/projects/gsoap2/files/gSOAP/ 2.安装: ...
- 洛谷 P1223 排队接水
洛谷 P1223 排队接水 题目描述 有n个人在一个水龙头前排队接水,假如每个人接水的时间为Ti,请编程找出这n个人排队的一种顺序,使得n个人的平均等待时间最小. 输入输出格式 输入格式: 输入文件共 ...
- Servlet 获取多个参数
<html><head> <title>First Servlet</title></head><body bgColor=" ...
- restcontroller和controller区别
http://www.cnblogs.com/softidea/p/5884772.html#undefined http://blog.csdn.net/blueheart20/article/de ...
- leetCode解题报告5道题(十)
题目一:Valid Number Validate if a given string is numeric. Some examples: "0" => true &quo ...
- 94.文件bat脚本自删除
taskkill / f / im 自删除.exedel 自删除.exedel 1.bat void main() { FILE *pf = fopen("1.bat", &quo ...
- 1.10 Python基础知识 - 序列:列表
在Python中有很多的组合数据类型,其中包括列表,元组,字符串等数据类型,这些数据类型统称为序列类型,用他们可以处理复杂的数据. 列表,是一组有序元素组合的数据结构.列表是可变的数据类型. 列表采用 ...