GetDefinition<T> Method (Geodatabase)
Gets a specific
Definition instance associated with of type in the geodatabase. This method must be called on the MCT. Use QueuedTask.Run.
Parameters
- name
-
The name of the dataset.
Type Parameters
- T
-
The type of dataset definition.
Return Value
A specific
Definition instance corresponding to type .
Obtaining Definition from Geodatabase
public async Task ObtainingDefinitionFromGeodatabase()
{
await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
{
// Remember that for Enterprise databases you have to qualify your dataset names with the DatabaseName and UserName.
TableDefinition enterpriseTableDefinition = geodatabase.GetDefinition<TableDefinition>("LocalGovernment.GDB.CitizenContactInfo");
// It does not matter if the dataset is within a FeatureDataset or not.
FeatureClassDefinition featureClassDefinition = geodatabase.GetDefinition<FeatureClassDefinition>("LocalGovernment.GDB.FireStation");
// GetDefinition For a RelationshipClass.
RelationshipClassDefinition relationshipClassDefinition = geodatabase.GetDefinition<RelationshipClassDefinition>("LocalGovernment.GDB.AddressPointHasSiteAddresses");
// GetDefinition For a FeatureDataset.
FeatureDatasetDefinition featureDatasetDefinition = geodatabase.GetDefinition<FeatureDatasetDefinition>("LocalGovernment.GDB.Address");
}
});
}
Checking for the existence of a Table
// Must be called within QueuedTask.Run9)
public bool TableExists(Geodatabase geodatabase, string tableName)
{
try
{
TableDefinition tableDefinition = geodatabase.GetDefinition<TableDefinition>(tableName);
tableDefinition.Dispose();
return true;
}
catch
{
// GetDefinition throws an exception if the definition doesn't exist
return false;
}
}
Checking for the existence of a Feature Class
// Must be called within QueuedTask.Run()
public bool FeatureClassExists(Geodatabase geodatabase, string featureClassName)
{
try
{
FeatureClassDefinition featureClassDefinition = geodatabase.GetDefinition<FeatureClassDefinition>(featureClassName);
featureClassDefinition.Dispose();
return true;
}
catch
{
// GetDefinition throws an exception if the definition doesn't exist
return false;
}
}
Target Platforms: Windows 11, Windows 10
ArcGIS Pro version: 3.0 or higher.