ArcMap

The new ScratchGDB and ScratchFolder environments

One of the enhancements to the 10.1 release was the addition of two new environment variables (scratchFolder and scratchGDB) as mentioned in the What’s New for Geoprocessing in 10.1. (If you haven’t read it, check out all enhancements!). While new environment variables may not exactly sound exciting, as a tool developer you’ll want to know this as you probably have worried at one point about handling intermediate data in your model, script or custom function tool. Generally you would want to be writing intermediate outputs to the “in_memory” workspace for performance gains, but there will be times you must persist the output to disk.

Prior to 10.1 you made use of the scratchWorkspace environment to write intermediate data. The scratchWorkspace provides the ability to write temporary data, but can be problematic as it can be either a folder or a geodatabase (depending on how your environment referenced it). You may have constructed your tool thinking that scratchWorkspace is a folder, as you’ve set ArcMap’s scratch location to a folder. When you shared your tool with a co-worker, their scratch environment setting was set to their Default.gdb and your tool failed as it tried to write shapefiles (.shp) into their file geodatabase.

This is where it starts to get exciting. At 10.1 these two new environment variables help you control where your output will be written to. Exactly as they sound, scratchFolder writes to a folder and scratchGDB writes to a geodatabase. Use them in your scripts and models in the same way you do now with the scratchWorkspace.

 

As shown, use the inline variables %scratchFolder% or scratchGDB% inside your models.

Or reference the environments while scripting by using arcpy.env.scratchFolder or arcpy.env.scratchGDB.

1
2
bufferOutput = os.path.join(arcpy.env.scratchGDB, "outBuffers")
arcpy.Buffer_analysis(inPoints, bufferOutput, "100 Miles")

Here are the key points you need to know to when using these:

Next Article

What's new in Web AppBuilder (December 2019)

Read this article