博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ArcEngine数据编辑--选择要素
阅读量:7027 次
发布时间:2019-06-28

本文共 4437 字,大约阅读时间需要 14 分钟。

转自原文

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

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

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

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

IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);IEnvelope pEnvelope;double tol = 20;pEnvelope = pPoint.Envelope;pEnvelope.Width = pEnvelope.Width + tol;pEnvelope.Height = pEnvelope.Height + tol;pEnvelope.CenterAt(pPoint); ISpatialFilter pSpatialFilter;pSpatialFilter = new SpatialFilterClass();pSpatialFilter.Geometry = pEnvelope;pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;IFeatureSelection pFeatureSelection;pFeatureSelection = ucDrawPanel.currentFeatureLayer as IFeatureSelection;IFeature pFeature;ucDrawPanel.unionFeature = new List
();//实例化合并要素集if (Shift == 1){ if (ucDrawPanel.currentFeatureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { pFeatureSelection.SelectFeatures(pSpatialFilter, esriSelectionResultEnum.esriSelectionResultAdd, true); ICursor pCursor; pFeatureSelection.SelectionSet.Search(null, false, out pCursor); }}else{ pActiveView.FocusMap.ClearSelection(); pFeatureSelection.SelectFeatures(pSpatialFilter, esriSelectionResultEnum.esriSelectionResultNew, true); ICursor pCursor; pFeatureSelection.SelectionSet.Search(null, false, out pCursor); }pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, ucDrawPanel.currentFeatureLayer, null);//高亮显示出来ISimpleFillSymbol iFillSymbol;ISymbol iSymbol;IRgbColor iRgbColor;iFillSymbol = new SimpleFillSymbol();iFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;iRgbColor = new RgbColor();iRgbColor.Green = 128;iFillSymbol.Color = iRgbColor;iSymbol = (ISymbol)iFillSymbol;iSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; IEnumFeature pEnumFeature = pActiveView.FocusMap.FeatureSelection as IEnumFeature;pEnumFeature.Reset();pFeature = pEnumFeature.Next();//选中要素高亮显示if (pFeature != null){ IGeometry pGeometry = pFeature.Shape; ITopologicalOperator pTop = pGeometry as ITopologicalOperator; while (pFeature != null) { ucDrawPanel.unionFeature.Add(pFeature); pGeometry = pTop.Union(pFeature.Shape); pTop = pGeometry as ITopologicalOperator; pFeature = pEnumFeature.Next(); } ucDrawPanel.currentFeature = ucDrawPanel.unionFeature[ucDrawPanel.unionFeature.Count - 1]; _mapCtrl.FlashShape(pGeometry, 1, 500, iSymbol);}//清空选择要素else{ pActiveView.FocusMap.ClearSelection(); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, pActiveView.Extent);}

 

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

 

if (Button == 1){    //清空地图视图    _mapCtrl.Map.ClearSelection();    IGraphicsContainer pContainer = _mapCtrl.Map as IGraphicsContainer;    pContainer.DeleteAllElements();    _mapCtrl.ActiveView.Refresh();     base.OnMouseDown(Button, Shift, X, Y);     IActiveView pActiveView = _mapCtrl.ActiveView;    IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);    IPoint TempPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X + 5, Y + 5);     IEnvelope objEnvelope;    double tol = Math.Abs(TempPoint.X - pPoint.X);    objEnvelope = pPoint.Envelope;    objEnvelope.Width = objEnvelope.Width + tol;    objEnvelope.Height = objEnvelope.Height + tol;    objEnvelope.CenterAt(pPoint);    setSelectable(ucDrawPanel.currentLayerName);//只有当前编辑图层可选     _mapCtrl.Map.SelectByShape((IGeometry)objEnvelope, null, true);//只选择一个要素    pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, _mapCtrl.ActiveView.Extent);     ucDrawPanel.currentFeatureLayer = GetLayerByName(_mapCtrl, ucDrawPanel.currentLayerName);    if (ucDrawPanel.currentFeatureLayer != null)    {        ucDrawPanel.currentFeature = GetFeatureBySelection(ucDrawPanel.currentFeatureLayer);    }    else    {        MessWin messWin = new MessWin();        messWin.SetTitleAndMess("提示", @"获取选择要素出错!", false);        return;    }}

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

public override void OnKeyDown(int keyCode, int Shift){    if (keyCode == (int)Keys.Escape)    {        IActiveView pActiveView = _mapCtrl.ActiveView;        pActiveView.FocusMap.ClearSelection();        pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, pActiveView.Extent);        _mapCtrl.CurrentTool = null;    }}

 

 

 

转载地址:http://hpoxl.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
我们是如何上网?
查看>>
JavaWEB程序员电脑必备配置
查看>>
我的友情链接
查看>>
oracle性能调优总结
查看>>
relink all the executables of 11g
查看>>
冲突域和冲突域
查看>>
Sass学习笔记 -- 嵌套
查看>>
linux日志分析及管理
查看>>
netapp学习(二)---开启DNS功能
查看>>
创建MYSQL用户及授权用户权限
查看>>
TextView颜色等属性在string.xml定义
查看>>
docker迁移容器
查看>>
HBase 表数据 导入导出
查看>>
PropertyGrid无意的发现DisplayNameAttribute及应用
查看>>
我的友情链接
查看>>
Android之计算缓存大小并且清空缓存
查看>>
tomcat报内存溢出,解决方案
查看>>
DI序曲二十五 App-V与Remote App综合使用
查看>>
LVS+Keepalived相关参考资料
查看>>