Is there a tool to Recalculate Feature Extents

10767
15
Jump to solution
01-12-2016 09:54 PM
BenVan_Kesteren1
Occasional Contributor III

Hi,

I have hundreds of feature datasets that have incorrect XY entents (unknown reason as to why), but I am hoping to save time by automating the pressing of the 'Recalculate' button as seen below:

2016-01-13 165116 Feature Class Properties .jpg

Does anyone know of a tool that I can run with an iterator to run over each of my feature classes???

Thanks

1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

In this thread Recalculate Extent jake provides some ways to do this (for featureclasses residing in SDE and other geodatabases).

And these threads arcpy - Pythonic way to recalculate feature extent in ArcGIS 10.2 - Geographic Information Systems S... and arcgis desktop - Recalculating full extent of File Geodatabase feature class? - Geographic Informati... on GIS Stack Exchange might be interesting too.

View solution in original post

15 Replies
NeilAyres
MVP Alum

Do you know why it is wrong?

Are you sure that there is not some fluff somewhere out of sight?

Create Spatial Index might update the extent, but not sure.

DanPatterson_Retired
MVP Emeritus

Neil is right, if memory serves that was a problem solver when processing on shapefiles ( a translation, I think) were not reflected until the shape field index was recalculated.

And check your environment settings

Maintain Spatial Index (Environment setting

or to rebuild Add Spatial Index

DougBrowning
MVP Esteemed Contributor

I had a 0,0 point.  I deleted and the Extent still will not recal properly.  I tried removing the Spatial Index and it still will not recalc.  

The DB is part of a replica but I have replicated several times.

Any other ideas?  It is doing it on 3 FCs.

I have has ones in the past that I tried for years to fix and never did get it.  If I export to a new GDB the extent is correct.

Thanks

0 Kudos
XanderBakker
Esri Esteemed Contributor

In this thread Recalculate Extent jake provides some ways to do this (for featureclasses residing in SDE and other geodatabases).

And these threads arcpy - Pythonic way to recalculate feature extent in ArcGIS 10.2 - Geographic Information Systems S... and arcgis desktop - Recalculating full extent of File Geodatabase feature class? - Geographic Informati... on GIS Stack Exchange might be interesting too.

JasonTipton
Occasional Contributor III

The arcpy tool to do this is Recalculate Feature Class Extent​.

arcpy.RecalculateFeatureClassExtent_management(feature_class)

You will still need exclusive lock on the feature class, but it should do the exact same thing as right clicking on the feature through the GUI.

EDIT

Sorry, I have a help ticket in for the same thing and this is what they suggested, but I just went to try it and it appears to not be available until 10.4 which should be available any day now...

0 Kudos
JasonTipton
Occasional Contributor III

Also, fun fact. If this is an Enterprise Geodatabase, it looks like you are just updating the shape column in the GDB_Items table.

System tables of a geodatabase stored in Oracle—Help | ArcGIS for Desktop

It would be really easy to just update that table... but probably not a supported workflow. At least you know what it is updating and can monitor it.

For example, I have a lot of feature classes that don't have extent information. I can find that by

select name, sde.st_astext(shape) 
from gdb_items
where shape is null
or dbms_lob.compare(sde.st_astext(shape), 'POLYGON EMPTY') = 0
DanPatterson_Retired
MVP Emeritus

Jason

for version 10.4 yes .... but not for 10.3 or prior

An overview of the Feature Class toolset—Help | ArcGIS for Desktop

The help version numbers are defaulting to 10.4

JasonTipton
Occasional Contributor III

Yes, so if going ahead and getting 10.4 is possible, you can use the arcpy tool. I'm using it now. It's kind of slow, but it is getting the work done....

Here's some code I banged out real quick. It will loop over every feature class in a workspace and calculate new extents for them all.

def calculate_extents(workspace):
    arcpy.env.workspace = workspace


    # Get the user name for the workspace
    user_name = arcpy.Describe(workspace).connectionProperties.user.lower()
    print user_name


    # Get a list of all the datasets the user owns.
    dataList = arcpy.ListFeatureClasses('{}*'.format(user_name.upper()))
    print(len(dataList))
   
    # Next, for feature datasets get all of the datasets and featureclasses
    # from the list and add them to the master list.
    for dataset in arcpy.ListDatasets('{}*'.format(user_name.upper()), "Feature"):
        arcpy.env.workspace = os.path.join(workspace,dataset)
        dataList += arcpy.ListFeatureClasses()


    # reset the workspace
    arcpy.env.workspace = workspace
    print('Setting Accept Connections => False')
    arcpy.AcceptConnections(workspace, False)
    print('Disconnecting Users {}'.format(arcpy.ListUsers(workspace)))
    arcpy.DisconnectUser(workspace, "ALL")
   
    for feature in dataList:
        while True:
            print feature
            try:
                extent1 = str(arcpy.Describe(feature).extent)
                arcpy.RecalculateFeatureClassExtent_management(feature)
                extent2 = str(arcpy.Describe(feature).extent)
                updated = 'UPDATED'
                if (extent1 == extent2):
                    updated = 'SAME'
                print('{}: {} =>\t{}'.format(updated, extent1,extent2))
                break
            except arcgisscripting.ExecuteError:
                print('ERROR -- Attempting to disconnect users')
                arcpy.DisconnectUser(workspace, "ALL")


    arcpy.AcceptConnections(workspace, True)

I'm using an Oracle database with no datasets. All feature classes are top level, so I'm not sure if this will traverse the datasets. It should, but I didn't have any to test it with. Also, I am filtering only the tables owned by the current user (ex: current_user.table_name). You can get rid of that on lines 11 and 16. I'm not sure how SQL Server handles all that...

Also, it seems to error out a lot, so I'm infinitely looping until it succeeds so it could stick forever on a bad feature class, but I haven't had it do that yet. Just be aware if it keeps printing the same feature class over and over, it's stuck...

NeilAyres
MVP Alum

Well, what's this doing in the code?

while True:

Looks like it will just keep going around and around forever.