Workspace中要素类与Xml文件的互转

private void ExportDatasetToXML(String databaseName, String outputXmlFile)
{
  // Open the source geodatabase.
  IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
  IWorkspace workspace = workspaceFactory.OpenFromFile(databaseName, 0);

  // Retrieve the first feature dataset from the workspace.
  IEnumDatasetName enumDatasetName = workspace.get_DatasetNames
    (esriDatasetType.esriDTFeatureDataset);
  enumDatasetName.Reset();
  IName featureDatasetName = (IName)enumDatasetName.Next();
  if (featureDatasetName == null)
  {
    throw new ArgumentException(
      "No feature datasets exist in the specified geodatabase.");
  }

  // Create a new enumerator and add the feature dataset name.
  IEnumNameEdit enumNameEdit = new NamesEnumeratorClass();
  enumNameEdit.Add(featureDatasetName);
  IEnumName enumName = (IEnumName)enumNameEdit;

  // Create a scratch workspace factory. 
  IScratchWorkspaceFactory scratchWorkspaceFactory = new
    ScratchWorkspaceFactoryClass();
  IWorkspace scratchWorkspace =
    scratchWorkspaceFactory.CreateNewScratchWorkspace();
  IDataset dataset = (IDataset)scratchWorkspace;
  IName workspaceName = dataset.FullName;

  // Create a GeoDBDataTransfer object and create a name mapping.
  IGeoDBDataTransfer geoDBDataTransfer = new GeoDBDataTransferClass();
  IEnumNameMapping enumNameMapping = null;
  Boolean hasConflicts = geoDBDataTransfer.GenerateNameMapping(enumName,
    workspaceName, out enumNameMapping);
  if (hasConflicts)
  {
    // TODO: Handle this in a way appropriate to your application.
  }

  // Create an exporter and export the dataset with binary geometry, not compressed,
  // and including metadata.
  IGdbXmlExport gdbXmlExport = new GdbExporterClass();
  gdbXmlExport.ExportDatasets(enumNameMapping, outputXmlFile, true, false, true)
    ;
}




private void XmlImportWS(string workspacePathname, string dbName, string
  inXmlFile)
{
  // Create an Access database (dbName) at the workspacePathname location.
  IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
  IWorkspaceName workspaceName = workspaceFactory.Create(workspacePathname,
    dbName, null, 0);

  // Open the geodatabase.
  IName name = (IName)workspaceName;
  IWorkspace workspace = (IWorkspace)name.Open(); // Explicit Cast

  // Create a GdbImporter.
  IGdbXmlImport gdbXmlImport = new GdbImporterClass();

  // Read schema section from the XML file.
  // Note: enumNameMapping is initialized to nothing and its value is set 'by ref' with a call to the GenerateNameMapping method.
  IEnumNameMapping enumNameMapping = null;
  gdbXmlImport.GenerateNameMapping(inXmlFile, workspace, out enumNameMapping);

  // Create the workspace schema and load the data.
  gdbXmlImport.ImportWorkspace(inXmlFile, enumNameMapping, workspace, false);
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值