ESRI.ArcGIS.Geodatabase.IWorkspace _ws = (ESRI.ArcGIS.Geodatabase.IWorkspace)aWorkspaceEdit; ESRI.ArcGIS.Geodatabase.IEnumDataset _ed = _ws.get_Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureDataset); ESRI.ArcGIS.Geodatabase.IDataset _ds = null; while ((_ds = _ed.Next()) != null) { if (_ds.BrowseName == _datasetName) { ESRI.ArcGIS.Geodatabase.IEnumDataset _dsed = _ds.Subsets; ESRI.ArcGIS.Geodatabase.IDataset _dsfc = null; while ((_dsfc = _dsed.Next()) != null) { if (_dsfc.BrowseName == aFeatureClassName) { _fc = (ESRI.ArcGIS.Geodatabase.IFeatureClass)_dsfc; break; } } } if (_fc == null) { _ds = _ed.Next(); } else { break; } } _ed.Reset();
Solved! Go to Solution.
ESRI.ArcGIS.Geodatabase.IEnumDatasetName _ed = _ws.get_DatasetNames(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureDataset); ESRI.ArcGIS.Geodatabase.IDatasetName _ds = null; IFeatureClass _fc = null; while ((_ds = _ed.Next()) != null) { if (_ds.Name==_datasetName) { ESRI.ArcGIS.Geodatabase.IEnumDatasetName _dsed = _ds.SubsetNames; ESRI.ArcGIS.Geodatabase.IDatasetName _dsfc = null; while ((_dsfc = _dsed.Next()) != null) { if (_dsfc.Name==aFeatureClassName) { IName name = _dsfc as IName; IDataset dataset = name.Open() as IDataset; _fc = (ESRI.ArcGIS.Geodatabase.IFeatureClass)dataset; break; } } } if (_fc != null) { break; } } _ed.Reset();
Are you able to view those feature datasets from arccatalog with the workspace connection utilized in your code?
The feature dataset retrieved by if (_fc == null) {
_ds = _ed.Next();
} logic is overwritten by next feature datasetwhile ((_ds = _ed.Next()) != null). Did you intend to skip the feature dataset in your logic? if not
Replace
if (_fc == null) {
_ds = _ed.Next();
}
else {
break;
}
with
if(_fc!=null)
{
break;
}
IName name = datasetName as IName; IDataset _dsfc = name.Open() as IDataset; _fc = (ESRI.ArcGIS.Geodatabase.IFeatureClass)_dsfc;
I was able to get all the feature datasets with the same logic. BTW never use IEnumDataset if you intend to just iterate through the objects to retrieve the objectname. It not only slows down the proces it also causes memory leak. Use IEnumDatasetName instead. You can use below logic to construct featureclass from IDatasetName.IName name = datasetName as IName; IDataset _dsfc = name.Open() as IDataset; _fc = (ESRI.ArcGIS.Geodatabase.IFeatureClass)_dsfc;
ESRI.ArcGIS.Geodatabase.IEnumDatasetName _ed = _ws.get_DatasetNames(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureDataset); ESRI.ArcGIS.Geodatabase.IDatasetName _ds = null; IFeatureClass _fc = null; while ((_ds = _ed.Next()) != null) { if (_ds.Name==_datasetName) { ESRI.ArcGIS.Geodatabase.IEnumDatasetName _dsed = _ds.SubsetNames; ESRI.ArcGIS.Geodatabase.IDatasetName _dsfc = null; while ((_dsfc = _dsed.Next()) != null) { if (_dsfc.Name==aFeatureClassName) { IName name = _dsfc as IName; IDataset dataset = name.Open() as IDataset; _fc = (ESRI.ArcGIS.Geodatabase.IFeatureClass)dataset; break; } } } if (_fc != null) { break; } } _ed.Reset();
Yes. You want a reference of one feature class not all feature classes in the feature dataset. If a feature dataset contains 20 feature class your logic is creating 20 feature class objects in memory although you are not using it. IDatasetName object supply object name info and not the object itself. When you debug your logic you may notice a delay on _ds.Subsets and _ws.get_Datasets statements. I modified your code to use IDatasetName. If you prefer less code then use IWorkspace2.get_NameExists method instead of iterating through the datasetnames.ESRI.ArcGIS.Geodatabase.IEnumDatasetName _ed = _ws.get_DatasetNames(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureDataset); ESRI.ArcGIS.Geodatabase.IDatasetName _ds = null; IFeatureClass _fc = null; while ((_ds = _ed.Next()) != null) { if (_ds.Name==_datasetName) { ESRI.ArcGIS.Geodatabase.IEnumDatasetName _dsed = _ds.SubsetNames; ESRI.ArcGIS.Geodatabase.IDatasetName _dsfc = null; while ((_dsfc = _dsed.Next()) != null) { if (_dsfc.Name==aFeatureClassName) { IName name = _dsfc as IName; IDataset dataset = name.Open() as IDataset; _fc = (ESRI.ArcGIS.Geodatabase.IFeatureClass)dataset; break; } } } if (_fc != null) { break; } } _ed.Reset();