Arcpy - Recalculating spatial indexes

1992
2
03-01-2018 07:36 AM
by Anonymous User
Not applicable

Hello everyone,

I work in database conversions and I've been getting my feet wet in python. My programming skills are very basic but I've been improving. We know the benefits of going into ArcCatalog and recalculating spatial indexes - especially after a conversion, it takes us from an extreme set of extents to something actually reasonable. Subsequent tools and the live software run much faster. Obviously this is low-hanging fruit for a python script and there is probably something already out there, but the practice is worth it to me. The problem is, the code runs but I'm not seeing any changes through ArcCatalog. The "extents" remain unchanged in the spatial index tab. Even empty feature classes retain their extents instead of going to 0/0/0/0. The Recalculate button does make that change - why doesn't my script? This is a SQL database with ESRI 10.2 format (I know, unfortunately I am limited to that version right now). 

Based on examples I found online, I used both RebuildIndexes_management and AnalyzeDatasets_management. The examples I saw fed a list of feature classes into the function once, I'm trying to do it one by one for logging purposes but I'm not sure if that's the best idea. My timestamped logs show each feature class took approximately 30 seconds, whether it was empty or gigantic, and it took four hours to work through the database. And then I don't see any extents change in ArcCatalog. I'm not clear on what I'm doing wrong. 

def RecalculateSpatialIndexes(databaseFilePath, T, logger):

    arcpy.env.workspace = databaseFilePath
    featureList = arcpy.ListFeatureClasses()

    printLog('--------------Beginning to Recalculate Spatial Indexes ---------------', T, logger)
    printLog('FeatureList: ' + str(featureList),T,logger)
    for f in featureList:
        printLog('Recalculating spatial index for: ' + str(f),T,logger)
        try:
            arcpy.RebuildIndexes_management(databaseFilePath, "NO_SYSTEM", f, "ALL")
            printLog('Running AnalyzeDatasets: ' + str(f),T,logger)
            arcpy.AnalyzeDatasets_management(databaseFilePath, "NO_SYSTEM", f, "ANALYZE_BASE", "ANALYZE_DELTA","ANALYZE_ARCHIVE")
        except Exception as err:
            printLog(str(err),T,logger)
            break
0 Kudos
2 Replies
JoshuaBixby
MVP Esteemed Contributor

If you run the Rebuild Indexes tool on one data set from ArcCatalog, and then compare that code snippet in the Results window to the call you are using in your code for the same data set, how do they compare?

0 Kudos
by Anonymous User
Not applicable

Running the ArcToolbox equivalent is certainly a good idea. I've done the rebuild indexes and analyze dataset tools, they return successfully just like in my python script, but neither of them are updating the "bounding box" within the spatial index tab. I've tried it on an empty feature class and a populated feature class and it just doesn't change. So it makes sense that the python version isn't doing anything either. I look at SQL Server Management Studio and the spatial index there is also unchanged. I'm having a fundamental misunderstanding here...if it's relevant at all, I'm using standalone feature classes that are not in any datasets, they are registered as versioned with the option to move edits to base.