转自原文ArcEngine数据编辑--选择要素

好久没有写博文了,这段时间相对空闲一点,把AE数据编辑实现总结下。

要编辑要素,首先要选中要素,按shift键进行多选,按esc键清空选择。

个人了解的选择高亮显示有两种方式,都是在public override void OnMouseDown(int Button, int Shift, int X, int Y)事件中处理实现:

1、  IFeatureSelection 这个要求明确选择的图层

  1. IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
  2. IEnvelope pEnvelope;
  3. double tol = ;
  4. pEnvelope = pPoint.Envelope;
  5. pEnvelope.Width = pEnvelope.Width + tol;
  6. pEnvelope.Height = pEnvelope.Height + tol;
  7. pEnvelope.CenterAt(pPoint);
  8.  
  9. ISpatialFilter pSpatialFilter;
  10. pSpatialFilter = new SpatialFilterClass();
  11. pSpatialFilter.Geometry = pEnvelope;
  12. pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
  13. IFeatureSelection pFeatureSelection;
  14. pFeatureSelection = ucDrawPanel.currentFeatureLayer as IFeatureSelection;
  15. IFeature pFeature;
  16. ucDrawPanel.unionFeature = new List<IFeature>();//实例化合并要素集
  17. if (Shift == )
  18. {
  19. if (ucDrawPanel.currentFeatureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
  20. {
  21. pFeatureSelection.SelectFeatures(pSpatialFilter,
  22. esriSelectionResultEnum.esriSelectionResultAdd, true);
  23. ICursor pCursor;
  24. pFeatureSelection.SelectionSet.Search(null, false, out pCursor);
  25. }
  26. }
  27. else
  28. {
  29. pActiveView.FocusMap.ClearSelection();
  30. pFeatureSelection.SelectFeatures(pSpatialFilter,
  31. esriSelectionResultEnum.esriSelectionResultNew, true);
  32.  
  33. ICursor pCursor;
  34. pFeatureSelection.SelectionSet.Search(null, false, out pCursor);
  35. }
  36. pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, ucDrawPanel.currentFeatureLayer, null);
  37. //高亮显示出来
  38. ISimpleFillSymbol iFillSymbol;
  39. ISymbol iSymbol;
  40. IRgbColor iRgbColor;
  41. iFillSymbol = new SimpleFillSymbol();
  42. iFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
  43. iRgbColor = new RgbColor();
  44. iRgbColor.Green = ;
  45. iFillSymbol.Color = iRgbColor;
  46. iSymbol = (ISymbol)iFillSymbol;
  47. iSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;
  48.  
  49. IEnumFeature pEnumFeature = pActiveView.FocusMap.FeatureSelection as IEnumFeature;
  50. pEnumFeature.Reset();
  51. pFeature = pEnumFeature.Next();
  52. //选中要素高亮显示
  53. if (pFeature != null)
  54. {
  55. IGeometry pGeometry = pFeature.Shape;
  56. ITopologicalOperator pTop = pGeometry as ITopologicalOperator;
  57. while (pFeature != null)
  58. {
  59. ucDrawPanel.unionFeature.Add(pFeature);
  60.  
  61. pGeometry = pTop.Union(pFeature.Shape);
  62. pTop = pGeometry as ITopologicalOperator;
  63. pFeature = pEnumFeature.Next();
  64. }
  65. ucDrawPanel.currentFeature = ucDrawPanel.unionFeature[ucDrawPanel.unionFeature.Count - ];
  66. _mapCtrl.FlashShape(pGeometry, , , iSymbol);
  67. }
  68. //清空选择要素
  69. else
  70. {
  71. pActiveView.FocusMap.ClearSelection();
  72. pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, pActiveView.Extent);
  73. }

2、  SelectByMap 基于整个地图,当然也可以先将图层的selectable属性动态设置下

  1. if (Button == )
  2. {
  3. //清空地图视图
  4. _mapCtrl.Map.ClearSelection();
  5. IGraphicsContainer pContainer = _mapCtrl.Map as IGraphicsContainer;
  6. pContainer.DeleteAllElements();
  7. _mapCtrl.ActiveView.Refresh();
  8.  
  9. base.OnMouseDown(Button, Shift, X, Y);
  10.  
  11. IActiveView pActiveView = _mapCtrl.ActiveView;
  12. IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
  13. IPoint TempPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X + , Y + );
  14.  
  15. IEnvelope objEnvelope;
  16. double tol = Math.Abs(TempPoint.X - pPoint.X);
  17. objEnvelope = pPoint.Envelope;
  18. objEnvelope.Width = objEnvelope.Width + tol;
  19. objEnvelope.Height = objEnvelope.Height + tol;
  20. objEnvelope.CenterAt(pPoint);
  21. setSelectable(ucDrawPanel.currentLayerName);//只有当前编辑图层可选
  22.  
  23. _mapCtrl.Map.SelectByShape((IGeometry)objEnvelope, null, true);//只选择一个要素
  24. pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, _mapCtrl.ActiveView.Extent);
  25.  
  26. ucDrawPanel.currentFeatureLayer = GetLayerByName(_mapCtrl, ucDrawPanel.currentLayerName);
  27. if (ucDrawPanel.currentFeatureLayer != null)
  28. {
  29. ucDrawPanel.currentFeature = GetFeatureBySelection(ucDrawPanel.currentFeatureLayer);
  30. }
  31. else
  32. {
  33. MessWin messWin = new MessWin();
  34. messWin.SetTitleAndMess("提示", @"获取选择要素出错!", false);
  35. return;
  36. }
  37. }

