转自原文arcengine 要素类的复制

using System;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Carto;
namespace MyGISClass
{
/// <summary>
/// 该类主要包含了要素类的复制以及同要素类数据的加载
/// 函数主要用于SDE与Personal GDB之间数据的处理
/// </summary>
class FeatureClassDataManager
{
/// <summary>
/// 根据传入的源要素类OldFeatureClass,新空间范围,要素存储工作空间,新要素类名
/// 产生具有相同字段结构和不同空间范围的要素类
/// </summary>
/// <param name="OldFeatureClass">源要素类</param>
/// <param name="SaveFeatWorkspace">存储工作空间</param>
/// <param name="FeatClsName">新要素类名</param>
/// <param name="pDomainEnv">新空间范围,可为null</param>
/// <returns></returns>
public IFeatureClass CloneFeatureClassInWorkspace(IFeatureClass OldFeatureClass, IFeatureWorkspace SaveFeatWorkspace, string FeatClsName, IEnvelope pDomainEnv)
{
IFields pFields = CloneFeatureClassFields(OldFeatureClass, pDomainEnv);
return SaveFeatWorkspace.CreateFeatureClass(FeatClsName, pFields, null, null, esriFeatureType.esriFTSimple, OldFeatureClass.ShapeFieldName, "");
}
/// <summary>
/// 复制AnnotationClass,未完待续
/// </summary>
/// <param name="OldFeatureClass"></param>
/// <param name="SaveFeatWorkspace"></param>
/// <param name="FeatClsName"></param>
/// <param name="pDomainEnv"></param>
/// <returns></returns>
public IFeatureClass CloneAnnotationClassInWorkspace(IFeatureClass OldFeatureClass, IFeatureWorkspace SaveFeatWorkspace, string FeatClsName, IEnvelope pDomainEnv)
{
IFeatureWorkspaceAnno pFWSAnno = (IFeatureWorkspaceAnno)SaveFeatWorkspace;
IAnnoClass pAnnoClass = (IAnnoClass)OldFeatureClass.Extension;
return null;
}
/// <summary>
/// 将inFeatureClass要素类中所有符合pQueryFilter的要素复制到saveFeatureClass中,仅复制不做任何修改
/// </summary>
/// <param name="inFeatureClass">源要素类</param>
/// <param name="saveFeatureClass">存储要素类</param>
/// <param name="pQueryFilter">过滤参数</param>
/// <returns></returns>
public bool LoadFeatureClass(IFeatureClass inFeatureClass, IFeatureClass saveFeatureClass, IQueryFilter pQueryFilter)
{
//生成两个要素类字段的对应表
Dictionary<int, int> pFieldsDict = new Dictionary<int, int>();
this.GetFCFieldsDirectory(inFeatureClass, saveFeatureClass, ref pFieldsDict);
IFeatureCursor pinFeatCursor = inFeatureClass.Search(pQueryFilter, false);
long nCount = inFeatureClass.FeatureCount(pQueryFilter);
IFeature pinFeat = pinFeatCursor.NextFeature();
IFeatureCursor psaveFeatCursor = saveFeatureClass.Insert(true);
//使用IFeatureBuffer在内存中产生缓存避免多次打开,关闭数据库
IFeatureBuffer psaveFeatBuf = null;
IFeature psaveFeat = null;
long n = ;
while (pinFeat != null)
{
try
{
psaveFeatBuf = saveFeatureClass.CreateFeatureBuffer();
psaveFeat = psaveFeatBuf as IFeature;
if (inFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
{
IAnnotationFeature pAF = (IAnnotationFeature)pinFeat;
IAnnotationFeature pNAF = (IAnnotationFeature)psaveFeat;
if (pAF.Annotation != null)
{
pNAF.Annotation = pAF.Annotation;
}
}
psaveFeat.Shape = pinFeat.Shape;
foreach (KeyValuePair<int, int> keyvalue in pFieldsDict)
{
if (pinFeat.get_Value(keyvalue.Key).ToString() == "")
{
if (psaveFeat.Fields.get_Field(keyvalue.Value).Type == esriFieldType.esriFieldTypeString)
{
psaveFeat.set_Value(keyvalue.Value, "");
}
else
{
psaveFeat.set_Value(keyvalue.Value, );
}
}
else
{
psaveFeat.set_Value(keyvalue.Value, pinFeat.get_Value(keyvalue.Key));
}
}
psaveFeatCursor.InsertFeature(psaveFeatBuf);
}
catch (Exception ex) { }
finally
{
psaveFeat = null;
n++;
if (n % == )
{
psaveFeatCursor.Flush();
}
pinFeat = pinFeatCursor.NextFeature();
}
}
psaveFeatCursor.Flush();
return true;
}
private IFields CloneFeatureClassFields(IFeatureClass pFeatureClass, IEnvelope pDomainEnv)
{
IFields pFields = new FieldsClass();
IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;
//根据传入的要素类,将除了shape字段之外的字段复制
long nOldFieldsCount = pFeatureClass.Fields.FieldCount;
long nOldGeoIndex = pFeatureClass.Fields.FindField(pFeatureClass.ShapeFieldName);
for (int i = ; i < nOldFieldsCount; i++)
{
if (i != nOldGeoIndex)
{
pFieldsEdit.AddField(pFeatureClass.Fields.get_Field(i));
}
else
{
IGeometryDef pGeomDef = new GeometryDefClass();
IGeometryDefEdit pGeomDefEdit = (IGeometryDefEdit)pGeomDef;
ISpatialReference pSR = null;
if (pDomainEnv != null)
{
pSR = new UnknownCoordinateSystemClass();
pSR.SetDomain(pDomainEnv.XMin, pDomainEnv.XMax, pDomainEnv.YMin, pDomainEnv.YMax);
}
else
{
IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
pSR = CloneSpatialReference(pGeoDataset.SpatialReference);
}
//设置新要素类Geometry的参数
pGeomDefEdit.GeometryType_2 = pFeatureClass.ShapeType;
pGeomDefEdit.GridCount_2 = ;
pGeomDefEdit.set_GridSize(, );
pGeomDefEdit.AvgNumPoints_2 = ;
pGeomDefEdit.SpatialReference_2 = pSR;
//产生新的shape字段
IField pField = new FieldClass();
IFieldEdit pFieldEdit = (IFieldEdit)pField;
pFieldEdit.Name_2 = "shape";
pFieldEdit.AliasName_2 = "shape";
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
pFieldEdit.GeometryDef_2 = pGeomDef;
pFieldsEdit.AddField(pField);
}
}
return pFields;
}
private ISpatialReference CloneSpatialReference(ISpatialReference pSrcSpatialReference)
{
double xmin, xmax, ymin, ymax;
pSrcSpatialReference.GetDomain(out xmin, out xmax, out ymin, out ymax);
ISpatialReference pSR = new UnknownCoordinateSystemClass();
pSR.SetDomain(xmin, xmax, ymin, ymax);
return pSR;
}
private void GetFCFieldsDirectory(IFeatureClass pFCold,IFeatureClass pFCnew,ref Dictionary<int,int> FieldsDictionary)
{
for(int i=;i<pFCold.Fields.FieldCount;i++)
{
string tmpstrold=pFCold.Fields.get_Field(i).Name.ToUpper();
switch(tmpstrold)
{
case "OBJECTID":
case "SHAPE":
case "SHAPE_LENGTH":
case "SHAPE_AREA":
case "FID":
{
//以上字段由系统自动生成
break;
}
default:
{
for(int j=;j<pFCnew.Fields.FieldCount;j++)
{
string tmpstrnew=pFCnew.Fields.get_Field(j).Name.ToUpper();
if(tmpstrold==tmpstrnew)
{
FieldsDictionary.Add(i,j);
break;
}
}
break;
}
}
}
}
}
}

arcengine 要素类的复制的更多相关文章

