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_ ...
随机推荐
- shell Builtin variables(shell内建变量)
内容来自:abs-guide $BASH The path to the Bash binary itself bash$ echo $BASH /bin/bash $BASH_ENV An envi ...
- Linux下U盘变成只读
今天用Ubuntu给同学拷贝数据的时候,突然其中一个文件夹U盘就不能复制和删除了.再windows7下可以删除除修改的那个文件夹之外的数据,但修改的那个文件夹死活删除不掉,只读属性也去不掉.再Ubun ...
- 快乐的JS正则表达式(三)
?的用途. 小任务:匹配一段网址如var str = "http://www.123.com/";注意http也可以是https var str = "http://i. ...
- 二叉堆(一)之 图文解析 和 C语言的实现
概要 本章介绍二叉堆,二叉堆就是通常我们所说的数据结构中"堆"中的一种.和以往一样,本文会先对二叉堆的理论知识进行简单介绍,然后给出C语言的实现.后续再分别给出C++和Java版本 ...
- sql order by 排序多个字段
order by 多个字段,每个字段后面都有排序方式,默认ASC 例如:select table a order by a.time1 ,a.time2 desc,a.time3 asc
- Linux - Yum的常用方法总结
简述 rpm是由红帽公司开发的软件包管理方式,使用rpm可以方便的进行软件的安装.查询.卸载.升级等工作. 但是rpm软件包之间的依赖性问题往往会很繁琐,尤其是软件由多个rpm包组成时. Yum(全称 ...
- [pyhton]python内建方法
撸一遍python的内建方法 这样做的好处就是:我如果要完成一个功能的时候,如果能用内建方法完成,就用内建方法.这样可以提高效率,同时使自己的代码更加优雅.哎呦?那岂不是撸完就是python高手了?我 ...
- Android学习笔记之使用百度地图实现Poi搜索
PS:装个系统装了一天.心力憔悴.感觉不会再爱了. 学习内容: 1.使用百度Map实现Poi搜索. 2.短串分享 3.在线建议查询 百度地图的研究也算是过半了.能够实现定位,实现相关信息的搜索,实 ...
- 设计模式之Interator模式(1)
interator是java容器遍历的一种手段,当然遍历容易你可以使用普通的for(;;)或者for(Object o : new Arraylist<Object>()),都是可以的. ...
- 译:c#生成条码的web控件
译文:http://www.codeproject.com/Tips/846860/Csharp-Barcode-Generator-Web-Control 在asp.net的web页用c#的web控 ...