// Create new workspace name objects. IWorkspaceName sourceWorkspaceName = new WorkspaceNameClass();
IWorkspaceName targetWorkspaceName = new WorkspaceNameClass();
IName targetName = (IName)targetWorkspaceName;

// Set the workspace name properties.
sourceWorkspaceName.PathName = @
    "C:\arcgis\ArcTutor\BuildingaGeodatabase\Montgomery.gdb";
sourceWorkspaceName.WorkspaceFactoryProgID =
    "esriDataSourcesGDB.FileGDBWorkspaceFactory";
targetWorkspaceName.PathName = @"PartialMontgomery.gdb";
targetWorkspaceName.WorkspaceFactoryProgID =
    "esriDataSourcesGDB.FileGDBWorkspaceFactory";

// Create a name object for the source feature class.
IFeatureClassName featureClassName = new FeatureClassNameClass();

// Set the featureClassName properties.
IDatasetName sourceDatasetName = (IDatasetName)featureClassName;
sourceDatasetName.WorkspaceName = sourceWorkspaceName;
sourceDatasetName.Name = "Blocks";
IName sourceName = (IName)sourceDatasetName;

// Create an enumerator for source datasets.
IEnumName sourceEnumName = new NamesEnumeratorClass();
IEnumNameEdit sourceEnumNameEdit = (IEnumNameEdit)sourceEnumName;

// Add the name object for the source class to the enumerator.
sourceEnumNameEdit.Add(sourceName);

// Create a GeoDBDataTransfer object and a null name mapping enumerator.
IGeoDBDataTransfer geoDBDataTransfer = new GeoDBDataTransferClass();
IEnumNameMapping enumNameMapping = null;

// Use the data transfer object to create a name mapping enumerator.
Boolean conflictsFound = geoDBDataTransfer.GenerateNameMapping(sourceEnumName,
    targetName, out enumNameMapping);
enumNameMapping.Reset();

// Check for conflicts.
if (conflictsFound)
{
    // Iterate through each name mapping.
    INameMapping nameMapping = null;
    while ((nameMapping = enumNameMapping.Next()) != null)
    {
        // Resolve the mapping's conflict (if there is one).
        if (nameMapping.NameConflicts)
        {
            nameMapping.TargetName = nameMapping.GetSuggestedName(targetName);
        }

        // See if the mapping's children have conflicts.
        IEnumNameMapping childEnumNameMapping = nameMapping.Children;
        if (childEnumNameMapping != null)
        {
            childEnumNameMapping.Reset();

            // Iterate through each child mapping.
            INameMapping childNameMapping = null;
            while ((childNameMapping = childEnumNameMapping.Next()) != null)
            {
                if (childNameMapping.NameConflicts)
                {
                    childNameMapping.TargetName = childNameMapping.GetSuggestedName
                        (targetName);
                }
            }
        }
    }
}

posted on 2010-12-17 22:28  醉意人间  阅读(622)  评论(0编辑  收藏  举报