Wednesday, June 13, 2012

env.ScratchGDB (ArcPy 10.1)

A new environmental parameter as 10.1 is env.scratchGDB.  This environmental parameter is guarantees to have a temporary scratch file geodatabase for your writing pleasure.  This means no more checking to see if a user created a file geodatabase for doing some work.
I personally think this is great.  It takes a common task and puts it into core.  Bravo ArcPy Development Team!
From this help:
Its primary purpose is for use by scripts and models as geoprocessing services, with the added focus of only pointing to a known geodatabase. When ArcGIS for Server executes a geoprocessing task, the scratch GDB is always available to write output to. This environment is also useful in authoring scripts and models for use on the desktop. Writing output to the scratch GDB will make your tool portable, because this location will always be available or created at execution time.

Some notes on the env.scratchGDB:

  1. Scratch GDB will exist if called and user will have write access to the file geodatabase
  2. Scratch GDB is read-only.  You can only change the location of the scratch GDB by changing the env.scratchWorkspace 
  3. If the env.scratchWorkspace is not set, then it defaults to the user's temporary directory

Example:
>>> import arcpy

>>> from arcpy import env
>>> env.scratchWorkspace = r"c:\temp"
>>> print env.scratchGDB
c:\\temp\\scratch.gdb


Enjoy