[GIS] Setting Output Extent (Environment Setting) using ArcPy

arcgis-10.0arcpy

I'm trying to figure out how to set my output extent before creating Thiessen Polygons in a loop of ~100 points shapefile. (ArcMap 10.0 – Python)

for i in range(3,51,1):
    arcpy.CreateThiessenPolygons_analysis("AVF%i" % i,"AVF%iVoronoi" % i,"ONLY_FID")

Basically I want my extent to be the same for each iteration.

I first found:

arcpy.Extent(293490,5898230,316430,5930230)

then someone told me about this ESRI help page:

#use 'CURRENT' if running from ArcMap, when published use MXD on disk

    mxd = arcpy.mapping.MapDocument("CURRENT")

    df = arcpy.mapping.ListDataFrames(mxd)[0]
    newExtent = df.extent
    newExtent.XMin, newExtent.YMin = 293490,5898230
    newExtent.XMax, newExtent.YMax = 316430,5930230
    df.extent = newExtent

but in any case, when I run my loop, the size of the output is not reflecting the changes.

ps: https://stackoverflow.com/questions/8996965/output-extent-environment-setting/8997122#8997122

Best Answer

I think you are just creating an Extent object with:

arcpy.Extent(293490,5898230,316430,5930230)

...but not actually setting the arcpy.env.extent property (unless you have more code that is not posted in your original question). From the docs:

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)  # <-- Have you tried this?

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

Try setting it like:

arcpy.env.extent = arcpy.Extent(293490,5898230,316430,5930230)
Related Question