Summary
EnvManager is a class for managing geoprocessing environments.
The environment settings set by the EnvManager class are temporary. Whether using EnvManager as a function decorator or in a with block, the environment settings are only set for that duration. At the completion of the with block or the end of the decorated function, the environments passed to the EnvManager class will revert to their previous values (you do not need to manually reset the environment values). The code indented under the with statement can include a single line of code or multiple lines.
Syntax
EnvManager (**kwargs)
| Parameter | Explanation | Data Type |
**kwargs | Environment settings are passed as keyword arguments; one or more environments can be passed using the environment name. For a complete list of the environments and their names, see the env class. | Variant |
Method Overview
| Method | Explanation |
| reset () | Resets the environment settings to their values prior to calling the EnvManager class. |
Methods
reset ()
Code sample
Use the EnvManager class to temporarily set the cellSize and extent environments before running the PointDensity function.
import arcpy
feature_class = r'd:\data\data.gdb\cities'
with arcpy.EnvManager(cellSize=10, extent='-16, 25, 44, 64'):
raster = arcpy.sa.PointDensity(feature_class, 'POP_RANK')Use the EnvManager class to temporarily set the workspace environment before accessing the ListFeatureClasses function.
import arcpy
with arcpy.EnvManager(workspace=r'd:\data\data.gdb'):
feature_classes = arcpy.ListFeatureClasses(feature_type='POLYGON')
print('The polygon feature classes are {}'.format(', '.join(feature_classes)))Use the EnvManager class as a decorator to set the workspace environment on a function declaration.
import arcpy
@arcpy.EnvManager(workspace=r'd:\data\data.gdb')
def myFunc(**kwargs):
fc_lst = arcpy.ListFeatureClasses()