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

 

转载于:https://www.cnblogs.com/arxive/p/6262948.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/402330.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Linux 系统应用编程——网络编程(TCP 协议三次握手过程)

TCP(Transmission Control Protocol) 传输控制协议 TCP是主机对主机层的传输控制协议&#xff0c;提供可靠的连接服务&#xff0c;采用三次握手确认建立一个连接: 位码即tcp标志位,有6种标示: SYN ( synchronous 建立联机 ) ACK ( acknowledgement 确认 ) PSH ( push 传送…

知识管理在客户关系管理中的应用领域

CRM中的知识获取 CRM前端业务系统&#xff08;包括销售管理、营销管理、客户服务三个模块&#xff09;为与客户互动、获取客户知识提供了各种途径&#xff0c;如销售自动化系统、电子商务网站、呼叫中心、网络社区、博客等等&#xff0c;另外&#xff0c;企业还直接从外部环境、…

基于ELK的简单数据分析

原文链接&#xff1a; http://www.open-open.com/lib/view/open1455673846058.html 环境 CentOS 6.5 64位JDK 1.8.0_20Elasticsearch 1.7.3LogStash 1.5.6Kibana 4.1.4介绍 ElasticSearch是有名的开源搜索引擎&#xff0c;现在很多公司使用ELK技术栈做日志分析&#xff0c;比如…

Linux 系统应用编程——网络编程(高级篇)

一、网络超时检测 在网络通信过程中&#xff0c;经常会出现不可预知的各种情况。例如网络线路突发故障、通信一方异常结束等。一旦出现上述情况&#xff0c;很可能长时间都不会收到数据&#xff0c;而且无法判断是没有数据还是数据无法到达。如果使用的是TCP协议&#xff0c;可…

[win10] 在桌面上显示计算机、控制面板、网络

1. 右击桌面&#xff0c;选择个性化 2. 选择”主题", 点击“桌面图标设置” 3. 把想要放桌面的图标给钩上

linux下共享文件夹(windows可访问,linux也可访问)

2019独角兽企业重金招聘Python工程师标准>>> 本文是转字网上的两段&#xff0c;如果是菜鸟&#xff0c;想懂有点难度&#xff0c;我这里给点注释 在linux上共享文件夹windows下看 ******************************************* 首先给linux设一个ip&#xff0c;要和…

用nginx做了一下反向代理,得到的ip地址都是127.0.0.1

nginx反向代理配置时&#xff0c;一般会添加下面的配置&#xff1a; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; loc…

【windows】 设置开机启动程序

开始 -> 运行&#xff0c;输入&#xff1a;shell:startup 将要启动的“快捷方式”放入此目录下。重启生效&#xff01;

ssh时,密码输入框(密码输入提示)很晚才出现的解决方法

新配置了一台server&#xff08;centos6.2&#xff09;&#xff0c;发现从windows使用putty登录时&#xff0c;在输入用户名后总是很慢才提示输入密码[rootFDFS-1 ~]# ssh -V OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010发现ssh的版本较高了使用另一台linux服务器连接&…

Linux time()函数解析

time() 函数语法如下&#xff1a; 所需头文件#include <time.h>函数原型time_t time(time_t * timer)参数说明timerNULL时得到机器日历时间&#xff1b; timer时间数值时&#xff0c;用于设置日历时间&#xff1b;函数返回值机器日历时间 功能: 获取当前的系统时间&#…

开源|LightGBM:三天内收获GitHub 1000+ 星

原创 2017-01-05 LightGBM 微软研究院AI头条【导读】不久前微软DMTK(分布式机器学习工具包)团队在GitHub上开源了性能超越其他boosting工具的LightGBM&#xff0c;在三天之内GitHub上被star了1000次&#xff0c;fork了200次。知乎上有近千人关注“如何看待微软开源的LightGBM&a…

【phpstudy】在windows上开启后访问php页面显示502

phpstudy在windows上安装好后&#xff0c;会默认创建一个网站&#xff0c;而且使用了php7.3.4版本&#xff0c;但是当你把这个网站删除&#xff0c;再自己去手动(不利用它这个工具)创建一个php网站&#xff0c;会发现访问php页面会出现502错误&#xff0c;纠其原因&#xff0c;…

重设MYSQL数据库ROOT用户的密码

一、 在已知MYSQL数据库的ROOT用户密码的情况下&#xff0c;修改密码的方法&#xff1a;1、 在SHELL环境下&#xff0c;使用mysqladmin命令设置&#xff1a;mysqladmin –u root –p password “新密码” 回车后要求输入旧密码2、 在mysql>环境中,使用update命令&#xff0c…

Linux---进程调度相关命令解析

进程相关命令 1、ps 查看系统中的进程 使用方式&#xff1a;ps [options] [--help] 说明&#xff1a;显示瞬间进程 (process) 的动态 参数&#xff1a;ps的参数非常多, 在此仅列出几个常用的参数并大略介绍含义 ps命令常用用法&#xff08;方便查看系统进程&#xff09; 1&a…

随机数的扩展--等概率随机函数的实现

【转载】 Hackbuteer1的专栏 思想&#xff1a;就是先生成范围足够容纳扩展后随机数的一个随机数&#xff0c;然后忽略扩展过头的部分。 比如&#xff0c;已知random_n&#xff0c;要求random_m&#xff0c;最简单方法可以先生成random_n2()n*(random_n()-1)random_n(); 至于怎么…

js前台数据校验

1.脚本 Validator {exp:{numWord:/^[A-Za-z0-9]$/, //数字或字母numWordM:/^[\-]*[A-Za-z0-9]$/, //数字或字母可为负数letter:/^[A-Za-z]$/, //字母chinese:/^[\u4E00-\u9FA5\uF900-\uFA2D]$/,numberReg:/^[0-9]$/,//数字格式 只能是0到9的数字 eg:92wordReg:/^(\w|[\u4E00-\…

Linux 系统应用编程——多线程经典问题(生产者-消费者)

“生产者——消费者”问题是Linux多线程编程中的经典问题&#xff0c;主要是利用信号量处理线程间的同步和互斥问题。 “生产者——消费者”问题描述如下&#xff1a; 有一个有限缓冲区&#xff08;这里用有名管道实现 FIFO 式缓冲区&#xff09;和两个线程&#xff1a;生产者和…

Linux 文件服务---------- nfs Server

Linux 文件服务nfs &#xff08;Network file system&#xff09;#网络文件系统 ---> 远程文件调用samba #文件共享&#xff08;unix /linux /windows &#xff09; ,只能适用于局域网。ftp #远程文件存取.(跨网络&#xff0c; 跨平台&#xff0c; 文件存取)。 nfs Server r…

VC命令行编译参数介绍

From: http://blog.csdn.net/zhangxinrun/article/details/5797122 CL.exe是控制Microsoft C和C编译器与链接器的32位工具。编译器产生通用对象文件格式(COFF)对象(.obj)文件。链接器产生可执行文件(.exe)或动态链接库文件(DLL)。 注意&#xff0c;所有编译器选项都区分大小写。…

在linux 5上配置戴尔MD3220i

http://zh.community.dell.com/techcenter/storage/f/150/t/2773.aspx转载于:https://blog.51cto.com/xs2013/1298568