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的更多相关文章
- ArcGIS Engine 编辑介绍
转自原文 ArcGIS Engine 编辑介绍 IWorkspaceEdit接口是ArcGIS Engine 实现空间数据编辑的重要接口,它让程序启动或者停止一个编辑流程,在这个编辑流程内,可以对数据 ...
- ArcGIS Engine 编辑- IWorkspaceEdit
转自原文 ArcGIS Engine 编辑- IWorkspaceEdit 这个例子中,我创建了1000条要素,并结合缓冲将数据写到文件中,并且添加了时间统计,当然数据是我捏造的,还请原谅,这个花费的 ...
- ArcGIS Engine 中的绘制与编辑
1.线段绘制 基本步骤 构建形状 1. 创建 IPoint IPoint m_Point = new PointClass(); m_Point.PutCoords(x, y); 2. 创建 IPoi ...
- ArcGIS Engine开发之地图基本操作(4)
ArcGIS Engine开发中数据库的加载 1.加载个人地理数据库数据 个人地理数据库(Personal Geodatabase)使用Miscrosoft Access文件(*.mdb)进行空间数据 ...
- ArcGIS Engine开发前基础知识(1)
ArcGIS二次开发是当前gis领域的一项重要必不可少的技能.下面介绍它的基本功能 一.ArcGIS Engine功能 在使用之前首先安装和部署arcgis sdk,(在这里不在赘述相关知识)可以实现 ...
- 转-ArcGIS Engine许可初始化
关于初始化Engine许可的,其实原理都很简单,大家一般都没有问题,但又往往会因为不够细心加上Engine的“小脾气”,让不少程序员都要在这里犯错. 以Engine9.2为例,应用程序是强制初始化许可 ...
- 转-ArcGIS Engine中的License设置
AE开发中的License有两种方法进行设置,一种是通过LicenseControl控件,另一种是通过IAoInitialize接口设置.整个应用程序中只能有一种方式存在,如果进行了两种License ...
- ArcGIS Engine中的8种数据访问 (转)
数据是GIS的基础, 访问数据也是进行任何复杂的空间分析及空间可视化表达的前提.ArcGIS支持的数据格式比较丰富,对不同的数据格式支持的程度也有很大差异.本文主要介绍一下以下八种数据格式在ArcGI ...
- ArcGIS Engine中的数据访问
ArcGIS Engine中的数据访问 数据是GIS的基础, 访问数据也是进行任何复杂的空间分析及空间可视化表达的前提.ArcGIS支持的数据格式比较丰富,对不同的数据格式支持的程度也有很大差异.本文 ...
随机推荐
- [ Tomcat ] [ startup ] Tomcat 無法在時限內開啟問題
http://www.ewdna.com/2011/12/tomcat-server-in-eclipse-unable-to.html
- vue中v-for的用法以及参数的作用
<template> <div> <div class="content clearfix" v-on:click="goorderingD ...
- 7.3 GROUP BY的“新”功能
7.3 GROUP BY的"新"功能正在更新内容,请稍后
- 2.lombok系列2:lombok注解详解
转自:https://www.imooc.com/article/18157 开篇 看到第一篇<初识lombok>你可能意犹未尽,本文我们按照场景来介绍一下常用的注解. 未特别说明,均标注 ...
- Spark SQL概念学习系列之Spark SQL基本原理
Spark SQL基本原理 1.Spark SQL模块划分 2.Spark SQL架构--catalyst设计图 3.Spark SQL运行架构 4.Hive兼容性 1.Spark SQL模块划分 S ...
- 1.8 Python基础知识 - 数值类型
一.int类型(任意精度整数) 整型类型(int)是表示整数的数据类型.与其他计算机语言有精度限制不同,Python的整数位数可以为任意长度位数(只受限制于计算机内存) 数字字符串即整型常量. pyt ...
- JS截取字符串 charAt(),slice(),substring(),substr()
1. charAt(i)输出指定下标的字母,长度为1,适用于把字符串切割成单个字符串. 2. slice() 和 substring() 都支持1-2个参数,第一个参数是开始位置,第二个参数是结束位置 ...
- 关于python的序列和矩阵运算的写法
#其实下面是这样一个函数,传入的是obj_value,传出的是newobj_value.,, #这里的obj_value实际上是一个序列... for z in obj_value: ...
- VUE错误记录 - 品牌后台练习 search(); 数组 splice forEach push 箭头函数
methods:{ add(){ var car = { id: this.id, name: this.name, ctime: new Date()}; this.list.push(car); ...
- vb.net 调用api
Public Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Integer) ...