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?
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
Avoid doing compress in geodatabase, that is not really want you want to accomplish.
If you are targeting ArcSDE file all you have to do is invoke
sdelayer -o alter -E calc or sdelayer -o alter -E minx,miny,maxx,maxy
from Python using the subprocess module.
You can recalculate the extent of your table by using SQL CTE like this
with cte_envelope as ( select geom.STEnvelope() as envelope from MyTable ), cte_corner as ( select envelope.STPointN(1) as point from cte_envelope union all select envelope.STPointN(3) from cte_envelope ) select min(point.STX) as min_x, min(point.STY) as min_y, max(point.STX) as max_x, max(point.STY) as max_y from cte_corner
If you have a 'Basic' licence, try:
A simple way to recalculate feature extent in the event you have removed spatial features and are trying to zoom to the new extent is to move data into a GDB 'Feature Dataset'. On import the recalculation is performed, so when you 'zoom to layer' it zooms to the new extent of the feature class. I did it this way as the compress method did not work for me.