About data conversion and transfer (ZZ) 数据转化和转移

轉自EDN: http://edndoc.esri.com/arcobjects/9.2/NET/c45379b5-fbf2-405c-9a36-ea6690f295b2.htm

Overview of data conversion and transfer
Within the geodatabase and geodatabase user interface (UI) libraries, there are five main interfaces involved with transferring datasets from one workspace to another. See the following topics: IFeatureDataConverter and IFeatureDataConverter2

  1. IGeoDBDataTransfer (also known as copy/paste)
  2. IDataset (specifically, the Copy method)
  3. IWorkspaceFactory (specifically, the Copy and Move methods) 
  4. IExportOperation

In addition to these classes and interfaces, other options for transferring data exist. The following table gives an overview of the benefits and drawbacks of each: (能實現數據轉化和遷移的方法有以下幾種)

Method
What is transferred
Works with query filter
Crosses data sources
Works with edit session
ArcGIS Desktop/
ArcGIS Engine
IFeatureDataConverter[2]
Single table, feature class, or feature dataset
True
True
False
Both
IGeoDBDataTransfer
Multiple tables, feature classes, and/or feature datasets, and domains from geodatabases
False
False
False
Both
IExportOperation (GeodatabaseUI)
Single table or feature class
True
True
False
ArcGIS Desktop
IDataset.Copy
Single dataset from a
file-based data source
False
False
False
Both
IWorkspaceFactory
(Copy and Move methods)
Local (personal or file) geodatabase, or an SDE connection file
False
False
False
Both
IGdbXmlExport and IGdbXmlImport (GeoDatabaseDistributed)
Entire workspace (schema, data optional), one or more datasets (schema, data optional), or a record set *
False
False
False
Both
IObjectLoader (EditorExt)
Individual rows from one dataset to another existing dataset
True
True
True
ArcGIS Desktop

 * The IGdbXmlExport and IGdbXmlImport interfaces indirectly transfer data between geodatabases by first converting the dataset schema (and, optionally, the data) to Extensible Markup Language (XML), then from XML back to its original form.

To summarize the previous table, the following situations are appropriate for each method:

  1. IFeatureDataConverter—Use when copying a single dataset or feature dataset and fine-grained control is necessary. This includes applying a query filter to restrict the rows that are copied, modifying the geometry definition, and applying a configuration key. Also useful for transferring datasets from one data source to another.
    IGeoDBDataTransfer—Use when copying one or more geodatabase datasets within the same geodatabase or to another geodatabase.
  2. IExportOperation—Use when copying a single dataset to another workspace and a query filter or selection set is necessary. Also useful for transferring datasets from one data source to another.
    IDataset.Copy—Use when copying a dataset from a file-based data source (such as a shapefile, a database file [DBF] table, or a coverage feature class) to another workspace.
  3. IWorkspaceFactory (Copy and Move methods)—Use when copying or moving an entire local geodatabase or an SDE connection file.
  4. IGdbXmlExport and IGdbXmlImport—Use when XML data is required, or working in a disconnected environment.
  5. IObjectLoader—Use when copying individual rows to an existing dataset.

Name objects and conversion methods
Many of the application programming interfaces (APIs) for data transfer involve the use of name objects. A name object is a lightweight representation of a dataset or a workspace that provides basic information, such as name and location, without requiring the client to open the dataset or the workspace. A name object can also represent a dataset that doesn't currently exist—they are used in this way with the IFeatureDataConverter and IExportOperation interfaces.

To get a name object for an existing dataset, there are three main options:

  1. Create a name object of the appropriate type (that is, FeatureClassName), cast it to the IDatasetName interface, and set the Name and WorkspaceName properties. This option requires having a name object for the dataset's workspace (and feature dataset, if applicable), but this can be created in a similar fashion.
  2. Generate a name object from an open dataset. After casting a dataset to the IDataset interface, the FullName property can be used to create a name object. This is only applicable for existing datasets, so it isn't an option in cases where a name object represents a dataset to be created.
  3. Browse the dataset's container for its name object. An example of this is the IWorkspace.DatasetNames method, which returns an enumerator of name objects for a specific dataset type. Again, this isn't an option for datasets that don't exist.

IFeatureDataConverter and IFeatureDataConverter2
The feature data converter copies a dataset within a workspace or to another workspace (of the same data source type or another data source type). The IFeatureDataConverter interface allows fine-grained control over the process of converting a dataset, including the following:

  1. Application of a query filter or a spatial filter to restrict the rows transferred to the new dataset.
  2. Application of a query filter's SubFields properties to restrict the fields transferred to the new dataset.
  3. Modification of the fields used in the new dataset (to some extent). Examples of this include changing a field's name and length, and in some cases its type (that is, a double field can be converted to an integer field).
  4. Providing a new GeometryDef object to replace the existing geometry definition.
  5. Setting a configuration keyword for the dataset.
    Not all of these are applicable to every type of conversion; for example, a table cannot be given a GeometryDef and a query filter cannot be used when converting a feature dataset.

In addition to the capabilities listed previously, the IFeatureDataConverter2 interface includes the option of providing a selection set to its ConvertFeatureClass and ConvertTable methods. This is particularly useful when creating a new dataset from the selected features of a feature layer.
 
The ConvertFeatureClass and ConvertTable methods of both feature data converter interfaces have an IEnumInvalidObject return type. This enumerator returns the Object IDs for each row or feature that could not be successfully converted, along with a short description explaining why the conversion was unsuccessful. An example of why a conversion can fail is when the new dataset contains a string field with a shorter length than its corresponding field in the original dataset, and an object's value for that field exceeds the new length; however, it is important to remember the rejection of an individual row or feature does not cancel the entire operation.
 
