C# Arcgis Engine 获得鼠标按下位置的要素
public IFeature GetFeatureOnMouseDown(IPoint point)
{
try
{
ILayer layer = Common.GetLayerByName(mMap, "地块");
if (layer == null)
{
MessageBox.Show("请加载地块图层!", "提示");
return null;
}
//IFeatureLayer fLayer = layer as IFeatureLayer;
//IFeatureSelection featureSelection = fLayer as IFeatureSelection;
//featureSelection.Clear();
//if (featureSelection == null)
//{
// return null;
//} IFeatureLayer featureLayer = layer as IFeatureLayer;
if (featureLayer == null)
return null;
IFeatureClass featureClass = featureLayer.FeatureClass;
if (featureClass == null)
return null; //IPoint point = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
IGeometry geometry = point as IGeometry; double length = ConvertPixelsToMapUnits(axMapControl1.ActiveView, );
ITopologicalOperator pTopo = geometry as ITopologicalOperator;
IGeometry buffer = pTopo.Buffer(length);
geometry = buffer.Envelope as IGeometry; ISpatialFilter spatialFilter = new SpatialFilterClass();
spatialFilter.Geometry = geometry;
switch (featureClass.ShapeType)
{
case esriGeometryType.esriGeometryPoint:
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
break;
case esriGeometryType.esriGeometryPolygon:
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
break;
case esriGeometryType.esriGeometryPolyline:
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
break;
}
spatialFilter.GeometryField = featureClass.ShapeFieldName;
IQueryFilter filter = spatialFilter as IQueryFilter; IFeatureCursor cursor = featureClass.Search(filter, false);
IFeature pfeature = cursor.NextFeature();
if (pfeature != null)
{
return pfeature;
//featureSelection.Add(pfeature);
//pfeature = cursor.NextFeature();
}
else
{
return null;
}
}
catch
{
return null;
}
}
大家可以修改一下我的代码,图层改成你需要的图层即可。也可以写成类。只是写成类的话,变量可能会多一点。
if (pfeature != null)
{
return pfeature;
//featureSelection.Add(pfeature);
//pfeature = cursor.NextFeature();
}
此处也可以将if改成while,如果选择的是多个要素的话。将我注释掉的代码打开即可选择多个要素。
C# Arcgis Engine 获得鼠标按下位置的要素的更多相关文章
- 最简单的ArcGIS Engine应用程序(下)
在中篇我们讲到使用OpenFileDialog控件可以添加shp文件.(最简单的ArcGIS Engine应用程序(中)) 添加lyr文件的操作也是大同小异的. using System; using ...
- ArcGIS Engine环境下创建自定义的ArcToolbox Geoprocessing工具
在上一篇日志中介绍了自己通过几何的方法合并断开的线要素的ArcGIS插件式的应用程序.但是后来考虑到插件式的程序的配置和使用比较繁琐,也没有比较好的错误处理机制,于是我就把之前的程序封装成一个类似于A ...
- ArcGIS Engine 下投影坐标和经纬度坐标的相互转换
ArcGIS Engine 下投影坐标和经纬度坐标的相互转换 投影转经纬度 ); pPoint.Project(pSRF.CreateGeographicCoordinateSystem((int)e ...
- VS2010下WPF开发ARCGIS ENGINE 10的带Ribbon控件项目
原文 http://blog.sina.com.cn/s/blog_47522f7f0100nq5t.html 题目好长,但是集目前最新的工具于一身..VS是最新的2010版,不过用的是.net3.5 ...
- JQuery使用mousedown和mouseup简单判断鼠标按下与释放位置是否相同
在JQuery中,我们可以利用mousedown.mouseup来跟踪页面的鼠标按下与释放事件. 如何获取鼠标的位置信息呢?事件event的pageX和pageY属性可以让我们获得鼠标在页面中的具体位 ...
- ArcGIS Engine开发之旅03--ArcGIS Engine中的控件
原文:ArcGIS Engine开发之旅03--ArcGIS Engine中的控件 制图控件,如MapControl.PageLayoutControl,其中MapControl控件主要用于地理数据的 ...
- 利用ArcGIS Engine、VS .NET和Windows控件开发GIS应用
Dixon 原文 用ArcGIS Engine.VS .NET和Windows控件开发GIS应用 此过程说明适合那些使用.NET建立和部署应用的开发者,它描述了使用ArcGIS控件建立和部署 ...
- 《ArcGIS Engine+C#实例开发教程》第五讲 鹰眼的实现
原文:<ArcGIS Engine+C#实例开发教程>第五讲 鹰眼的实现 摘要:所谓的鹰眼,就是一个缩略地图,上面有一个矩形框,矩形框区域就是当前显示的地图区域,拖动矩形框可以改变当前地图 ...
- ArcGIS Engine Style文件操作
对于一个GISer来说,地图,符号这些都应该有着比别人更深刻的理解和认识,作为平台软件都会提供一套自己的符号库,符号库里面根据类别和种类进行区分,因为点,线,面的自然存在和固有属性是不肯能让你用面状符 ...
随机推荐
- 8.queue
#include <iostream> #include <stack> #include <algorithm> #include <list> #i ...
- 版本控制器:SVN(精讲)
版本控制器:SVN 1 开发中的实际问题 1.1 小明负责的模块就要完成了,就在即将Release之前的一瞬间,电脑突然蓝屏,硬盘光荣牺牲!几个月来的努力付之东流——需求之一:备份! 1.2 这个项目 ...
- Saying Good-bye to Cambridge Again
Saying Good-bye to Cambridge Again Very quietly I take my leave, As quietly as I came here; ...
- javascript常用收集一下
事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture(); event.srcEl ...
- codeforces 527 C Glass Carving
Glass Carving time limit per test 2 seconds Leonid wants to become a glass carver (the person who cr ...
- Xor Sum 2(位运算)
D - Xor Sum 2 Time limit : 2sec / Memory limit : 1024MB Score : 500 points Problem Statement There i ...
- 什么是Node.js?
Node.js是一个基于Chrome JavaScript运行时建立的平台, 用于方便地搭建响应速度快.易于扩展的网络应用.Node.js 使用事件驱动, 非阻塞I/O 模型而得以轻量和高效,非常适 ...
- python读取word文档
周末需要做一个统计word文档字数的问题,刚开始以为很简单,因为之前做过excel表格相关的任务,所以认为利用扩展模块应该比较简单. 通过搜索,确实搜到了一个python操作word的模块,pytho ...
- [译] 我最终是怎么玩转了 Vue 的作用域插槽
原文链接:https://juejin.im/post/5c8856e6e51d456b30397f31#comment 原文地址:How I finally got my head around S ...
- [NOIP2012提高组]国王游戏
题目:洛谷P1080.Vijos P1779.codevs1198. 题目大意:国王和每个大臣左.右手各写了一个数.规定每个大臣得到的金币数为他前面所有人左手的数字的乘积除以他自己右手的数(向下取整) ...