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 -------------------------------------华丽丽的分割线--------------- ...
随机推荐
- appium-java,连接真机启动微信
1.启动appium 2.设置信息 3.设置IP和端口 4.appium连接手机,微信中打开debugx5.qq.com,信息->TBS settings->是否打开TBS内核Insper ...
- 20179223《Linux内核原理与分析》第八周学习笔记
视频学习 可执行文件是怎么得来的? .c汇编成汇编代码.asm,然后再汇编成目标码.o.然后在连接成可执行文件,然后加载到内存可执行了. 对hello.c文件预处理(cpp),预处理负责把includ ...
- ssh/scp免密码登录传输
# 本地服务器生成key(直接回车默认) ssh-keygen # 将key传输到要登录的服务器 ssh-copy-id -i /root/.ssh/id_rsa.pub root@IP地址 # 输入 ...
- 强大的Core Image(教你做自己的美图秀秀))
iOS5新特性:强大的Core Image(教你做自己的美图秀秀)) iOS5给我们带来了很多很好很强大的功能和API.Core Image就是其中之一,它使我们很容易就能处理图片的各种效 ...
- vector 介绍
介绍 这篇文章的目的是为了介绍std::vector,如何恰当地使用它们的成员函数等操作.本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if()和for_each()中的使用.通 ...
- 无法连接到SQL数据库
问题: 连接到服务器------------------------------无法连接到 .. 其他信息:在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误.未找到或无法访问服 ...
- BZOJ1495 [NOI2006]网络收费
题意 传送门 MY市NS中学,大概是绵阳市南山中学. 分析 参照Maxwei_wzj的题解. 因为成对的贡献比较难做,我们尝试把贡献算到每一个叶子节点上.我们发现按照题目中的收费方式,它等价于对于每棵 ...
- 错误:Authentication with old password no longer supported, use 4.1 style passwords.
今天重新装了系统,mysql connector 使用了官网的最新版本(6.8.3). 启动项目出现标题中的错误.原因大家谷歌. 解决方法,使用低版本的 connector. 我使用的是 6.5.6 ...
- Python 函数 -hasattr()
hasattr(object, name)hasattr() 函数用于判断对象是否包含对应的属性.如果对象有该属性返回 True,否则返回 False.object -- 对象.name -- 字符串 ...
- bzoj 1670 [Usaco2006 Oct]Building the Moat护城河的挖掘——凸包
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1670 用叉积判断.注意两端的平行于 y 轴的. #include<cstdio> ...