The ConvertFeatureDataset method converts a feature dataset from one data source to another; however, relatively few data sources support feature datasets (compared to feature classes and tables), so it isn't used as often as the other two conversion methods, and in most cases, IGeoDBDataTransfer is a better option for copying a feature dataset. This is especially true because ConvertFeatureDataset only transfers children that are feature classes, whereas IGeoDBDataTransfer includes other types of datasets, such as relationship classes, topologies, and geometric networks. The options available during conversion are significantly less than the other two methods, but a geometry definition and a configuration key can still be applied. Since a feature dataset doesn't include rows or features, this method has a void return type.

(該方法能夠將Personal Geodatabase/Geodatabase數據集轉換到另一個新的。數據源可以是personal geodmatabase, enterprise geodatabase,dbase file,shapefile,,Info File或者是ArcInfo Coverage, 導出的target只能是personal geodatabase,enterprise geomdatabase,dbase file或者是shapefile. 這種方法僅支持simple feature classes (point, line, polygon),不支持復雜的feature class(geometric network feature classes, SDE 3.x annotation, Geodatabase annotation, coverage annotation).而且 Subtypes 和 domains在轉換后都不會被保留.)

IGeoDBDataTransfer
Using the GeoDBDataTransfer class is equivalent to using the Copy and Paste commands within ArcMap for geodatabase datasets. It allows one or more datasets to be copied within or across geodatabases. The options available with this interface are significantly less than those of the IFeatureDataConverter methods, but in many cases this simplifies the overhead preparation required for the transfer.
 
One major advantage of this interface over the feature data converter is that it can be used to transfer nearly any type of geodatabase object, including relationship classes, topologies, geometric networks. It also transfers datasets and objects that are associated with a copied object automatically. For example, if this interface is used to transfer a feature class that utilizes domains or representation classes, the process detects these and automatically transfers them with the feature class.
 
The only customizable aspect of this process is through a generated name mapping enumerator. The Transfer method requires a name mapping enumerator (IEnumNameMapping) that can be generated using the GenerateNameMapping method. Although the main reason to modify the name mappings is to resolve name conflicts (this occurs if a dataset of the same name exists in the target workspace), the INameMapping interface exposes properties that can be used to set the names and configuration keywords of the new datasets.

 (这方法只能be copied within or across geodatabases,说简单点就是只能在access和SDE之间进行转换,而且还不支持queryfilter。不过,它支持的数据类型还蛮多:featureclass, featuredataset,geometry network,table,relationshipclass,而且需要的参数也较少.)

IExportOperation
The IExportOperation interface is effectively a "wrapped" version of the feature data converter. It allows a feature class or a table to be copied within its existing workspace or to another workspace (of the same or another type). The following are the three main differences between using IExportOperation and IFeatureDataConverter:

  1. It's slightly less configurable. In some cases this may be a disadvantage, but in cases where modification of objects like the fields collection isn't required, this reduces the overhead preparation involved.
  2. IExportOperation displays a progress bar during operation. This can be useful for graphical user interface (GUI) applications, but may be inappropriate for console applications or processes intended to be silent. (这点是我很不喜欢的)
  3. IExportOperation is located in the GeodatabaseUI library, meaning it is only available to ArcGIS Desktop users(只能在桌面版中使用,浪费了).

(用IExportOperation导simple featureclass还行,导Annotation featureclass就无能为力了,似乎还真没有哪个方法能导annotation featureclass的)

IDataset.Copy
The IDataset.Copy method allows a dataset from a file-based data source (such as a shapefile, a DBF table, or a coverage feature class) to be copied to another workspace of the same type. There are virtually no configurable options in this process, as the method only takes two parameters—the name and workspace of the new dataset.

 (簡單的复制數據,而且是要file-base的數據源,而且target需要跟數據源是同一個類型)

IWorkspaceFactory.Copy and IWorkspaceFactory.Move
IWorkspaceFactory.Copy and IWorkspaceFactory.Move allow a local geodatabase (a personal or file geodatabase) or an SDE connection file to be copied or moved within the file system. Both methods require workspace name objects. See the following:

  1. Copy requires a name object for the existing workspace and for the workspace to be created.
  2. Move only requires a name object for the existing workspace.

(copy和move方法有個叫destinationFolder的參數,因此,這個方法是基于file system操作的)

IObjectLoader.LoadObjects Method

The ISelectionSet object that the IObjectLoader::LoadObjects method returns is empty if the applyValidation argument is False. If this argument is True, validation is performed, and the ISelectionSet object returned contains the invalid features. The IQueryFilter::SubFields MUST match the IObjectLoader::OutputFields. All fields must have there IsNullable and Editable parameters set to TRUE or the attribute loading will fail.

The order of the fields in the inputTable and outputTable is not important. Field mapping doune through the inputQueryFilter::SubFields and the outputFields properties. In this case order is important. The first field in the inputQueryFilter::SubFields maps to the first field in the outputFields, the second in the inputQueryFilter::SubFields maps to the second field in the outputFields and so on. Fields not contained in the inputQueryFilter::SubFields will not be mapped. Mapped field types must be compadible. Text to text, numeric to numeric, etc. Type mismatches will cause the interface to fail on execution.
(該方法來自EditorExt,只能在desktop使用。它往一個已经存在要素類中添加要素或者向已經存在的表中添加行對象,與數據轉換過程不一样,裝載操作是在一個編輯流程(edit session)內進行的,如果數據裝載失敗的話,会產生一個EnumInvalidObject枚舉變量。數據源可以是shapefile,personal geodatabase等等, 而CAD不能作為數據源.)

你可能感兴趣的:(conversion)