使用FileGDB API提供的函数GetChildDatasets可以像ArcCatalog一样,访问FileGDB的目录结构,包括FileGDB所包括的FeatureDataset,FeatureClass,RasterDatast,RasterCatalog,MosaicDataset等等,在FileGDB API中一共包含以下几种类型:
Feature Class Item Range Domain Extension Dataset Parcel Fabric Workspace Extension Domain Relationship Class Raster Catalog Folder Tin Dataset Survey Dataset AbstractTable Mosaic Dataset Feature Dataset Schematic Dataset Terrain Replica Dataset Network Dataset Historical Marker Catalog Dataset Resource Table Raster Dataset Geometric Network Topology Toolbox Coded Value Domain Replica Representation Class Workspace
以下的步骤是访问FileGDB中根目录中所有的FeatureDataset以及各个FeatureDataset下所包括的FeatureClass的代码以及实现结果。
1. 使用ArcCatalog创建一个FileGDB,名称为TestFileGDB,向其中录入一些FeatureDataset以及FeatureClass和普通表,结果如下图:
2. 自己写个例子程序运行结果如下,(此程序纯c++实现的console例子程序,没有使用任何的linux的界面库)
3. 实现代码如下:
#include #include #include <string> #include #include #include #include #define EXT_FILEGDB_API _declspec(dllimport) #pragma warning (disable : 4251) #include "Geodatabase.h" #include "GeodatabaseManagement.h" using namespace std; using namespace FileGDBAPI; Geodatabase geodatabase; long getchilddataset(std::wstring parentDataset, std::wstring DatasetType,std::vector& childDatasets); int main() { // Create a new geodatabase in the current directory. long hr; // Re-open the geodatabase. if ((hr = OpenGeodatabase(L"../data/TestFileGDB.gdb", geodatabase)) != S_OK) { wcout << "An error occurred while opening the geodatabase." << endl; wcout << "Error code: " << hr << endl; return -1; } wcout << "The geodatabase has been opened." << endl; std::vector childDatasets; std::vector childFeatureClass; hr = getchilddataset(L"//",L"Feature Dataset",childDatasets); if(S_OK != hr) { wprintf(L"%s/n",L"An error occurred whild getchilddata from root"); wprintf(L"Error code: %d/n",hr); return -1; } int index = 0; int FeatureClassIndex = 0; int FeatureDataCount = (int)childDatasets.size(); int FeatureClassCount = 0; wprintf(L"TestFileGDB/n"); //wcout << "--"; for(index = 0; index < FeatureDataCount; index++) { std::wstring DatasetName = (std::wstring)childDatasets.at(index); wcout << " " << DatasetName << endl; childFeatureClass.clear(); hr = getchilddataset(DatasetName,L"Feature Class",childFeatureClass); if(S_OK == hr) { FeatureClassCount = (int)childFeatureClass.size(); for(FeatureClassIndex = 0; FeatureClassIndex " << FeatureClassName <//",L"Feature Class",childFeatureClass); FeatureClassCount = (int)childFeatureClass.size(); if(S_OK == hr) { for(FeatureClassIndex = 0; FeatureClassIndex < FeatureClassCount; FeatureClassIndex++) { std:wstring FeatureClassName = childFeatureClass.at(FeatureClassIndex); wcout << " " << FeatureClassName < tablelist; int tablecount = 0; int tableindex = 0; std::wstring tablename; hr = getchilddataset(L"//",L"Table",tablelist); if(S_OK == hr) { tablecount = (int)tablelist.size(); for(tableindex = 0; tableindex < tablecount; tableindex++) { tablename = tablelist.at(tableindex); wcout << " " << tablename << endl; } } // Close the geodatabase before the delete. if ((hr = CloseGeodatabase(geodatabase)) != S_OK) { wcout << "An error occurred while closing the geodatabase." << endl; wcout << "Error code: " << hr << endl; return -1; } return 0; } long getchilddataset(std::wstring parentDataset, std::wstring DatasetType,std::vector& childDatasets) { long result = geodatabase.GetChildDatasets(parentDataset,DatasetType,childDatasets); return result; }
整个工程会在整个系列完成后上传。