ArcGIS Engine 10 开发手册(4-23)数据转换
发布时间: 2017-10-28
所属分类: ArcGIS Engine 10 开发手册
关于数据转换的说明
数据转换主要涉及复制和转换数据出入 Geodatabases 的对象。 两个主要的数据转换对象是 FeatureDataConverter 和 GeoDBDataTransfer。
ArcCatalog 用户应该熟悉 FeatureDataConverter;导入(import)功能广泛使用该 coclass。 ArcCatalog 用户也应该熟悉 GeoDBDataTransfer;在 Geodatabases 之间复制数据集的 copy/paste 功能使用该 class。
还有其它一些对象和接口支持 FeatureDataConverter 和 GeoDBDataTransfer,并执行以下功能:
- 使用 IFieldChecker 检查字段名称中的潜在问题。
- 检查使用 IEnumInvalidObject 的转换过程中被拒* 绝的数据。
- 使终端用户了解 IFeatureProgress
转换示例代码
public void ConvertFeatureClass (IWorkspaceFactory\ _pSWorkspaceFactory, String _pSWs, string _pSName, orkspaceFactory _pTWorkspaceFactory, String _pTWs, string _pTName)
{
// Open the source and target workspaces.
IWorkspace pSWorkspace = _pSWorkspaceFactory.OpenFromFile (_pSWs, 0);
IWorkspace pTWorkspace = _pTWorkspaceFactory.OpenFromFile (_pTWs, 0);
IFeatureWorkspace pFtWs = pSWorkspace as IFeatureWorkspace;
IFeatureClass pSourceFeatureClass = pFtWs.OpenFeatureClass (_pSName);
IDataset pSDataset = pSourceFeatureClass as IDataset;
IFeatureClassName pSourceFeatureClassName = pSDataset.FullName as IFeatureClassName;
IDataset pTDataset = (IDataset) pTWorkspace;
IName pTDatasetName = pTDataset.FullName;
IWorkspaceName pTargetWorkspaceName = (IWorkspaceName) pTDatasetName;
IFeatureClassName pTargetFeatureClassName = new FeatureClassNameClass ();
IDatasetName pTargetDatasetName = (IDatasetName) pTargetFeatureClassName;
pTargetDatasetName.Name = _pTName;
pTargetDatasetName.WorkspaceName = pTargetWorkspaceName;
// 创建字段检查对象
IFieldChecker pFieldChecker = new FieldCheckerClass ();
IFields sourceFields = pSourceFeatureClass.Fields;
IFields pTargetFields = null;
IEnumFieldError pEnumFieldError = null;
pFieldChecker.InputWorkspace = pSWorkspace;
pFieldChecker.ValidateWorkspace = pTWorkspace;
// 验证字段
pFieldChecker.Validate (sourceFields, out pEnumFieldError, out pTargetFields);
if (pEnumFieldError != null)
{
// Handle the errors in a way appropriate to your application. Console.WriteLine("Errors were encountered during field validation.");
}
String pShapeFieldName = pSourceFeatureClass.ShapeFieldName;
int pFieldIndex = pSourceFeatureClass.FindField (pShapeFieldName);
IField pShapeField = sourceFields.get_Field (pFieldIndex);
IGeometryDef pTargetGeometryDef = pShapeField.GeometryDef;
// 创建要素转换对象
IFeatureDataConverter pFDConverter = new FeatureDataConverterClass ();
IEnumInvalidObject pEnumInvalidObject = pFDConverter.ConvertFeatureClass
(pSourceFeatureClassName, null, null, pTargetFeatureClassName, pTargetGeometryDef, pTargetFields, "",1000, 0);
// Check for errors.
IInvalidObjectInfo pInvalidInfo = null;
pEnumInvalidObject.Reset ();
while ((pInvalidInfo = pEnumInvalidObject.Next ()) != null)
{
// Handle the errors in a way appropriate to the application.
Console.WriteLine ("Errors occurred for the following feature: {0}",
pInvalidInfo.InvalidObjectID);
}
}
IWorkspaceFactory pSwf = new AccessWorkspaceFactoryClass ();
IWorkspaceFactory pDwf = new AccessWorkspaceFactoryClass ();
ConvertFeatureClass (pSwf, "E:\\s.mdb", "s", pDwf, "E:\\d.mdb", "d");
ArcGIS Engine 10 开发手册全集
ArcGIS Engine 10 开发手册全集: ArcGIS Engine 10 开发手册
相关阅读
声明
1.本文所分享的所有需要用户下载使用的内容(包括但不限于软件、数据、图片)来自于网络或者麻辣GIS粉丝自行分享,版权归该下载资源的合法拥有者所有,如有侵权请第一时间联系本站删除。
2.下载内容仅限个人学习使用,请切勿用作商用等其他用途,否则后果自负。
手机阅读
公众号关注
知识星球
手机阅读
最新GIS干货
私享圈子