  1. arcengine新建要素类

    ArcGIS里面新建数据集,看起来简单,平时都是默认创建,实际上好多细节问题我们都没注意到 一.在数据集上新建要素类: How to create a feature class within a f ...

  2. ArcGIS模型构建器案例教程-批量复制工作空间所有要素类

    ArcGIS模型构建器案例教程-批量复制工作空间所有要素类 目的:批量复制工作空间所有要素类 工具名称:WorkspaceCopyFeatureClasses 使用方法:输入工作空间,指定输出工作空间 ...

  3. 用ArcMap在PostgreSQL中创建要素类需要执行”create enterprise geodatabase”吗

    问:用Acmap在PostgreSQL中创建要素类需要执行"create enterprise geodatabase"吗? 关于这个问题,是在为新员工做postgresql培训后 ...

  4. 往sde中导入要素类报错000732

    sde可以成功连接,可以在Server中注册. 但是向sde中导入要素类报错000732,如图所示. 点击红色圆圈提示 ERROR 000732. 将路径修改为绝对路径即可,如下图所示.

  5. ARCGIS获取图层下的要素信息及要素类转换为要素

    /// <summary> /// 得到需要的字段名和字段值 /// </summary> /// <param name="layer">&l ...

  6. Geodatabase - 创建要素类.

