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

好久没有写博文了,这段时间相对空闲一点,把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 = ;
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<IFeature>();//实例化合并要素集
if (Shift == )
{
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 = ;
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 - ];
_mapCtrl.FlashShape(pGeometry, , , iSymbol);
}
//清空选择要素
else
{
pActiveView.FocusMap.ClearSelection();
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, pActiveView.Extent);
}

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

if (Button == )
{
//清空地图视图
_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 + , Y + ); 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;
}
}

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. 类名引用static变量好处

    不仅强调了变量static的结构,而且在有些情况下他还为编译器进行优化提供了更好的机会.

  2. 动态库dll使用module.def文件导出函数(像静态库一样使用)

    1.新建文件module.def. 2.动态库工程上右键->属性->链接器->输入->模块定义文件编辑它写入module.def 3.下面为module.def实例(smart ...

  3. MD5和sha1加密算法--散列加密技术 MD5:128bit的大整数

    在很多电子商务和社区应用中,我们都要存放很多的客户的资料,其中包括了很多的隐私信息和客户不愿被别人看到的信息,当然好有客户执行各种操作的密码,此时就需要对客户的信息进行加密再存储,目前有两种比较好的加 ...

  4. JS / CSS 实现的便签记录本

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  5. 洛谷 P1724 东风早谷苗

    洛谷 P1724 东风早谷苗 题目描述 在幻想乡,东风谷早苗是以高达控闻名的高中生宅巫女.某一天,早苗终于入手了最新款的钢达姆模型.作为最新的钢达姆,当然有了与以往不同的功能了,那就是它能够自动行走, ...

  6. jsp+tomcat+ 创建project 配置project

    *如今我们已经下载到了 tomcat 7.0+ eclipse for java ee 直接解压,打开eclipse. 接下来是步骤: eclipse 打开的界面.空空如也 ! ..* 点击 file ...

  7. win7打不开chm格式文件

           近期在开发的过程中,发现重装的系统Wind7 打不开java帮助文档.搜索了半天才找到. 在这里分享一下. 一.假设不能打开,可这样恢复文件关联: 1.開始执行,输入:regsvr32 ...

  8. 2.1 Vue组件

    Vue组件 全局组件和局部组件 父子组件通讯-数据传递 父->子:通过Props传递 子->父:不允许,但vue通过子组件触发Emit来提交给子组件进行触发 Slot import Cou ...

  9. xpath使用方法详解id 、starts-with、contains、text()和last() 的用法

    1.XPATH使用方法 使用XPATH有如下几种方法定位元素(相比CSS选择器,方法稍微多一点): a.通过绝对路径定位元素(不推荐!) WebElement ele = driver.findEle ...

  10. scrapy-加蘑菇代理

    加代理ip     隧道代理 setting中 解开  下载器