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_ ...
随机推荐
- char str[]和char *str的区别
1.http://blog.csdn.net/szchtx/article/details/10396149 char ss[]="C++"; ss[0]='c'; ...
- There is an internal error in the React performance measurement code.Did not expect componentDidMount timer to start while render timer is still in progress for another instance
一.There is an internal error in the React performance measurement code.Did not expect componentDidMo ...
- Material Design UI Widgets
Android L 开发者预览支持库提供两个新的Widgets,RecyclerView和CardView.使用这两个Widgets可以显示复杂的Listview和卡片布局,这两个Widgets默认使 ...
- 【weka应用技术与实践】过滤器
weka中的过滤器主要用于数据预处理阶段对数据集的各种操作. 今天简单地使用一下过滤器: 首先打开一个自带数据集weather.numeric.arff,这是一个关于通过天气条件,气温以及风力等因素来 ...
- Spring MVC 3.x 基本配置
WEB-INF/web.xml 例1 <?xml version="1.0" encoding="UTF-8"?> <web-app xmln ...
- 使用MyXls,出现访问被拒绝情况
MyXls 作为一款比较好用的 操作Excel 的开源项目. 最近日常偶然发现报权限的问题,导出xls失败,处理方式以下: 如报上图所示错误,则需要在web.config中 <system.we ...
- 【分布式】RPC初探
事先声明:本文代码参考自Dubbo作者的博客. RPC(Remote Procedure Call)远程过程调用,是分布式系统当中必不可少的一个玩意.比如说在单机系统当中,我想调用某个方法,直接调就可 ...
- ssl 握手过程【收藏】
收藏几篇关于ssl handshake的好文 http://www.slashroot.in/comment/1242 SSL protocol, does its fantastic job of ...
- Windows及Linux平台下的计时函数总结
本文对Windows及Linux平台下常用的计时函数进行总结,包括精度为秒.毫秒.微秒三种精度的各种函数.比如Window平台下特有的Windows API函数GetTickCount().timeG ...
- IOS开发UI基础UISlide属性
UISlide属性 • minimumValue : 当值可以改变时,滑块可以滑动到最小位置的值,默认为0.0_slider.minimumValue = 10.0; • maximum ...