    在NET中,会遇到以“_2”结尾的属性,这些属性是可写的. 以下代码在已有工作空间下,创建一个新的点要素类: //例如,personalDBPath=@"G:\doc\gis\1.400\d ...

  7. Geodatabase - 打开要素类

    string dbPath = @"G:\doc\gis\1.400\data\pdb.mdb"; ESRI.ArcGIS.Geodatabase.IWorkspaceFactor ...

  8. 如何删除要素类 IFeatureWorkspace 接口介绍(1)

    如何删除要素类 要想删除一个要素类,那么必须先得到这个,在得到这个要素类的时候,我们要学习一个新的接口IFeatureWorkspace. IFeatureWorkspace  接口介绍 这个接口主要 ...

  9. c# 封装的文件夹操作类之复制文件夹

    c#  封装的文件夹操作类之复制文件夹 一.复制文件夹原理: 1.递归遍历文件夹 2.复制文件 二.FolderHelper.cs /// <summary> /// 文件夹操作类 /// ...

随机推荐

  1. Loadrunner经典测试实例

    Loadrunner经典测试实例

  2. 微信小程序弹框提示绑定手环实例

    今天想聊一聊小程序里面存在的一些逻辑问题,拿手上的这个小程序来说,(这个小程序是开发出来玩的,每个人手上有一个手环,带着手环时候的心率,运动步数,血压数据都会展现在这个小程序里面,一目了然)用户第一次 ...

  3. 【Educational Codeforces Round 35 A】 Nearest Minimums

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 找出最小的数字的位置. 最近的肯定是相邻的某对. [代码] #include <bits/stdc++.h> using ...

  4. amazeui学习笔记一(开始使用2)--布局示例layouts

    amazeui学习笔记一(开始使用2)--布局示例layouts 一.总结 1.样例分析(不要忘记,优先分析这个布局示例):有教你页面怎么布局的,实例中可以分析一波 2.响应式:对应meta标签中的v ...

  5. OpenWrt配置绿联的usb转Ethernet网口驱动

    这个选择kernel modules中的kmod-usb-net-asix 须要加入网络设备接口.相似建立一个vlan,配置下防火墙之类的.

  6. 使用Struts2和jQuery EasyUI实现简单CRUD系统(七)——数据分页处理

    上篇完毕多选删除的功能之后,接下来就是做分页功能了.曾经的分页是一个麻烦的问题.并且数据量巨大的时候,直接把这些元素取出来显然速度较慢,所以取一定区间的数据还是高效的. watermark/2/tex ...

  7. Spring-data-redis:特性与实例--转载

    原文地址:http://shift-alt-ctrl.iteye.com/blog/1886831 Spring-data-redis为spring-data模块中对redis的支持部分,简称为“SD ...

  8. Android 快速下载 Android framework 源码

    官网 Android framework源码git地址 github: https://github.com/android/platform_frameworks_base google 官方: h ...

  9. C++——多态性实现机制

    C++的多态性实现机制剖析 1. 多态性和虚函数 #include <iostream.h> class animal { public: void sleep() { cout<& ...

  10. window.print()打印网页(一)

    有时候需要将网页内容打印到纸上,最简单的一种方法是用window对象的print方法. window.print()默认打印当前网页的所有部分.(除了背景,默认打印都是白底黑字,如果有特别的设置 要另 ...