Recalculating the feature extent in python?

1374
5
02-08-2014 02:30 AM
OrZarchi
New Contributor
Hi,
Is there a way to simulate recalculating the extent of a feature class in arcpy?
This is needed, for example, after adding or deleting features as the extent isn't automatically reboxed.
I've searched the forums, and I know it can easily be done manually in ArcCatalog, and I found some examples using arcobjects.
Nothing for arcpy so far.
Thanks
Tags (2)
0 Kudos
5 Replies
KimOllivier
Occasional Contributor III
Use the Describe object to find the extent of the dataset. A single featureclass can be its own dataset.
print arcpy.Describe('seacoast').extent

1089354.4464 4747978.9305 2092003.9868 6223163.9395 NaN NaN NaN NaN
0 Kudos
OrZarchi
New Contributor
Thanks,
I asked about recalculating a FC's extent like you can in ArcMap, your method only retrieves a read-only representation.
0 Kudos
KimOllivier
Occasional Contributor III
Describe will dynamically recalculate the extent of all the features in a featureclass after your changes. You cannot reset it, it is a property of the extent of all the features used for creating spatial indexing.

Here is a test using the Python window in ArcMap
 arcpy.env.workspace = r'E:\project\forumhelp'
>>> print arcpy.Describe("sourcearea").extent
2626051.8 185544.48 2626576.5 186112.94 NaN NaN NaN NaN
>>> # moved a vertex to the left, saved
>>> print arcpy.Describe("sourcearea").extent
2625867.4387207 185544.480102539 2626576.50012207 186112.940124512 NaN NaN NaN NaN


I do not know what you are 'recalculating' in ArcMap. I cannot find a property in the layer dialog. Do you mean that you are setting the extent of the data frame for the full extent command to override the default extent?

Once you have the extent object from Describe you can program the dataframe extent using the Mapping module and the DataFrame object. Or you could modify the extent object first to say add 10% before using it.
0 Kudos
OrZarchi
New Contributor
Hi,
I found another thread (with a screenshot) describing the problem.
http://forums.arcgis.com/threads/77105-Recalculate-Extent?p=271206&viewfull=1#post271206
There you can see the feature extent property I'm referring to.
While using arcpy.Describe indeed always returns the correct extent, the "other" extent values seen in the screenshot (http://forums.arcgis.com/attachment.php?attachmentid=21603&d=1360324936) are never recalculated.
The reason I care about these numbers?
In my workflow I'm trying to publish a feature class to an arcgis server, and the resulting feature service's extent is locked to these values, disregarding the actual FC extent.
The attached threads only offer workarounds, I was hoping for a better solution.
0 Kudos
KimOllivier
Occasional Contributor III
If you have found an arcobjects solution, it is possible to call arcobjects from Python. Mark Cederholm has had several presentations at Esri conferences on how to do this using comtypes. Maybe this is a last resort?
0 Kudos