AnsweredAssumed Answered

Arcpy - Recalculating spatial indexes

Question asked by mdly68 on Mar 1, 2018
Latest reply on Mar 1, 2018 by mdly68

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

Outcomes