Parameters
- name
- The name of the dataset to open.
Type Parameters
- T
- The type of dataset to open.
Exception | Description |
---|---|
System.InvalidOperationException | No valid geodatabase has been opened prior to calling this operation. -or- The dataset type corresponding to T is not supported (see DatasetType). -or- Using AttributedRelationshipClass as T to open a dataset whose type is actually DatasetType.RelationshipClass. |
ArcGIS.Core.Data.Exceptions.GeodatabaseException | A geodatabase-related exception has occurred. For example, the name is invalid. |
public async Task OpeningDatasetsFromGeodatabase() { await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => { using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde")))) { using (Table table = geodatabase.OpenDataset<Table>("LocalGovernment.GDB.EmployeeInfo")) { } // Open a featureClass (within a feature dataset or outside a feature dataset). using (FeatureClass featureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.AddressPoint")) { } // You can open a FeatureClass as a Table which will give you a Table Reference. using (Table featureClassAsTable = geodatabase.OpenDataset<Table>("LocalGovernment.GDB.AddressPoint")) { // But it is really a FeatureClass object. FeatureClass featureClassOpenedAsTable = featureClassAsTable as FeatureClass; } // Open a FeatureDataset. using (FeatureDataset featureDataset = geodatabase.OpenDataset<FeatureDataset>("LocalGovernment.GDB.Address")) { } // Open a RelationsipClass. Just as you can open a FeatureClass as a Table, you can also open an AttributedRelationshipClass as a RelationshipClass. using (RelationshipClass relationshipClass = geodatabase.OpenDataset<RelationshipClass>("LocalGovernment.GDB.AddressPointHasSiteAddresses")) { } } }); }
// Create a FileGeodatabaseConnectionPath using the path to the gdb. Note: This can be a path to a .sde file. FileGeodatabaseConnectionPath geodatabaseConnectionPath = new FileGeodatabaseConnectionPath(new Uri(@"C:\Temp\rasters.gdb")); // Create a new Geodatabase object using the FileGeodatabaseConnectionPath. Geodatabase geodatabase = new Geodatabase(geodatabaseConnectionPath); // Open the raster dataset. RasterDataset gdbRasterDataset = geodatabase.OpenDataset<RasterDataset>("sample");
Target Platforms: Windows 11, Windows 10