Switching into load only mode and back will rebuild the index.
Try the following:
// Open the geodatabase.
fgdbError hr;
wstring errorText;
Geodatabase geodatabase;
if ((hr = OpenGeodatabase(L"C:/FileGDB_API_Test/OpenTable - Copy/TemplateData.gdb", geodatabase)) != S_OK)
{
wcout << "An error occurred while opening the geodatabase." << endl;
ErrorInfo::GetErrorDescription(hr, errorText);
wcout << errorText << "(" << hr << ")." << endl;
return -1;
}
wcout << '\n' << "Open TemplateData.gdb" << '\n' << endl;
// Open the counties table.
Table table;
if ((hr = geodatabase.OpenTable(L"\\counties", table)) != S_OK)
{
wcout << "An error occurred while opening the table." << endl;
ErrorInfo::GetErrorDescription(hr, errorText);
wcout << errorText << "(" << hr << ")." << endl;
return -1;
}
// Switch in and out of LoadOnlyMode. This rebuilds the spatial index
table.LoadOnlyMode(true);
table.LoadOnlyMode(false);
// Close the table
if ((hr = geodatabase.CloseTable(table)) != S_OK)
{
wcout << "An error occurred while closing ManyFieldTypes." << endl;
ErrorInfo::GetErrorDescription(hr, errorText);
wcout << errorText << "(" << hr << ")." << endl;
return -1;
}
// 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;
}
Lance Shipman
Esri
Geodatabase Product Engineer, File Geodatabase, SQLite