AO Identify地图交互
转自supernever文章 Identify
1、框选要素高亮显示
private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
IGeometry pGeo = axMapControl1.TrackRectangle();
ISpatialFilter pSpatialFilter = new SpatialFilterClass();
pSpatialFilter.Geometry = pGeo;
pSpatialFilter.GeometryField = "SHAPE";
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
IArray geoArray = new ArrayClass();
IMap pMap = axMapControl1.Map;
for (int i = 0; i < pMap.LayerCount; i++)
{
IFeatureLayer pFeatureLayer = pMap.get_Layer(i) as IFeatureLayer;
if(pFeatureLayer.Visible!=true)
continue;
IFeatureCursor pFeatureCursor = pFeatureLayer.Search(pSpatialFilter, false);
IFeature pFeature = pFeatureCursor.NextFeature();
while (pFeature != null)
{
geoArray.Add(pFeature);
pFeature = pFeatureCursor.NextFeature();
}
}
FlashAndIdentify(geoArray);
}
/// <summary>
/// 对所选择要素集进行高亮显示并打开属性查询窗口
/// </summary>
/// <param name="inArray">所选择的要素集</param>
private void FlashAndIdentify(IArray inArray)
{
try
{
if (inArray == null)
return;
HookHelperClass hookHelper = new HookHelperClass();
hookHelper.Hook = axMapControl1.Object;
IHookActions hookAction = (IHookActions)hookHelper;
hookAction.DoActionOnMultiple(inArray, esriHookActions.esriHookActionsFlash);
frmIdentify newFrm = frmIdentify.CreatIdentify((IHookHelper)hookHelper, inArray);
newFrm.Show();
newFrm.ShowProperty(inArray);
}
catch (Exception exc) { MessageBox.Show(exc.Message); }
}
/// <summary>
/// 打开Identify对话框,并显示所选择的要素集
/// </summary>
/// <param name="array">要素集</param>
public void ShowProperty(IArray array)
{
tvFeature.Nodes.Clear();
lvProperty.Items.Clear();
int geoCount = array.Count;
if (geoCount > 0)
{
toolStripStatusLabel1.Text = "共选择" + geoCount + "条记录";
for (int count = 0; count < geoCount; count++)
{
IFeature pFeature = array.get_Element(count) as IFeature;
IFields pFields = pFeature.Fields;
int FieldIndex = pFields.FindField("OBJECTID");
TreeNode newNode = new TreeNode(pFeature.get_Value(FieldIndex).ToString());
tvFeature.Nodes.Add(newNode);
}
IFeature pF = array.get_Element(0) as IFeature;
listview = IdentifyFeature.getFeaturePorperty(pF);
for (int index = 0; index < listview.Items.Count; index++)
{
lvProperty.Items.Add(listview.Items[index].Clone()
as ListViewItem);//ListViewItem只能添加到一个ListView中,此处使用Clone方法
}
}
else
toolStripStatusLabel1.Text = "共选择0条记录";
}
/// <summary>
/// 高亮显示所点击节点代表的要素及其属性
/// </summary>
/// <param name="lvIndex">节点索引</param>
/// <param name="FeatureArray">所选择的要素集</param>
private void NodeClicktoFeature(int lvIndex, IArray FeatureArray)
{
IFeature pFeature = FeatureArray.get_Element(lvIndex) as IFeature;
listview = IdentifyFeature.getFeaturePorperty(pFeature);
lvProperty.Items.Clear();
for (int index = 0; index < listview.Items.Count; index++)
{
lvProperty.Items.Add(listview.Items[index].Clone() as ListViewItem);//ListViewItem只能添加到一个ListView中,此处使用Clone方法
}
IHookActions hookAction = pHookHelper as IHookActions;
hookAction.DoAction(pFeature.ShapeCopy, esriHookActions.esriHookActionsFlash);
}
/// <summary>
/// 显示每个要素信息
/// </summary>
/// <param name="pFeature">选择的要素</param>
/// <returns></returns>
public static ListView getFeaturePorperty(IFeature pFeature)
{
ListView listview = new ListView();
listview.View = System.Windows.Forms.View.Details;
IFields pFields = pFeature.Fields;
for (int index = 0; index < pFields.FieldCount; index++)
{
string strValue, strField;
strField = pFields.get_Field(index).Name.ToString();
if (pFields.get_Field(index).Type == esriFieldType.esriFieldTypeGeometry)
{
strValue = pFeature.Shape.GeometryType.ToString();
switch (strValue)
{
case "esriGeometryPoint":
strValue = "点";
break;
case "esriGeometryPolyline":
strValue = "线";
break;
case "esriGeometryPolygon":
strValue = "面";
break;
}
}
else
{
strValue = pFeature.get_Value(index).ToString();
if (strValue == "")
strValue = "<null>";
}
ListViewItem item = new ListViewItem();
item.SubItems[0].Text = strField;
item.SubItems.Add(strValue);
listview.Items.Add(item);
}
return listview;
}
关于ARCGIS中IDENTIFY功能的实现
一:功能实现的基本思路是这样的:
1. 点击时,先获取点击位置的屏幕坐标,然后转换到地图坐标;
2. 定义一个图层对象(Identify),调用相应的Identify方法生成点对象;
3. 提取图层中点击处的图形,提取属性,填充到事先设计好的窗口中;
4. 显示窗口。
二:代码
IIdentify pIdentify; //IIdentify接口(要素图层下的一个接口)定义了获得要素图层单个要素的属性的捷径方法。它有一Identify方法,返回一个IArray数组对象。
IPoint pPoint;
IArray pIDArray;
IFeatureIdentifyObj pFeatIdObj;//定义一个要素对象
IIdentifyObj pIdObj;
IMap pMap = axMapControl1.Map;//将当前地图赋给地图对象pMap
pIdentify = pMap.get_Layer(0) as IIdentify;//将图层赋给图层对象pIdentify
pPoint = new PointClass();//定义了一个实现IPoint接口的点对象
pPoint.PutCoords(e.mapX, e.mapY);//pPoint.PutCoords用来设置点的X,Y值从而创建一个点对象。
pPoint.SpatialReference = pMap.SpatialReference;
pIDArray = pIdentify.Identify(pPoint);//Identify方法返回一个Array数组对象
if (pIDArray != null)
{
pFeatIdObj = pIDArray.get_Element(0) as IFeatureIdentifyObj;//获得要素集数组中的第一个元素
pIdObj = pFeatIdObj as IIdentifyObj;
pIdObj.Flash(axMapControl1.ActiveView.ScreenDisplay);//选中要素闪烁
MessageBox.Show("Layer˖ +
pIdObj.Layer.Name +
System.Environment.NewLine + "Feature˖ +
pIdObj.Name);//显示要素所在图层的名字,要素的的名字
}
else
MessageBox.Show("没有要素选中");
程序的运行结果如图,说明Identify方法生成的数组为空,如下图;

