ArcEngine数据编辑--选择要素

转自原文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 = 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<IFeature>();//实例化合并要素集
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;
    }
}
时间: 2024-10-28 10:47:18

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

ArcEngine选中面要素样式修改

//只用前五行,可以直接将选中的面要素的颜色全部修改成红色,也就是填充颜色 IRgbColor pRgbColor= new RgbColor();; pRgbColor.Red = 255; pRgbColor.Green = 0; pRgbColor.Blue = 0; IFeatureSelection pFtSelection = pFeatureLayer as IFeatureSelection; //符号边线颜色 ,下边这五行设定选中面的边线,但是需要配合后边的代码执行 IRgbC

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

if(axMapControl2.LayerCount<=0) { MessageBox.Show("请加载图层后使用该功能","系统提示",MessageBoxButtons.OK,MessageBoxIcon.Warning); } else { ILayer pLayer = axMapControl2.get_Layer(0); IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer; IFeatur

ArcEngine 创建线要素图层

在创建要素图层的时候,默认的几何类型是Polygon: Dim objectClassDescription As IObjectClassDescription = New FeatureClassDescription Dim fields2 As Fields = objectClassDescription.RequiredFields 上面代码的fields2包含2个字段,一个OBJECTID字段和一个SHAPE字段,而SHAPE字段决定了要素的几何类型(GeometryType),这

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

转自原文Arcengine 实现要素选取的方法(转载) 选择一个要素或者一个要素集(FeatureSelection)的方法很多,如IMap::SelectByShape.ILayer::search.IFeatureSection::SelectFeature等方法 主要用到的方法: IMap接口的SelectFeature(Layer, Feature) (方法,从一个Layer中选择一个Feature): IMap接口SelectByShape(Shape, env, justOne) (

Dotspatial 空间要素选择

//通过遍历选择要素,获取选择要素相交的要素 private void toolStripButton43_Click(object sender, EventArgs e) { //查看与选中要素重叠的要素 if (map1.Layers.Count == 0) { return; } //重叠分析 //遍历要素,显示面积 PolygonLayer pLayer = map1.Layers[0] as PolygonLayer; FeatureSet fs = null; fs = (Feat

ArcEngine 一些实现代码

[030]?? ArcEngine 一些实现代码 ---------------------------------------------------------------------------------------------------------原文链接:http://www.cnblogs.com/alex-bn-lee/archive/2012/04/08/2437358.html ●·● 目录: A1 ………… 实现:鼠标滑过显示要素 tipA2 ………… 实现:通过鼠标选择

ArcMap按位置选择的空间选择方法

1了解目标图层与源图层 “目标”图层是从中选择要素的图层 “源”图层是这样的图层:用户要基于该图层与目标图层的空间关系,使用该图层中的要素确定应当选择的要素. 2了解选择用于所选项目的空间关系规则 图中,选中的要素用青色高亮显示,它们与红色源要素相交.接触,或者包含在红色源要素中. 相交 相交返回与源要素完全或部分重叠的要素.以下是一些示例: 返回某一距离内的要素 此运算符使用源要素周围的缓冲距离创建缓冲,并且返回所有与缓冲区域相交的要素.例如,选择距离河流或者铁路 100 米以内的城市. 以青

C#进行arcEngine开发 2

arcengine 空间分析: 目前我知道的有: 1.Geoprocessor 利用ESRI.ARCGIS.AnalysisTools中的相关工具进行clip,interset,identity操作: 以clip为例如下: string ioutPath = mlstr + xzshpstr; Geoprocessor g = new Geoprocessor(); g.OverwriteOutput = true; ESRI.ArcGIS.AnalysisTools.Clip clip = n

vs2008下如何部署arcengine开发的程序

说实话本想搞WPF+ArcEngine开发的,环境都搭建好了,突然发现貌似有很多授权的问题,唯恐部署软件后不能在其它客户端上使用,而且是项目开发,于是决定先暂时放下这个想法,待联系做研究性系统时再予以开发使用.好了,接下来我将以图解形式详细说明一下如何部署一个arcgis二次开发程序. 所需文件 首先,我先将我们所用到的文件及搭建环境要求列一下. 客户端系统环境:win xp.win7.win8 客户端系统需要安装:dotNetFx35.WindowsInstaller3.1.ArcEngine