PS:esc键退出,在OnKeyDown事件中实现

  1. public override void OnKeyDown(int keyCode, int Shift)
  2. {
  3. if (keyCode == (int)Keys.Escape)
  4. {
  5. IActiveView pActiveView = _mapCtrl.ActiveView;
  6. pActiveView.FocusMap.ClearSelection();
  7. pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, pActiveView.Extent);
  8. _mapCtrl.CurrentTool = null;
  9. }
  10. }

ArcEngine数据编辑--选择要素的更多相关文章

  1. 利用IIdentify接口实现点选和矩形选择要素

    duckweeds 原文利用IIdentify接口实现点选和矩形选择要素 Identify接口定义了获得要素图层单个要素的属性的捷径方法.它有一个Identify方法,返回一个IArray数组对象. ...

  2. AE,按照属性值关系选择要素

    if(axMapControl2.LayerCount<=0) { MessageBox.Show("请加载图层后使用该功能","系统提示",Messag ...

  3. ArcEngine选中面要素样式修改

    //只用前五行,可以直接将选中的面要素的颜色全部修改成红色,也就是填充颜色 IRgbColor pRgbColor= new RgbColor();; pRgbColor.Red = ; pRgbCo ...

  4. ArcEngine 创建线要素图层

    在创建要素图层的时候,默认的几何类型是Polygon: Dim objectClassDescription As IObjectClassDescription = New FeatureClass ...

  5. ArcEngine 数据编辑(IWorkspaceFactory)

    数据编辑做过很多次,没怎么出现问题,今天出现了问题,浪费了大半天,记录一下. 问题:修改Featrue的属性,修改后停止编辑,但是没有提示是否保存修改 原因:在编辑数据的时候没有加StartEditO ...

  6. Arcengine 实现要素选取的方法(转载)

    转自原文Arcengine 实现要素选取的方法(转载) 选择一个要素或者一个要素集(FeatureSelection)的方法很多,如IMap::SelectByShape.ILayer::search ...

  7. ArcGIS Engine中如何获取Map中已经选择的要素呢

    1.使用IEnumFeturea对象获取map中的FeatureSelection,该方法可以获取所有图层的选择要素.IMap中的FeatureSelection可不是IFeatureSelectio ...

  8. Dotspatial 空间要素选择

    //通过遍历选择要素,获取选择要素相交的要素 private void toolStripButton43_Click(object sender, EventArgs e) { //查看与选中要素重 ...

  9. ArcGIS Engine中如何获取Map中已经选择的要素呢(转)

    ArcGIS Engine中如何获取Map中已经选择的要素呢   1.使用IEnumFeturea对象获取map中的FeatureSelection,该方法可以获取所有图层的选择要素.IMap中的Fe ...

随机推荐

  1. POJ3622 Gourmet Grazers(FHQ Treap)

    Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 2363   Accepted: 881 Description Like s ...

  2. Windows 下 Sublime Text 默认打开方式问题解决办法

    Sublime Text 2 是很受ACMer喜爱的文本编辑器 但是绿色版删除后无法设置为默认打开方式...而且网上也没有给出明确的解决办法 注册表的解决办法: 删除 HKEY_CURRENT_USE ...

  3. 模板 Fail树

    fail树就是将Trie图的Fail指针反指,从而生成一棵树,这个树的性质是:子节点对应字符串为以当前串为后缀,而子节点为原串的前缀,前缀的后缀就是嵌套在原串中的子串. 模板:BZOJ3172 Des ...

  4. 【Codeforces Round #455 (Div. 2) C】 Python Indentation

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 一个for循环之后. 下一个写代码的地方一是从(x+1,y+1)开始的 然后如果写完了一个simple statement 下次就有 ...

  5. Opera mini for S60 custom server

    Opera mini for S60 custom server 在线改服 http://yourshell.info/mo/mini/ 本人贫穷一族,一直在用S60V2,这种手机启动JAVA很占内存 ...

  6. amazeui学习笔记二(进阶开发4)--JavaScript规范Rules

    amazeui学习笔记二(进阶开发4)--JavaScript规范Rules 一.总结 1.注释规范总原则: As short as possible(如无必要,勿增注释):尽量提高代码本身的清晰性. ...

  7. .condarc(conda 配置文件)

    Configuration - Conda documentation .condarc以点开头,一般表示 conda 应用程序的配置文件,在用户的家目录(windows:C:\\users\\use ...

  8. ASP.NET路径解惑

    对于ASP.NET的路径问题,一直都是云里雾里,没有去详细的理解,今天正好可以梳理一下它们之间的关系和使用方法.而若想明白路径的表示方式的使用方法和区别以及注意事项可以通过下面的几个概念来进一步加深: ...

  9. Android网络框架OkHttp之get请求(源码初识)

    概括 OkHttp现在很火呀.于是上个星期就一直在学习OkHttp框架,虽然说起来已经有点晚上手了,貌似是2013年就推出了.但是现在它版本更加稳定了呀.这不,说着说着,OkHttp3.3版本在这几天 ...

  10. ZOJ 1242 Carbon Dating

    UVA昨天上不去,今天一大早起来还是上不去 0.0 于是去ZOJ 这题大意就是半衰期... 取对数用到了换底公式...我都忘了这玩意了T T 上代码... #include<iostream&g ...