Select to view content in your preferred language

Arcpy - Rebuild indexes in file geodatabase

2625
9
12-04-2019 10:00 AM
MaximeDemers
Frequent Contributor

I am trying to automatize the rebuild of file geodatabase indexes using arcpy v10.6, but I encounter an ERROR 000837 The workspace is not the correct workspace type.

Why? Does arcpy.RebuildIndexes_management() works only with Enterprise geodatabases? Then, how to rebuild indexes in file geodatabases?

Thank you

import arcpy, os

workspace = "C:/tmp/myDatabase.gdb"
fc = "MyFeatureClass"
arcpy.Exists(workspace)
>>>True
arcpy.Exists(os.path.join(workspace, fc))
>>>True

arcpy.RebuildIndexes_management(workspace, "NO_SYSTEM", [fc], "ALL")
>>>ERROR 000837 The workspace is not the correct workspace type.‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
9 Replies
JoeBorgione
MVP Emeritus

Can you run the tool manually on the fgdb?

That should just about do it....
0 Kudos
MaximeDemers
Frequent Contributor

It seems that you can only use that tool with Enterprise geodatabase because the first parameter in the toolbox accepts only .sde files...

0 Kudos
JoeBorgione
MVP Emeritus

That's what it looks like to me as well...

Rebuild dataset indexes using the Rebuild Indexes tool—ArcGIS Help | ArcGIS Desktop 

That should just about do it....
0 Kudos
MaximeDemers
Frequent Contributor

Then, the solution would be to drop and recreate the indexes?

0 Kudos
JoeBorgione
MVP Emeritus

I just have to ask: What's the end game?  Why do you need your indexes rebuilt?

That should just about do it....
0 Kudos
MaximeDemers
Frequent Contributor

Because the data is updated regularly in this database

0 Kudos
KimOllivier
Honored Contributor

You just use the ArcTool arcpy.management.AddSpatialIndex(). The help explains it will rebuild an existing index. Since the indexing is simpler you don't need to specify the spatial grid sizes. I have done this after loading data into a large featureclass and it makes a huge difference to drawing speed and processing.

If processes appear to hang it is always worthwhile to interrupt the process, rebuild the indexes (including attribute indexes) and restart the process. Never be happy with any tool that takes longer than a cup of coffee. Find a better way.

Note that you need to ensure that your features are small and contiguous relative to the full extent. If you have a large 'Mozilla' feature such as an enclosing coastline or large area punctuated with 'holes' representing forest you will defeat the spatial indexing. This is what the DICE tool is for, to split up unreasonably large polygons.

The same applies to polylines. A single line representing a national highway included with short local roads will make all processes that use an index be very slow. Also do not be tempted to dissolve by a single attribute to 'normalize' the attribute table where one zone is represented by thousands of multi-part polygons.

Running processing across a network is likely to be very slow. Process locally, which means: extract, process, replace.

MaximeDemers
Frequent Contributor

Thank you for the great explanations. It's very useful!

I have another question about indexes, maybe you could answer it...

When you copy a file geodatabase using arcpy.CopyManagement() or when publishing a service to ArcGIS Server Enterprise and data are copied, does the indexes are recreated or just copied as is?

0 Kudos
MarkVolz1
New Contributor

Hi,

I know this is a bit late but when using file gdb's you can only add and delete an attribute index, not rebuild it (unless you use the above cheat with the spatial index ). The arcpy functions to do these operations can be found here: An overview of the Indexes toolset—ArcMap | Documentation 

0 Kudos