三:程序调试
问题分析:
出现上述问题的原因是IPoint没有和图层建立关系,即无论你有没有点到图层中的点,程序都会通过pPoint.PutCoords(e.MapX,e.MapY)生成点对象,但是pIdentify.identify()方法对参数(pPoint)的传递无响应,该方法只会识别图层中的元素,因此返回的数组始终是空NULL;
问题解决:
参考AE帮助中的DEMO,在此不用point对象,建立一个Envelop对象pEnv(相当于缓冲区), 将该对象作为参数传递给Identify方法就可以了
最终运行结果

四:相关理论知识总结
用到的相关对象 方法 接口:
IMap接口 是开始多数GIS任务的起点,它主要用于管理Map对象中的layer对象,要素选择集、MapSourround对象、标注引擎和空间参考等对象。IMap接口中定义了大量的方法来操作它其中的图层对象(如:AddLayer 、ClearLayers)。
IIdentify接口定义了获得要素图层单个要素的属性的捷径方法。它有一个Identify方法,返回一个IArray数组对象。
IPoint接口定义了Point对象的属性和方法,ID属性可以返回点队形的ID号。使用IPoint::X和IPoint::Y用户可以获得一个点的X和Y的坐标值。
IPoint::PutCoords用于设置一个点的X、Y坐标值,当用户new完成一个Point后,可以用这个方法来建立一个实际的点对象。
包络线Envelop:
Envelop通过它的最大和最小X,Y坐标来定义一个矩形形状,因此包络线对象相对于它的空间参考而言总是直角的。包络线也定义了最大的和最小的Z值、M值,这两个值分别通过IZAware,IMAware接口来定义。

