转自:http://www.cnblogs.com/gisak/archive/2011/03/30/2000297.html

选择一个要素或者一个要素集(FeatureSelection)的方法很多,如IMap::SelectByShape、ILayer::search、IFeatureSection::SelectFeature等方法

主要用到的方法:

IMap接口的SelectFeature(Layer, Feature) (方法,从一个Layer中选择一个Feature);

IMap接口SelectByShape(Shape, env, justOne) (方法,从Layer中依靠一个图形的范围shape和一个选择的环境env来选择要素,而在所有图层中只从IFeatureLayer的图层中进行选择)

IFeatureSelection接口SelectFeatures (Filter, Method, justOne ) (方法,根据指定的标准过滤器filter和方法,选择要素,第一个参数为QueryFilter类型的变量,第二个参数为esriSelectionResultEnum类型的变量,第三个参数为布尔型变量,通常为false)

IFeatureLayer接口Search (IqueryFilter, book ) (方法,创建一个游标去查询相应设置的过滤器的查询)

1 点选法获取要素

废话少说先看代码:

View Code

   
private double ConvertPixelsToMapUnits(IActiveView pActiveView, double pixelUnits) { // Uses the ratio of the size of the map in pixels to map units to do the conversion IPoint p1 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperLeft; IPoint p2 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperRight; int x1, x2, y1, y2; pActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p1, out x1, out y1); pActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p2, out x2, out y2); double pixelExtent = x2 - x1; double realWorldDisplayExtent = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width; double sizeOfOnePixel = realWorldDisplayExtent / pixelExtent; return pixelUnits * sizeOfOnePixel; } IMap pMap = axMapControl1.Map; IActiveView pActiveView = pMap as IActiveView; IFeatureLayer pFeatureLayer = pMap.get_Layer(0) as IFeatureLayer; IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; //设置点击点的位置 IPoint point = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); ITopologicalOperator pTOpo = point as ITopologicalOperator; double length; length = ConvertPixelsToMapUnits(pActiveView, 4); IGeometry pBuffer = pTOpo.Buffer(length); IGeometry pGeomentry = pBuffer.Envelope; //空间滤过器 ISpatialFilter pSpatialFilter = new SpatialFilterClass(); pSpatialFilter.Geometry = pGeomentry; //根据被选择要素的不同,设置不同的空间滤过关系 switch (pFeatureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: pSpatialFilter.SpatialRel=esriSpatialRelEnum.esriSpatialRelContains; break; case esriGeometryType.esriGeometryPolyline: pSpatialFilter.SpatialRel=esriSpatialRelEnum.esriSpatialRelCrosses; break; case esriGeometryType.esriGeometryPolygon : pSpatialFilter.SpatialRel=esriSpatialRelEnum.esriSpatialRelIntersects; break; } IFeatureSelection pFSelection=pFeatureLayer as IFeatureSelection; pFSelection.SelectFeatures(pSpatialFilter,esriSelectionResultEnum.esriSelectionResultNew,false); ISelectionSet pSelectionset=pFSelection.SelectionSet; ICursor pCursor; pSelectionset.Search(null,true,out pCursor); IFeatureCursor pFeatCursor=pCursor as IFeatureCursor; IFeature pFeature=pFeatCursor.NextFeature(); while(pFeature!=null) { pMap.SelectFeature(pFeatureLayer,pFeature); pFeature=pFeatCursor.NextFeature(); } pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphicSelection,null,null); //另外的改写: pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName; IQueryFilter pFilter = pSpatialFilter; IFeatureCursor pFeatCursor = pFeatureLayer.Search(pFilter,false); IFeature pFeature=pFeatCursor.NextFeature(); while(pFeature!=null) { pMap.SelectFeature(pFeatureLayer,pFeature); pFeature=pFeatCursor.NextFeature(); } pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphicSelection,null,null);

另外还有一种比较简单的点选方法:

View Code

   
IGeometry g = null; IEnvelope pEnv; IActiveView pActiveView = axMapControl1.ActiveView; IMap pMap = axMapControl1.Map; pEnv = axMapControl1.TrackRectangle(); if (pEnv.IsEmpty == true) { ESRI.ArcGIS.Display.tagRECT r; r.bottom = e.y + 5; r.top = e.y - 5; r.left = e.x - 5; r.right = e.x + 5; pActiveView.ScreenDisplay.DisplayTransformation.TransformRect(pEnv, ref r, 4); pEnv.SpatialReference = pActiveView.FocusMap.SpatialReference; } g = pEnv as IGeometry; axMapControl1.Map.SelectByShape(g, null, false); axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);

2 拉框选择

