Select to view content in your preferred language

Set multiple output extent in python scripting.

557
3
06-21-2013 03:32 PM
SamHuang
Deactivated User
Hi there,

I like to find out how you can set multiple extents within python scripts. For instance setting one extent for clipping analysis follow by setting a new output extent in another clipping analysis ?

Thanks in advance!
0 Kudos
3 Replies
LucasDanzinger
Esri Frequent Contributor
Not sure if this answers your question, but you can reset the arcpy.env.extent however many times you want throughout the script...

import arcpy
from arcpy import env

env.extent = "-107.0 38.0 -104.0 40.0"
arcpy.Clip_analysis(r"C:\temp\indata",r"C:\temp\clipFeatures",r"C:\temp\outFeatures")

env.extent = "-108.0 39.0 -105.0 50.0"
arcpy.Clip_analysis(r"C:\temp\indata1",r"C:\temp\clipFeatures1",r"C:\temp\outFeatures1")
0 Kudos
SamHuang
Deactivated User
Hope anyone can also answer this.

What if you want to set the environment syntax based on another file's extent ? How would the syntax look ? I've tried many different ways and it has  constantly given me an error as follow.

  File "iddea.py", line 71, in iddea
    pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
UnicodeEncodeError: 'ascii' codec can't encode characters in position 40-42: ordinal not in range(128)


thanks in advance
0 Kudos
LucasDanzinger
Esri Frequent Contributor
You would need to describe the source feature class:

import arcpy
desc = arcpy.Describe("pathToFeatureClass")
descExtent = desc.extent #returns an extent object
arcpy.env.extent = descExtent #extent object can be used to set arcpy.env.extent
print arcpy.env.extent
0 Kudos