Esri / file-geodatabase-api

FileGeodatabaseAPI_1.4 (1.4.0.183) The File Geodatabase C++ API for Windows, MacOS and Linux
Apache License 2.0
154 stars 60 forks source link

How to List All Datasets? #26

Closed sunzechang closed 5 years ago

sunzechang commented 5 years ago

If I dont Know the names of datasets,how do I get datasets

lshipman commented 5 years ago
#include <string>
#include <iostream>
#include <fstream>

#include <FileGDBAPI.h>

using namespace std;
using namespace FileGDBAPI;

int main()
{
  // Open the geodatabase.
  fgdbError hr;
  wstring errorText;
  Geodatabase geodatabase;
  if ((hr = OpenGeodatabase(L"C:/FileGDB_API_Test/OpenTable/TemplateData_Protected.gdb", geodatabase)) != S_OK)
  {
    wcout << "An error occurred while opening the geodatabase." << endl;
    ErrorInfo::GetErrorDescription(hr, errorText);
    wcout << errorText << "(" << hr << ")." << endl;
    return -1;
  }

  // Test GetChildDatasets
  wcout << "Test GetChildDatasets:" << endl;
  std::vector<std::wstring> childList;
//  if ((hr = geodatabase.GetChildDatasets(L"\\World", L"Feature Class", childList)) != S_OK)
  if ((hr = geodatabase.GetChildDatasets(L"\\", L"", childList)) != S_OK)
  {
    wcout << "An error occurred while getting the child datasets." << endl;
    ErrorInfo::GetErrorDescription(hr, errorText);
    wcout << errorText << "(" << hr << ")." << endl;
    return -1;
  }

  for (size_t i = 0; i < childList.size(); i++)
  {
    wcout << childList[i] << endl;
  }

  // Close the geodatabase
  if ((hr = CloseGeodatabase(geodatabase)) != S_OK)
  {
    wcout << "An error occurred while closing the geodatabase." << endl;
    ErrorInfo::GetErrorDescription(hr, errorText);
    wcout << errorText << "(" << hr << ")." << endl;
    return -1;
  }

  return 0;
}