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_ ...
随机推荐
- toad 常用快捷键与配置
F8 调出以前执行的sql命令 F9 执行全部sql Ctrl+. 补全table_name Ctrl+t 补全table_name,或者显示字段 alt+ 箭头上下 看sql history Ctr ...
- angularjs + seajs构建Web Form前端(三) -- 兼容easyui
回顾 在上一章中使用了angular实现了ajax form和树形结构,经过以上两章对于angular的大致使用,对于angular也有了初步的认识,接下来的内容只会对angular的一些用法做简单的 ...
- 我的第一个Socket程序-SuperSocket使用入门(三)
本来博客都停了,不打算更了,但今天百度一个socket的问题时无意间发现第一篇的socket文章权重仅次于SuperSocket网站,顿时觉得自己6到不行,再写一篇,讨论下数据持久化的问题 去年搞那个 ...
- annotation:@Override出现The method of type must override asuperclass解决方案
原因追踪及解决办法: 1. 查阅资料发现说在jdk1.5下要使用@Override这个annotation必须保证被标注的方法来源于class而不是interface. 2. 即使自己的jdk是1.6 ...
- ServiceStack 介绍
关于ServiceStack ServiceStack 官网介绍: Opensource .NET and Mono REST Web Services framework 什么是 ServiceSt ...
- Rpath handling on Linux
The solution in the article below seems promising: http://www.blaenkdenum.com/notes/cmake/#rpath set ...
- 【转载】Linux下编辑生成.mo文件
转载自:http://www.hackbase.com/tech/2012-02-27/65972.html 编辑生成.mo文件 我们在弄网站的时候很可能会接触到.mo和.po文件..po文件是GNU ...
- [Perl]抓取个人的所有闪存+格式化保存为文本
以下代码保存为utf8文本格式 环境:ActivePerl v5.16 built for MSWin32-x86 两个要调整的地方: for my $i (17..45) { 这里改成自己对应的页 ...
- Linq查询操作之Where筛选
筛选操作where能够处理逻辑运算符组成的逻辑表达式.比如逻辑“与”,逻辑“或”,并从数据源中筛选数据,它和where子句的功能非常相似.Enumerable类的Where()原型如下: public ...
- C#设计模式——组合模式(Composite Pattern)
一.概述 在软件开发中,我们往往会遇上类似树形结构的对象体系.即某一对象既可能在树形结构中作为叶节点存在,也可能作为分支节点存在.比如在文件系统中,文件是作为叶节点存在,而文件夹就是分支节点.在设计这 ...