ArcGIS Engine 编辑- ITask

简介:

转自原文ArcGIS Engine 编辑- ITask

 

下面的代码是我们定制的一个工作流-给等高线赋值

 

 

namespace EngineApplication

{

    [Guid("5b0c0692-eaf7-4d64-9cee-c8c1afaf06f4")]

    [ClassInterface(ClassInterfaceType.None)]

    [ProgId("EditeTest.ContourTask")]

 

    public class CalculateContour : ESRI.ArcGIS.Editor.IEditTask

    {

         #region

        IEditor pEngineEditor;

        IEditSketch pEditSketch;

        IEditLayers pEditLayer;

      

        #endregion

 

  

     

 

        #region "IEditTask Implementations"

        public void Activate(IEditor pEditor, ESRI.ArcGIS.Editor.IEditTask pEditTask)

        {

            if (pEditor == null)

                return;

 

            pEngineEditor = pEditor;

            pEditSketch = pEngineEditor as IEditSketch;

            pEditSketch.GeometryType = esriGeometryType.esriGeometryPolyline;

            pEditLayer = pEditSketch as IEditLayers;

 

            //Listen to engine editor events

            ((IEngineEditEvents_Event)pEditSketch).OnTargetLayerChanged += new IEngineEditEvents_OnTargetLayerChangedEventHandler(OnTargetLayerChanged);

 

            ((IEngineEditEvents_Event)pEditSketch).OnCurrentTaskChanged += new IEngineEditEvents_OnCurrentTaskChangedEventHandler(OnCurrentTaskChanged);

        }

 

        public void Deactivate()

        {

            // TODO: Add ArcGISClass1.Deactivate implementation

 

            pEditSketch.RefreshSketch();

 

            //Stop listening to engine editor events.

            ((IEngineEditEvents_Event)pEditSketch).OnTargetLayerChanged -= OnTargetLayerChanged;

 

            ((IEngineEditEvents_Event)pEditSketch).OnCurrentTaskChanged -= OnCurrentTaskChanged;

 

            //Release object references.

            pEngineEditor = null;

            pEditSketch = null;

            pEditLayer = null;

        }

 

        public string Name

        {

            get

            {

                // TODO: Add ArcGISClass1.Name getter implementation

                return "ContourTask";

            }

        }

        public string UniqueName

        {

            get

            {

                return "ContourTask";

            }

        }

 

        public string GroupName

        {

            get

            {

                //This property allows groups to be created/used in the EngineEditTaskToolControl treeview.

                //If an empty string is supplied the task will be appear in an "Other Tasks" group.

                //In this example the Reshape Polyline_CSharp task will appear in the existing Modify Tasks group.

                return "Other Tasks";

            }

        }

 

        public void OnDeleteSketch()

        {

            // TODO: Add ArcGISClass1.OnDeleteSketch implementation

        }

 

        public void OnFinishSketch()

        {

            // TODO: Add ArcGISClass1.OnFinishSketch implementation

 

            //get reference to featurelayer being edited

            IFeatureLayer pFeatureLayer = pEditLayer.CurrentLayer as IFeatureLayer;

            //get reference to the sketch geometry

            IGeometry pPolyline = pEditSketch.Geometry;

 

            if (pPolyline.IsEmpty == false)

            {

                ParaSetting pFormSetting = new ParaSetting(pFeatureLayer.FeatureClass);

 

                pFormSetting.ShowDialog();

 

 

                if (pFormSetting.DialogResult == DialogResult.OK)

                {

                    pHeightName = pFormSetting.pFieldNames.Text;

 

                    pHeight = Convert.ToDouble(pFormSetting.dHeight.Text);

 

                    pInterval = Convert.ToDouble(pFormSetting.dInterval.Text);

 

                    pFormSetting.Dispose();

 

                    pFormSetting = null;

 

                    IFeatureCursor pFeatureCursor = GetFeatureCursor(pPolyline, pFeatureLayer.FeatureClass);

 

                    CalculateIntersect(pFeatureCursor, pPolyline);

 

                    MessageBox.Show("OK");

                }

 

 

            }

 

            //refresh the display

            IActiveView pActiveView = pEngineEditor.Map as IActiveView;

            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, (object)pFeatureLayer, pActiveView.Extent);

 

        }

 

