// Converts a GlobalID field to a GUID field.
public static void ConvertGlobalIdToGuid(IWorkspace workspace, String
datasetName)
{
// Open the table.
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
ITable table = featureWorkspace.OpenTable(datasetName);
// Get the GlobalID field.
IClassEx classEx = (IClassEx)table;
if (!classEx.HasGlobalID)
{
throw new Exception(String.Format("No GlobalID column in table: {0}.",
datasetName));
}
String globalIDFieldName = classEx.GlobalIDFieldName;
// Convert the GlobalID column to a GUID column.
IClassSchemaEditEx classSchemaEditEx = (IClassSchemaEditEx)table;
classSchemaEditEx.UnregisterGlobalIDColumn(globalIDFieldName);
}
2 一下代码实现将普通的字段转变成GlobalID
/ Converts a GUID field to a GlobalID field.
public static void ConvertGuidToGlobalId(IWorkspace workspace, String
datasetName, String guidFieldName)
{
// Open the table.
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
ITable table = featureWorkspace.OpenTable(datasetName);
// Get the GUID field to convert.
IFields fields = table.Fields;
int guidFieldIndex = fields.FindField(guidFieldName);
IField guidField = fields.get_Field(guidFieldIndex);
if (guidField.Type != esriFieldType.esriFieldTypeGUID)
{
throw new Exception(String.Format("Field {0} is not a GUID field.",
guidFieldName));
}
// Convert the GUID column to a GlobalID column.
IClassSchemaEditEx classSchemaEditEx = (IClassSchemaEditEx)table;
classSchemaEditEx.RegisterGlobalIDColumn(guidField.Name);
}
本文介绍了如何在特定工作空间中将数据集的普通字段转换为全局ID(Global ID)和GUID(通用唯一识别符)字段,包括了从全局ID到GUID的转换以及从GUID到全局ID的转换过程。
5451

被折叠的 条评论
为什么被折叠?



