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?

  • If this answer works it sounds like by far the easiest way to do this. – PolyGeo Feb 26 '15 at 21:27
  • I read something before that said if you compacted the database, it would recalculate the extents. I cannot confirm nor deny it, but I thought it could be something you look into. – Branco Feb 26 '15 at 21:38
  • @Branco That may have come from another answer on the same question. – PolyGeo Feb 26 '15 at 21:49
  • Compacting is actually the chosen answer for that question Branco. I'm not sure if I can do compression unless I can apply it to just one dataset. Polygeo, did you mean that the manual way of calculating extent (right click, properties, spatial extent, recalculate) as your suggested answer? I want to programmatically do this. Recalculating the extent is one step in a longer process of standardizing a dataset. – Tiffany Mar 2 '15 at 17:09

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.

    #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

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

  • I can't disconnect all of the users from the database while this is going on, there are too many people using it. The process will be used one dataset at a time because not all of the data in the SDE are ready to be standardized so I want the compression to only apply to the dataset given in the initial parameters. – Tiffany Mar 2 '15 at 17:04
  • in documentation of geodatabase compression they say When the Compress tool is executed, the geodatabase is unavailable until compression is completed – geogeek Mar 3 '15 at 6:39

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

  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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.