View Code

   
IMap pMap = axMapControl1.Map; IActiveView pActiveView = pMap as IActiveView; IEnvelope pEnv = axMapControl1.TrackRectangle(); pMap.SelectByShape(pEnv, null, false); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection,null, null);

AE要素选择(点选和拉框选择)相关推荐

  1. Angular实现虚拟滚动多选下拉框笔记

    要求: 实现一个angular多选下拉框组件,当有超过2000个选项时,滑动/挑选/全选均不卡. 正篇: 为了方便,这里不考虑扩展性,所以规定下拉框展开只显示7行数据,行高27px 约定:input为 ...

  2. HTML多选mysql,html多选下拉框 | 学步园

    一个jquery ui,实现html的多选下拉框,在下拉里面加checkbox,不改变页面的提交特性,只是动态的改变select选中的多选数据. jsp页面例子: pageEncoding=" ...

  3. rails使用html form,Rails 页面多选下拉框, form_for, form_tag 使用技巧及 select2 使用

    表单的多选下拉框在 web 项目中比较常用且常见,所以快速构建多选下拉框是每个 Rails 全栈开发者必备的技能. 这篇文章总结使用 select2 前端插件和 Rails 内置的视图帮助方法 sel ...

  4. 【js】复选框,复选下拉框,文本框勾连

    [js]对常见事件的一个总结 ps: 内容涉及(kendo Ui, jQuery) 如下图所示:要求实现功能点 (1)用户名(复选下拉框,可选择多个)和用户名(文本输入框)相勾连 复选下拉框改变,文本 ...

  5. LayUI可选择可输入下拉框

    LayUI可选择可输入下拉框 可输入的下拉框 把input 叠加到select上,外观看起来像一个框. 利用z-index把 input框放到select 上层.并让select 不自动填充. 我现在 ...

  6. Qt实现复选下拉框 C++

    文章目录 一.QListWidget+QListWidgetItem 二.activate(int) 总结 一.QListWidget+QListWidgetItem 实现QComboBox下拉框复选 ...

  7. 微信小程序下拉框选择

    wxml代码 <view class='top-selected' bindtap='bindShowMsg'><text>{{grade_name}}</text> ...

  8. layui多选下拉框,多选,使用xm-select插件

    1. layui的多选下拉框可以使用 xm-select 插件实现.使用步骤如下:1. 下载 xm-select 插件,并在页面中引入: html <link rel="stylesh ...

  9. html css 多选下拉框,jQuery多选下拉框插件

    jquery.multi-select.js是一款jQuery多选下拉框插件.该插件可以将select元素转换为带checkbox的多选下拉框,非常实用. 使用方法 在页面中引入下面的文件. lt;l ...

最新文章

  1. 大脑天天超负荷,三分天赋,七分练,世间惊现普通脑修炼秘籍
  2. 低代码缺少的五大组件
  3. 计算字符串和文件的MD5值
  4. internship weekly task update
  5. Where is number of opportunities not displayed message poped up
  6. Vue 页面权限控制(一)
  7. [置顶] 数据结构之 链栈的实现
  8. Eclipse保护色设置
  9. matlab积分器的工作原理,Simulink积分器详解(图)
  10. Intellij IDEA 插件下载慢或无法查询
  11. 程序员请万分珍重你的第一份工作,否则后悔了概不负责
  12. 解读Tilera怪兽级64核处理器(转)
  13. java判断闰年中闰月_闰年闰月查询表_闰月查询表_闰年查询表-万年历
  14. iOS 音乐播放器的实现
  15. ardupilot软件仿真及调试(vscode版)
  16. 这一周CSDN人都看了些什么?(5.14-5.20)
  17. ZCMU-1635:超大型 LED 显示屏(细节题)
  18. 08-cmd定时关机和取消定时关机
  19. 一篇文章带你理清宽带、带宽、网速、吞吐量与宽带上下行
  20. 小马哥-----高仿米4拆机 刷机主板多图展示 主板为x77 型号k6 6582芯片 14年底版本

热门文章

  1. 利用linux的/dev/urandom文件产生较好的随机数
  2. 头条的6个赚钱方法,做的好也可以每天收益几百元
  3. 360度商品展示html5,360度图片旋转产品预览展示js插件
  4. QT操作Sqlite数据库修改字段名称和删除字段
  5. SAP R3 安装出错 FJS-00012 Error when executing script.
  6. 命令行参数是什么?如何去使用它?
  7. 对比下HTML5和小程序的组件标签的区别
  8. git(二) ——— error: invalid object 100644 6edf27fdfc03af6c77731d76b048063f279e7ac6
  9. DISN:Deep Implicit Surface Network for High-quality Single-view 3D Reconstruction
  10. 字节跳动2022年最新面试经验分享,2个部门6轮面试全复盘(算法岗)