        private IFeatureCursor GetFeatureCursor(IGeometry pGeometry, IFeatureClass pFeatureClass)

        {

 

            //空间过虑器的创建

            ISpatialFilter pSpatialFilter = new SpatialFilter();

            pSpatialFilter.Geometry = pGeometry;

            //空间过虑器几何体实体

            //空间过虑器参照系

 

            //空间过虑器空间数据字段名

            pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;

            //空间过虑器空间关系类型

            pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

            //相交

            IFeatureCursor pFeatureCursor = pFeatureClass.Search(pSpatialFilter, false);

 

            return pFeatureCursor;

 

 

        }

 

        //起始等高线值

        private double pHeight;

        //等高线间距

        private double pInterval;

        //高程字段名

        private string pHeightName;

 

 

 

        private void CalculateIntersect(IFeatureCursor pFeatureCursor, IGeometry Geometry)

        {

 

 

            //要素游标

            IMultipoint pIntersectionPoints = null;

            //多点

            IPointCollection pPointColl = null;

 

            List<IFeature> pFeatureList = new List<IFeature>();

            //和直线相交的要素集合,未排序

            double[,] pIndex = null;

            //距离和初始索引

 

 

            if (pFeatureCursor == null)

            {

                return;

            }

            ITopologicalOperator pTopoOperator = Geometry as ITopologicalOperator;

 

            IPointCollection pSketchPointColl = Geometry as IPointCollection;

            //所画直线的起点

            IPoint P0 = pSketchPointColl.get_Point(0);

            IFeature pFeature = pFeatureCursor.NextFeature();

            double HValue = 0;

            int FldIndex = 0;

            pFeatureList.Clear();

            while ((pFeature != null))

            {

                //和直线相交的要素集合

                pFeatureList.Add(pFeature);

                //

                pFeature = pFeatureCursor.NextFeature();

            }

            //此时pFeatureL中的等值线并不是按顺序(空间)排列,需要排序

            //求出各交点到直线起点距离

            int pCount = pFeatureList.Count;

            pIndex = new double[2, pCount];

            for (int i = 0; i <= pCount - 1; i++)

            {

                try

                {

                    pFeature = pFeatureList[i];

                    //求交点:

                    pIntersectionPoints = pTopoOperator.Intersect(pFeature.Shape, esriGeometryDimension.esriGeometry0Dimension) as IMultipoint;

 

                    pPointColl = pIntersectionPoints as IPointCollection;

                    //QI

                    //原来序号

                    pIndex[0, i] = i;

                    //距离

                    pIndex[1, i] = GetDistace(P0, pPointColl.get_Point(0));

                    //下个要素

                    pFeature = pFeatureCursor.NextFeature();

                }

                catch (Exception e)

                {

                    MessageBox.Show(e.ToString());

                }

            }

            //排序:将和直线相交的等直线按与起点的距离排序,冒泡法

            for (int i = 0; i <= pCount - 1; i++)

            {

                for (int j = i + 1; j <= pCount - 1; j++)

                {

                    if (pIndex[1, j] < pIndex[1, i])

                    {

                        double pTempindex = pIndex[0, i];

                        pIndex[0, i] = pIndex[0, j];

                        pIndex[0, j] = pTempindex;

                        //交换索引

                        double pTemp = pIndex[1, i];

 

                        pIndex[1, i] = pIndex[1, j];

 

                        pIndex[1, j] = pTemp;

                        //交换距离

                    }

                }

            }

            //开始高程赋值

            HValue = pHeight;

            try

            {

                for (int i = 0; i <= pCount - 1; i++)

                {

                    pFeature = pFeatureList[i];

                    //获取高程字段的索引

                    FldIndex = pFeature.Fields.FindField(pHeightName);

                    //高程赋值

                    pFeature.set_Value(FldIndex, HValue as object);

                    //要素更新

                    pFeature.Store();

                    //Get the next feature and next H

                    HValue = HValue + pInterval;

                }

 

            }

            catch (Exception e)

            {

 

 

                MessageBox.Show(e.ToString());

            }

        }

 

        /// <summary>

        /// 获取我们画的线和等高线之间的距离

        /// </summary>

        /// <param name="pPoint1"></param>

        /// <param name="pPoint2"></param>

        /// <returns></returns>

        private double GetDistace(IPoint pPoint1, IPoint pPoint2)

