arcengine 要素类的复制
转自原文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 要素类的复制的更多相关文章
- arcengine新建要素类
ArcGIS里面新建数据集,看起来简单,平时都是默认创建,实际上好多细节问题我们都没注意到 一.在数据集上新建要素类: How to create a feature class within a f ...
- ArcGIS模型构建器案例教程-批量复制工作空间所有要素类
ArcGIS模型构建器案例教程-批量复制工作空间所有要素类 目的:批量复制工作空间所有要素类 工具名称:WorkspaceCopyFeatureClasses 使用方法:输入工作空间,指定输出工作空间 ...
- 用ArcMap在PostgreSQL中创建要素类需要执行”create enterprise geodatabase”吗
问:用Acmap在PostgreSQL中创建要素类需要执行"create enterprise geodatabase"吗? 关于这个问题,是在为新员工做postgresql培训后 ...
- 往sde中导入要素类报错000732
sde可以成功连接,可以在Server中注册. 但是向sde中导入要素类报错000732,如图所示. 点击红色圆圈提示 ERROR 000732. 将路径修改为绝对路径即可,如下图所示.
- ARCGIS获取图层下的要素信息及要素类转换为要素
/// <summary> /// 得到需要的字段名和字段值 /// </summary> /// <param name="layer">&l ...
- Geodatabase - 创建要素类.
在NET中,会遇到以“_2”结尾的属性,这些属性是可写的. 以下代码在已有工作空间下,创建一个新的点要素类: //例如,personalDBPath=@"G:\doc\gis\1.400\d ...
- Geodatabase - 打开要素类
string dbPath = @"G:\doc\gis\1.400\data\pdb.mdb"; ESRI.ArcGIS.Geodatabase.IWorkspaceFactor ...
- 如何删除要素类 IFeatureWorkspace 接口介绍(1)
如何删除要素类 要想删除一个要素类,那么必须先得到这个,在得到这个要素类的时候,我们要学习一个新的接口IFeatureWorkspace. IFeatureWorkspace 接口介绍 这个接口主要 ...
- c# 封装的文件夹操作类之复制文件夹
c# 封装的文件夹操作类之复制文件夹 一.复制文件夹原理: 1.递归遍历文件夹 2.复制文件 二.FolderHelper.cs /// <summary> /// 文件夹操作类 /// ...
随机推荐
- golang 逐行读取文件
package main import ( "bufio" "fmt" "io" "os" ) func main() ...
- 趣闻|Python之禅(The Zen of Python)
在Python解释器中输入“import this”会发生什么?如果你不知道这个彩蛋,推荐继续阅读这篇文章. 2001年秋,Foretec(一家会议组织公司)正在准备召开第十届Internationa ...
- 一个很详细的web.xml讲解(转)
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "- ...
- 【习题 6-7 UVA - 804】Petri Net Simulation
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟就好 [代码] /* 1.Shoud it use long long ? 2.Have you ever test sever ...
- JPA的配置文件persistence.xml参数详解
<?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0&q ...
- 洛谷——P1179 数字统计
https://www.luogu.org/problem/show?pid=1179 题目描述 请统计某个给定范围[L, R]的所有整数中,数字 2 出现的次数. 比如给定范围[2, 22],数字 ...
- 主定理(Master Theorem)与时间复杂度
1. 问题 Karatsuba 大整数的快速乘积算法的运行时间(时间复杂度的递推关系式)为 T(n)=O(n)+4⋅T(n/2),求其最终的时间复杂度. 2. 主定理的内容 3. 分析 所以根据主定理 ...
- 当数据库没有备份,redo或undo损坏
数据库在没有备份的情况下,如果数据库redo或undo损坏,可以通过如下方法处理,但是不一定成功 把init文件中的: undo_management=manual 然后启动数据库到mount 状态后 ...
- [D3] Build a Column Chart with D3 v4
Column and bar charts are staples of every visualization library. They also make a great project for ...
- MySql 中的setAutoCommit方法
引言 setAutoCommit方法用一句话说就是用来保持事务完整性.一个系统的更新操作可能涉及多张表,这个时候,就须要用多个Sql语句来实现,实际上我认为这个东西就是用来实现事务的. 当我们进行多条 ...