Convert part to feature command


// Copyright 2010 ESRI// // All rights reserved under the copyright laws of the United States// and applicable international laws, treaties, and conventions.// // You may freely redistribute and use this sample code, with or// without modification, provided you include the original copyright// notice and use restrictions.// // See the use restrictions at <your ArcGIS install location>/DeveloperKit10.0/userestrictions.txt.// using System;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Editor;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem; namespace Convert_Part_To_FeatureCS
{
/// <summary>/// The command must be in the edit sketch context menu /// and converts a selected part to its own feature./// </summary>
[Guid("f766682c-3a1c-4b97-8354-af3c12706e1f")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("Convert_Part_To_FeatureCS.ConvertPart")]
publicsealedclass ConvertPart : BaseCommand
{
#region ArcGIS Component Category Registrar generated code
/// <summary>/// Required method for ArcGIS Component Category registration -/// Do not modify the contents of this method with the code editor./// </summary>privatestaticvoid ArcGISCategoryRegistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
SketchMenuCommands.Register(regKey); }
/// <summary>/// Required method for ArcGIS Component Category unregistration -/// Do not modify the contents of this method with the code editor./// </summary>privatestaticvoid ArcGISCategoryUnregistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
SketchMenuCommands.Unregister(regKey); } #endregion#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
staticvoid RegisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType);
} [ComUnregisterFunction()]
[ComVisible(false)]
staticvoid UnregisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType);
}
#endregionprivate IApplication m_application; public ConvertPart()
{
base.m_category = "Developer Samples";
base.m_caption = "Convert Part to Feature";
base.m_message = "Command must be run from Edit Sketch Context Menu only";
base.m_toolTip = "Creates a new feature from a part";
base.m_name = "Convert Part to Feature";
} public IEditor m_editor;
public IEditSketch m_editSketch;
public IFeatureClass featureClass;
public IMap map = new Map(); #region Overriden Class Methods /// <param name="hook">Instance of the application</param>publicoverridevoid OnCreate(object hook)
{
if (hook == null)
return; m_application = hook as IApplication;
if (m_application == null)
return; UID uID = new UID();
uID.Value = "esriEditor.Editor";
m_editor = m_application.FindExtensionByCLSID(uID) as IEditor; if (m_editor == null)
return; m_editSketch = m_editor as IEditSketch;
}
/// <summary>/// Command Enabled called to determine enable status./// </summary>publicoverridebool Enabled
{
get
{
if (m_editor == null)
returnfalse; if (!m_editSketch.Geometry.IsEmpty && m_editor.SelectionCount == 1)
{
returntrue;
}
else
{
returnfalse;
}
}
}
/// <summary>/// After enabling the edit sketch of a multipart feature right click on the part to be converted and/// select Convert Part to Feature, to make the part it's own feature./// </summary>publicoverridevoid OnClick()
{
IActiveView activeView; if (m_editor == null)
return; m_editor.StartOperation(); //if the sketch only has one part to begin with - exit.
IGeometryCollection geometryCollection = m_editSketch.Geometry as IGeometryCollection;
{
if (geometryCollection.GeometryCount == 1)
{
return;
} //get the part, this is the one the user right-clicked on.int Part = m_editSketch.Part; IEnumFeature enumFeature = m_editor.EditSelection;
enumFeature.Reset(); IFeature origFeature = enumFeature.Next(); if (origFeature == null)
{
m_editor.AbortOperation();
return;
} featureClass = origFeature.Class as IFeatureClass;
IFeature newFeature = featureClass.CreateFeature(); geometryCollection = origFeature.Shape as IGeometryCollection;
IGeometry origPartGeometry = geometryCollection.get_Geometry(Part); //delete the original part.
geometryCollection.RemoveGeometries(Part, 1);
geometryCollection.GeometriesChanged();
origFeature.Shape = geometryCollection as IGeometry;
origFeature.Store(); //check the type of geometry.
IPolygon polygon = new PolygonClass();
IPolyline polyline = new PolylineClass();
IMultipoint multiPoint = new MultipointClass();
object Missing = Type.Missing; //make sure the new geometry is z aware, set a flag for later use.
IGeometryDef fcGeoDef = CheckZGeometryDef(featureClass);
//if the feature class is z aware set the flag to true.
Boolean isZAware = true;
IZAware zAware;
if (fcGeoDef.HasZ == false)
{
isZAware = false;
}
switch (origPartGeometry.GeometryType)
{
case esriGeometryType.esriGeometryRing:
if (isZAware == true)
{
zAware = polygon as IZAware;
zAware.ZAware = true;
}
geometryCollection = polygon as IGeometryCollection;
geometryCollection.AddGeometry
(origPartGeometry, ref Missing, ref Missing);
break; case esriGeometryType.esriGeometryPath:
if (isZAware == true)
{
zAware = polyline as IZAware;
zAware.ZAware = true;
}
geometryCollection = polyline as IGeometryCollection;
geometryCollection.AddGeometry
(origPartGeometry, ref Missing, ref Missing);
break; case esriGeometryType.esriGeometryPoint:
if (isZAware == true)
{
zAware = multiPoint as IZAware;
zAware.ZAware = true;
}
geometryCollection = multiPoint as IGeometryCollection;
geometryCollection.AddGeometry
(origPartGeometry, ref Missing, ref Missing);
break; default:
m_editor.AbortOperation();
break;
} newFeature.Shape = geometryCollection as IGeometry; //copy the attributes of the orig feature the new feature.
IField field = new FieldClass();
IFields fields = origFeature.Fields; //skip OID and geometry.for (int fieldCount = 0; fieldCount < fields.FieldCount; fieldCount++)
{
field = fields.get_Field(fieldCount); if ((field.Type != esriFieldType.esriFieldTypeGeometry) &&
(field.Type != esriFieldType.esriFieldTypeOID) && field.Editable)
{
newFeature.set_Value(fieldCount, origFeature.get_Value(fieldCount));
}
} newFeature.Store(); m_editor.StopOperation("Convert Part to Feature"); //refresh map according to old and new selections.
activeView = m_editor.Map as IActiveView;
activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
m_editor.Map.ClearSelection(); ILayer featLayer = GetFeatureLayer(newFeature);
if (featLayer == null)
return; m_editor.Map.SelectFeature(featLayer, newFeature);
activeView.PartialRefresh
(esriViewDrawPhase.esriViewGeoSelection, null, null);
}
}
//}/// <summary>/// Function to obtain the feature layer from the selected feature./// </summary>public ILayer GetFeatureLayer(IFeature feature)
{
if (feature == null)
returnnull; map = m_editor.Map; featureClass = feature.Class as IFeatureClass; for (int layerCount = 0; layerCount < map.LayerCount; layerCount++)
{
// Search the layers for the layer in question and get the name.if (featureClass.AliasName == map.get_Layer(layerCount).Name)
{
return map.get_Layer(layerCount);
}
}
returnnull;
} public IGeometryDef CheckZGeometryDef(IFeatureClass featureClass)
{
string shapeFieldName = featureClass.ShapeFieldName;
IFields fields = featureClass.Fields;
int geometryIndex = fields.FindField(shapeFieldName);
IField field = fields.get_Field(geometryIndex);
IGeometryDef geometryDef = field.GeometryDef;
return geometryDef;
}
}
}
#endregion
Convert part to feature command的更多相关文章
- arcmap Command
The information in this document is useful if you are trying to programmatically find a built-in com ...
- Character Sets: Migrating to utf8mb4 with pt_online_schema_change
David Berube | June 12, 2018 | Posted In: MySQL Modern applications often feature the use of data ...
- Sublime Text编辑器的12个技巧和诀窍
本文为您提供Sublime Text编辑器的12个技巧和诀窍,深入挖掘这个看似简洁的代码编辑器,背后所隐藏的实现各种高级功能的无限可能. 1) 选择 以下是一些Sublime Text选择文本的快捷键 ...
- Sublime Text实用小技巧
1.输入"!"或"html:5",然后按Tab键: html:5 或!:用于HTML5文档类型 html:xt:用于XHTML过渡文档类型 html:4s:用于 ...
- 12个不可不知的Sublime Text应用技巧和诀窍
本文为您提供Sublime Text编辑器的12个技巧和诀窍,深入挖掘这个看似简洁的代码编辑器,背后所隐藏的实现各种高级功能的无限可能. 1) 选择 以下是一些Sublime Text选择文本的快捷键 ...
- 十三、EnterpriseFrameWork框架核心类库之数据库操作(多数据库事务处理)
本章介绍框架中封装的数据库操作的一些功能,在实现的过程中费了不少心思,针对不同数据库的操作(SQLServer.Oracle.DB2)这方面还是比较简单的,用工厂模式就能很好解决,反而是在多数据库同时 ...
- The mean shift clustering algorithm
The mean shift clustering algorithm MEAN SHIFT CLUSTERING Mean shift clustering is a general non-par ...
- im4java开发向导
0.搜索ImageMagick下载安装 1.Setting up the Environment 引入im4java到classpath 设置图片处理引擎的command searchpa ...
- 【转】MUD教程--巫师入门教程4
我们再次复习一下clean_up()函数返回1的含义,如果clean_up()函数返回1,则MUDOS在这一次的调用时不会做其的任何举动,但到了下一次想调用的时间里,还将再次调用这个对象的clean_ ...
随机推荐
- 类或方法名后加<>
声明类型为泛型. 说明传递的参数为泛型,而不仅仅是一种类型. public void aa<T>(T a) { Console.WriteLine(a); } 调用时可写: this.aa ...
- transition & transform
transition: 过渡时间 被改变属性 执行函数 延迟时间 transition:width 1s,height 2s 1s; transform: 平移(translate).缩放(scale ...
- 基于MSP430F413水果电池供电的低功耗时钟
我最早接触MSP430时候,看到书的第一页就是一张水果电池的图片,一直以来想做一个低功耗的可以水果电池供电的系统,毕业之后的下半年选择MSP430F413单片机来画了一个低功耗的板子,一直没有调试 ...
- `cocos2dx非完整` 游戏架构缩影 添加启动流程
这期的话题可能不是很好, 我没有想到很好的词句去更好的表达. 我一直都是很固执的认为, 同一类型的游戏,在开发做的前期工作上面其实都是可以复用的,也就是大同小异的.从游戏启动,启动日志,启动检查,检查 ...
- 爬虫技术 -- 基础学习(三)理解URL和URI的联系与区别
网络爬虫的基本操作是抓取网页.首先要了解下URL~~ 在理解URL之前,先了解下URI,这两个概念我曾经混淆过~@_@|| 什么是URI? Web上每种可用的资源,如:html文档.视频,图片等都由一 ...
- 在腾讯开发应用中心上架apk所遇到的问题
这篇只是为了记录我走过的弯路,和判断错误的方法 首先当我用 keyStore打包apk的时候,程序没有报任何错误,当然也可以运行: 接下来就是上传该apk吧: 等上传完了,就报解析错误.如下.: aa ...
- iOS-布局-Masonry-优先级
一.AutoLayout有两个重要的属性: 1.Content Compression Resistance 百度翻译(内容压缩抗力) 2.Content Hugging 百度翻译(内容拥抱) ...
- intellij 调试方法
intellij 调试方法 转自 http://www.th7.cn/Program/net/201410/296492.shtml
- redis主从遇到的两个坑
最近在使用redis主从的时候做了下面两件事情: 1 希望redis主从从操作上分析,所有写操作都在master上写,所有读操作都在从上读. 2 由于redis的从是放在本地的,所以有的key的读写操 ...
- Windows魔法堂:解决“由于启动计算机时出现页面文件配置问题.......”
一.前言 昨晚终于在VirtualBox中安装好Win7了,但在系统启动后弹出窗报“由于启动计算机时出现页面文件配置问题.......”,于是度娘一下.以下记录以供日后查阅. 二.原因 网上说的是在使 ...