ArcGIS Engine 10 开发手册(4-23)数据转换

本文目录
  • 正文

关于数据转换的说明

数据转换主要涉及复制和转换数据出入 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 开发手册

如您有疑问,可在文末留言,或到QQ群提问。

本站QQ群:291616564 麻辣GIS

微信公众号:malagis,扫描右边二维码直接关注。

微信捐助麻辣GIS 支付宝捐助麻辣GIS

如果本文对您有所帮助,欢迎对我们团队进行打赏捐助,让我们在传播3S的路上可以走得更远。


作者:,GIS爱好者。
分享本文,请您带上本文链接

发表评论