        {

            return (pPoint1.X - pPoint2.X) * (pPoint1.X - pPoint2.X) + (pPoint1.Y - pPoint2.Y) * (pPoint1.Y - pPoint2.Y);

        }

 

        #endregion

 

        public void OnTargetLayerChanged()

        {

            PerformSketchToolEnabledChecks();

        }

 

 

 

        void OnCurrentTaskChanged()

        {

            if (pEngineEditor.CurrentTask.Name == "CalculateContourTask")

            {

                PerformSketchToolEnabledChecks();

            }

        }

 

        private void PerformSketchToolEnabledChecks()

        {

            if (pEditLayer == null)

                return;

 

            //Only enable the sketch tool if there is a polyline target layer.

            if (pEditLayer.CurrentLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolyline)

            {

                pEditSketch.GeometryType = esriGeometryType.esriGeometryNull;

                return;

            }

 

 

            pEditSketch.GeometryType = esriGeometryType.esriGeometryPolyline;

 

        }

 

    }

}

 

效果如下:

 

task2

 

没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。






    本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/arxive/p/6262948.html ,如需转载请自行联系原作者
相关文章
|
存储 C语言
ArcGIS:Excel/Txt 文件生成点图层、属性表编辑的基本方法、属性表之间的连接(合并)和关联的操作、属性表的字段计算器的使用
ArcGIS:Excel/Txt 文件生成点图层、属性表编辑的基本方法、属性表之间的连接(合并)和关联的操作、属性表的字段计算器的使用
339 0
|
定位技术
ArcGIS:如何对Shapefile文件进行符号系统修改、标注、合并、分割、拓扑编辑等?
ArcGIS:如何对Shapefile文件进行符号系统修改、标注、合并、分割、拓扑编辑等?
673 0
|
7月前
|
人工智能 编解码 定位技术
ArcGIS导出AI或EPS格式的地图图片并在Adobe Illustrator中继续编辑
ArcGIS导出AI或EPS格式的地图图片并在Adobe Illustrator中继续编辑
327 1
|
7月前
|
定位技术
ArcGIS中各版本ArcMap安装OpenStreetMap编辑工具集插件ArcGIS Editor for OSM
ArcGIS中各版本ArcMap安装OpenStreetMap编辑工具集插件ArcGIS Editor for OSM
206 1
|
定位技术 索引
ArcGIS数据编辑1 新要素的创建
🏆在本文中,作者讲解了ArcGIS要素创建了全流程,从面要素到线要素,分别以不同的方法补全了道路的缺失部分
260 0
|
SQL 开发框架 数据可视化
ArcGIS Engine学习系列1 AE基础介绍
市面上AE教程大致到ArcGIS10.2,ESRI宣布从ArcGIS10.5开始便停止AE的更新,使用AO做开发,初学者可以在学习C#语言后,从AE入门,逐渐过度到AO。不同版本下AE数据类型数量Enums:枚举类型,用于实现一些定义的内容Structs:结构体Interfaces:接口Classes:类AE开发中,为了更好地管理COM对象,ESRI将这些COM对象放到不同的组件库中。
302 0
|
Web App开发 JavaScript 前端开发
|
定位技术
ArcGIS Engine中的Symbols详解
本文由本人翻译ESRI官方帮助文档。尊重劳动成果,转载请注明来源。 Symbols     ArcObjects用了三种类型的Symbol(符号样式)来绘制图形特征:marker symbols(标记符号),line symbols(线符号),和fill symbols(填充符号)。
911 0
|
定位技术 C# C++
VC2010+ArcGIS Engine 10.1 开发(一)
                      使用MFC(VS2010)开发ArcGIS Engine 10.1 网上C#结合ArcGIS Engine的资料简直太多了,多的都无法形容,但是C++的却很少,前一段时间不断的有人问在VC中如何开发ArcGI...
1110 0
|
C# 定位技术
VC2010+ArcGIS Engine 10.1 开发(二)
采用ActiveX控件插入的方式 上面我们是通过代码直接将地图控件放到界面上,这种有一个不好的地方就是,如果我们要设置控件的一些样式和视觉效果,我们要自己写很多代码,在C#中我们就很容易,其实在VC中也可以采用这种方式,下来我介绍下: 插入控件 在Vi...
848 0