IEnvelope::PutCoords:提供了一种构造了包络线的方法,它通过传入XMin,YMin,XMax,YMax四个点对象而返回一个包络线;IEnvelop::Query则可以返回一个包络线的四个值。
五:
该程序的属性显示用了一个MESSAGEBOX,功能过于简单,没法对元素所有属性字段的显示,需要找一个合适的控件对其属性进行展示。
AO Identify地图交互的更多相关文章
- Adobe Edge Animate –svg地图交互-精确的边缘及颜色置换
Adobe Edge Animate –svg地图交互-精确的边缘及颜色置换 版权声明: 本文版权属于 北京联友天下科技发展有限公司. 转载的时候请注明版权和原文地址. 上一篇我们说到了使用jquer ...
- 大型情感类电视连续剧--Android高德之旅(3)地图交互
总要说两句 前两篇讲到了地图的基础显示和地图类型,今天来记录下高德地图交互相关的设置.地图的绘制分很多层,层级的显示需要根据不同的场景来设置.地图的触摸事件也很丰富,有单击.双击.单指拖拽.双指拖拽. ...
- 【11】openlayers 地图交互
地图交互interaction 关于map的方法: //添加地图交互 map.addInteraction(interaction) //删除地图交互 map.removeInteraction(in ...
- arcgis地图服务之 identify 服务
arcgis地图服务之 identify 服务 在近期的一次开发过程中,利用IdentityTask工具查询图层的时候,请求的参数中ImageDisplay的参数出现了错误,导致查询直接不能执行,百度 ...
- PHP+Mysql+jQuery实现地图区域数据统计-展示数据
我们要在地图上有限的区块内展示更多的信息,更好的办法是通过地图交互来实现.本文将给大家讲解通过鼠标滑动到地图指定省份区域,在弹出的提示框中显示对应省份的数据信息.适用于数据统计和地图区块展示等场景. ...
- 百度地图api简单使用方法
百度地图API的使用方法 百度地图API 开始学习百度地图API最简单的方式是看一个简单的示例.以下代码创建了一个520x340大小的地图区域并以天安门作为地图的中心: 1. <html&g ...
- 20+ 个很有用的 jQuery 的 Google 地图插件
转自:http://www.oschina.net/translate/20-useful-jquery-google-maps-plugins Google 地图在寻找我们想要了解的商店或者其它有趣 ...
- 百度地图的简单使用 ——html js
一.简介 百度地图JavaScript API是一套由JavaScript语言编写的应用程序接口,它能够帮助您在网站中构建功能丰富.交互性强的地图应用,包含了构建地图基本功能的各种接口,提供了诸如本地 ...
- AGS API for JavaScript 图表上地图
原文:AGS API for JavaScript 图表上地图 图1 图2 图3 -------------------------------------华丽丽的分割线--------------- ...
随机推荐
- js艺龙
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【剑指offer】丑数,C++实现
原创博文,转载请注明出处!本题牛客网地址 博客文章索引地址 博客文章中代码的github地址 1. 题目 2. 思路 空间换时间的方法.由于题目要求按序查找丑数,可以采用辅助容器vector按序存储丑 ...
- Adobe Flash Builder 4.6 Premium 安装破解
1.到Adobe官网下载FlashBuilder 4.6,有简体中文版: 语言:简体中文(Simplified)http://trials3.adobe.com/AdobeProducts/FLBR/ ...
- ThreadDeath 理解
public class RunnableTest2 { public static Object obj1 = new Object(); public static Object obj2 = n ...
- Mysql按照字段值做分组行转列查询
今天做个后台服务,有个需求是批量生成一批表的数据,如果用BulkInsert会提升很大一截提交效率,但是如果用循环构造提交的Datable,则算法开销太高,所以用这种查询批量查出符合格式的DataTa ...
- JQ 知识点集合
数组与字符串间的转换 一.数组转字符串(将数组元素用某个字符连接成字符串) var a, b; a = new Array(0,1,2,3,4); b = a.join("-"); ...
- IOS SEL (@selector) 原理及使用总结(一)
SEL 类成员方法的指针 可以理解 @selector()就是取类方法的编号,他的行为基本可以等同C语言的中函数指针,只不过C语言中,可以把函数名直接赋给一个函数指针,而Object-C的类不能直接应 ...
- python调用rpc实现分布式系统
rpc 一般俗称,远程过程调用,把本地的函数,放到远端去调用. 通常我们调用一个方法,譬如: sumadd(10, 20),sumadd方法的具体实现要么是用户自己定义,要么存在于该语言的库函数中,也 ...
- F4NNIU 版本的标准电阻列表(2018-09-29 更新)
F4NNIU 版本的标准电阻列表(2018-09-29 更新) 值代码 电阻值 格式化值 单位 公差代码 公差 格式化值数字 描述 0RJ 0 0 R J 5% J0000 0R 5% (0RJ) 1 ...
- 笔记:webpack 打包参数 mode development
webpack 打包参数 mode development 在开发时使用 webpack 打包后不压缩,所以只需要在 webpack 打包命令中加上 --mode mode development 即 ...