Is it possible using the API to re-build the spatial index for a layer.
We have an application that runs on Citrix servers. Sometimes they get disconnected and the application is forced to close on the server.
This results in records not being updated in the spatial index. As a result any bounding box queries fail to return the records.
In ArcCatalog I can delete the index then re-add it and then everything is back to normal. I'd like to be able to do that using the API.
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