6

How can i access to feature extent of a feature class and change the extent using arcpy ?

enter image description here

9

You can access the feature extent of a feature class by using the Describe function

import arcpy, os

fc = r'C:\path\to\your.gdb\fc'

desc = arcpy.Describe(fc)

xmin = desc.extent.XMin
xmax = desc.extent.XMax
ymin = desc.extent.YMin
ymax = desc.extent.YMax

print "xmin: %s \nxmax: %s \nymin: %s \nymax: %s" % (xmin, xmax, ymin, ymax)

You can change the output extent in the environment settings (source Esri).

The Output Extent environment setting defines what features or rasters will be processed by a tool. This setting is useful when you need to process only a portion of a larger dataset. You can think of this setting as a rectangle used to select input features and rasters for processing. Any feature or raster that passes through the rectangle will be processed and written to output. Note that the rectangle is used only to select features, not clip them. The extent of the output dataset will typically be larger than the Output Extent setting to account for features that pass through the extent rectangle.

import arcpy

# Set the extent environment using a keyword.
arcpy.env.extent = "MAXOF"

# Set the extent environment using the Extent class.
arcpy.env.extent = arcpy.Extent(-107.0, 38.0, -104.0, 40.0)

# Set the extent environment using a space-delimited string.
arcpy.env.extent = "-107.0 38.0 -104.0 40.0"

If you are referring to changing the actual geometry of a feature class, which may subsequently alter the extent, then your best is to use a Cursor.

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.