[GIS] Pythonic way to recalculate feature extent in ArcGIS 10.2

arcgis-desktoparcpyenterprise-geodatabaseextents

I am creating a tool that will automate a tedious process of data standardization. One of the steps is to recalculate the feature extent of a SDE file. Surprisingly I cannot find anything useful in regards to recalculating feature extent, except for a VBA script here: Recalculating full extent of File Geodatabase feature class? and a tool here: http://www.arcgis.com/home/item.html?id=576ebff497094274bdd7c76e456de6c3. Unfortunately I don't know VBA well enough to understand fully what is going on or how to incorporate it into my existing Python script, nor do I know how to call an add-in. Also I will not be the only one using this tool and I'd rather avoid making everyone who uses the tool download the add-in. I've heard about reboxing but it doesn't seem like it's used anymore. Does anyone have any ideas on what I could do or how to use the VBA script in my Python script?

Best Answer

Like in the comment of PolyGeo, Compacting database recalculates feature class extent, so here is an arcpy script to automate this task and also to make rebuild index and analyze:

import arcpy , sys , os , subprocess
arcpy.env.overwriteOutput = True

def main():

    db_path = os.path.join(os.path.dirname(__file__), "Connection_db_name.sde")
    arcpy.env.workspace = db_path

    #disconnect all users from the database.
    arcpy.DisconnectUser(db_path, "ALL")

    # Run the compress tool.
    arcpy.Compress_management(db_path)

    #Allow the database to begin accepting connections again
    arcpy.AcceptConnections(db_path, True)


    # Get a list of all the datasets the user has access to.
    # First, get all the stand alone tables, feature classes and rasters.
    dataList = arcpy.ListTables() + arcpy.ListFeatureClasses() + arcpy.ListRasters()

    # Next, for feature datasets get all of the featureclasses
    # from the list and add them to the master list.
    for dataset in arcpy.ListDatasets():
        dataList += arcpy.ListFeatureClasses(feature_dataset=dataset)


    # pass in the list of datasets owned by the admin to the rebuild indexes and analyze datasets tools
    # Note: to use the "SYSTEM" option the user must be an administrator.
    arcpy.RebuildIndexes_management(db_path, "SYSTEM", dataList, "ALL")

    arcpy.AnalyzeDatasets_management(db_path, "SYSTEM", dataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE")

    ##this feature class if not deleted may cause some problems in the next compress
    arcpy.Delete_management(db_name+".sde.sde_compress_log")

Geodatabase compression requires disconnecting all the users because When the Compress tool is executed, the geodatabase is unavailable until compression is completed

Related Question