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 获得鼠标按下位置的要素的更多相关文章

  1. 最简单的ArcGIS Engine应用程序(下)

    在中篇我们讲到使用OpenFileDialog控件可以添加shp文件.(最简单的ArcGIS Engine应用程序(中)) 添加lyr文件的操作也是大同小异的. using System; using ...

  2. ArcGIS Engine环境下创建自定义的ArcToolbox Geoprocessing工具

    在上一篇日志中介绍了自己通过几何的方法合并断开的线要素的ArcGIS插件式的应用程序.但是后来考虑到插件式的程序的配置和使用比较繁琐,也没有比较好的错误处理机制,于是我就把之前的程序封装成一个类似于A ...

  3. ArcGIS Engine 下投影坐标和经纬度坐标的相互转换

    ArcGIS Engine 下投影坐标和经纬度坐标的相互转换 投影转经纬度 ); pPoint.Project(pSRF.CreateGeographicCoordinateSystem((int)e ...

  4. VS2010下WPF开发ARCGIS ENGINE 10的带Ribbon控件项目

    原文 http://blog.sina.com.cn/s/blog_47522f7f0100nq5t.html 题目好长,但是集目前最新的工具于一身..VS是最新的2010版,不过用的是.net3.5 ...

  5. JQuery使用mousedown和mouseup简单判断鼠标按下与释放位置是否相同

    在JQuery中,我们可以利用mousedown.mouseup来跟踪页面的鼠标按下与释放事件. 如何获取鼠标的位置信息呢?事件event的pageX和pageY属性可以让我们获得鼠标在页面中的具体位 ...

  6. ArcGIS Engine开发之旅03--ArcGIS Engine中的控件

    原文:ArcGIS Engine开发之旅03--ArcGIS Engine中的控件 制图控件,如MapControl.PageLayoutControl,其中MapControl控件主要用于地理数据的 ...

  7. 利用ArcGIS Engine、VS .NET和Windows控件开发GIS应用

    Dixon 原文  用ArcGIS Engine.VS .NET和Windows控件开发GIS应用     此过程说明适合那些使用.NET建立和部署应用的开发者,它描述了使用ArcGIS控件建立和部署 ...

  8. 《ArcGIS Engine+C#实例开发教程》第五讲 鹰眼的实现

    原文:<ArcGIS Engine+C#实例开发教程>第五讲 鹰眼的实现 摘要:所谓的鹰眼,就是一个缩略地图,上面有一个矩形框,矩形框区域就是当前显示的地图区域,拖动矩形框可以改变当前地图 ...

  9. ArcGIS Engine Style文件操作

    对于一个GISer来说,地图,符号这些都应该有着比别人更深刻的理解和认识,作为平台软件都会提供一套自己的符号库,符号库里面根据类别和种类进行区分,因为点,线,面的自然存在和固有属性是不肯能让你用面状符 ...

随机推荐

  1. 一入python深似海--python之道

    python社区不乏幽默.先来看"python之道"这首诗. 导入this包: import this 输出是一首诗,这首诗总结了Python的风格,能够指导Python程序猿的编 ...

  2. Objective-C对象与Core Foundation对象

    Core Foundation 对象主要使用在用C语言编写的Core Foundation 框架中,并引用计数的对象.与Objective-C对象差别非常少.不管哪种框架生成的对象,一旦生成,便可在两 ...

  3. bzoj1070: [SCOI2007]修车(费用流)

    1070: [SCOI2007]修车 题目:传送门 题解: 一道挺简单的费用流吧...胡乱建模走起 贴个代码... #include<cstdio> #include<cstring ...

  4. Word frequency analysis

    Write a program that reads a file, breaks each line into words, scripts whitespace and punctuation f ...

  5. POJ 3667 线段树+标记

    自从某次考试写线段树写挂了以后 这是第一次写线段树,,,,,, 这是一个伤心的故事-- 题意: 思路: 标记 维护从左到右的最大值 从右到左的最大值 区间内的最大值-- 然后就一搞 就出来了 //By ...

  6. Kali linux 2016.2(Rolling)中metasploit的主机探测

    不多说,直接上干货! 1.活跃主机扫描 root@kali:~# ping -c 202.193.58.13 PING () bytes of data. bytes ttl= time=25.4 m ...

  7. 在cncc的最后几天的笔记

    数据库范式:http://blog.csdn.net/fg2006/article/details/6936439 数据库事务隔离级别:http://blog.csdn.net/fg2006/arti ...

  8. python 字符串匹配问题

    想匹配html = <div class="back fl"><a href="javascript:void(0);" onclick=&q ...

  9. hive parquet table 配置使用压缩

    创建parquet table : create table mytable(a int,b int) STORED AS PARQUET; 创建带压缩的parquet table: create t ...

  10. Out-of-Process iframes (OOPIFs)

    For Developers‎ > ‎Design Documents‎ > ‎ Out-of-Process iframes (OOPIFs) This page provides an ...