转自原文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

ArcGIS Engine 编辑- ITask的更多相关文章

  1. ArcGIS Engine 编辑介绍

    转自原文 ArcGIS Engine 编辑介绍 IWorkspaceEdit接口是ArcGIS Engine 实现空间数据编辑的重要接口,它让程序启动或者停止一个编辑流程,在这个编辑流程内,可以对数据 ...

  2. ArcGIS Engine 编辑- IWorkspaceEdit

    转自原文 ArcGIS Engine 编辑- IWorkspaceEdit 这个例子中,我创建了1000条要素,并结合缓冲将数据写到文件中,并且添加了时间统计,当然数据是我捏造的,还请原谅,这个花费的 ...

  3. ArcGIS Engine 中的绘制与编辑

    1.线段绘制 基本步骤 构建形状 1. 创建 IPoint IPoint m_Point = new PointClass(); m_Point.PutCoords(x, y); 2. 创建 IPoi ...

  4. ArcGIS Engine开发之地图基本操作(4)

    ArcGIS Engine开发中数据库的加载 1.加载个人地理数据库数据 个人地理数据库(Personal Geodatabase)使用Miscrosoft Access文件(*.mdb)进行空间数据 ...

  5. ArcGIS Engine开发前基础知识(1)

    ArcGIS二次开发是当前gis领域的一项重要必不可少的技能.下面介绍它的基本功能 一.ArcGIS Engine功能 在使用之前首先安装和部署arcgis sdk,(在这里不在赘述相关知识)可以实现 ...

  6. 转-ArcGIS Engine许可初始化

    关于初始化Engine许可的,其实原理都很简单,大家一般都没有问题,但又往往会因为不够细心加上Engine的“小脾气”,让不少程序员都要在这里犯错. 以Engine9.2为例,应用程序是强制初始化许可 ...

  7. 转-ArcGIS Engine中的License设置

    AE开发中的License有两种方法进行设置,一种是通过LicenseControl控件,另一种是通过IAoInitialize接口设置.整个应用程序中只能有一种方式存在,如果进行了两种License ...

  8. ArcGIS Engine中的8种数据访问 (转)

    数据是GIS的基础, 访问数据也是进行任何复杂的空间分析及空间可视化表达的前提.ArcGIS支持的数据格式比较丰富,对不同的数据格式支持的程度也有很大差异.本文主要介绍一下以下八种数据格式在ArcGI ...

  9. ArcGIS Engine中的数据访问

    ArcGIS Engine中的数据访问 数据是GIS的基础, 访问数据也是进行任何复杂的空间分析及空间可视化表达的前提.ArcGIS支持的数据格式比较丰富,对不同的数据格式支持的程度也有很大差异.本文 ...

随机推荐

  1. 自定义控件学习——下拉刷新ListView

    效果 开始用Android Studio写了,还有挺多不明白这IDE用法的地方....蛋疼 主要思路 1. 添加了自定义的头布局    2. 默认让头布局隐藏setPadding.设置 -自身的高度  ...

  2. $routeParams 实现路由指定参数

    [摘要]后台管理系统权限控制到按钮级别,将每一个资源的key绑定在url中,渲染页面的时候去根据key来获取当前页面的按钮列表. router.js angular.module("app. ...

  3. System and method for controlling switching between VMM and VM using enabling value of VMM timer indicator and VMM timer value having a specified time

    In one embodiment, a method includes transitioning control to a virtual machine (VM) from a virtual ...

  4. Android实现点击通知栏后,先启动应用再打开目标Activity

    情况简述 在开发Android app的过程中,遇到这样一个需求:app中启动一个Service,该Service在独立进程中运行,与服务器保持长连接,将服务器推送过来的消息在通知栏中显示,并设置点击 ...

  5. matlab 辅助函数 —— 文件下载与文件解压

    0. 可读性的提升 为了提升代码的交互友好性,可在代码执行一些耗时操作时,显示地输出一些文本信息,以显示进度: fprintf('Downloading xxfilename...\n') urlwr ...

  6. Cocos2d 游戏状态机

    加cocos2d 是标题党. 事实上跟cocos2d无关. 1.游戏背景介绍 比方有这么一个"记忆"类的比赛游戏.你和电脑对战.轮到谁的回合,谁翻两张牌.假设两张牌一样,就消掉这两 ...

  7. Python内部机制-PyObject对象

    PyObject对象机制的基石 学过Python的人应该非常清晰,Python中一切都是对象,全部的对象都有一个共同的基类,对于本篇博文来说,一切皆是对象则是探索Python的对象机制的一个入口点.我 ...

  8. Playing with coroutines and Qt

    你好!我最近想知道C ++中的协程的状态,我发现了几个实现.我决定选择一个用于我的实验.它简单易用,适用于Linux和Windows. 我的目标是试图找到一种方法来让代码异步运行,而不必等待信号触发插 ...

  9. wepy小程序实现列表分页上拉加载(1)

    使用wepy开发微信小程序商城第一篇:项目初始化 使用wepy开发微信小程序商城第二篇:路由配置和页面结构 列表页效果图: 1.新建列表页 (1)在pages里面新建一个list.wpy文件 初始代码 ...

  10. Mac 环境下svn服务器的配置

    Mac 环境下svn服务器的配置 本文目录 • 一.创建代码仓库,用来存储客户端所上传的代码 • 二.配置svn的用户权限 • 三.使用svn客户端功能 在Windows环境中,我们一般使用Torto ...