So far, all I am getting out of it is that it is a place for temporal data and that it garantees that the scratch workspace will exist if the tool is to be ported.
The scratchWorkspace is not guaranteed to exist. The scratchFolder and scratchGDB (which are derived from the scratchWorkspace) are. In ModelBuilder, intermediate datasets can be pathed with paths like %scratchFolder%\xx0.shp - these will be guaranteed to work as if the workspace and scratch are not defined, they will be either determined or created depending on the existence and type of the current workspace.In Python you need to clean up after yourself...from arcpy import env
env.scratchWorkspace = r"C:\GIS\temp_data.gdb"
env.scratchWorkspace = env.scratchFolder
# the call env.scratchFolder will locate (or create) scratchFolder
# - based on the current scratch workspace. guaranteed writable
# Since the workspace is a gdb, it will create a folder parallel to the gdb named "scratch"
tmpFC = arcpy.CreateScratchName("", "", "featureclass", env.scratchFolder)
# Then CreateScratchName creates a unique name for you to use for your temp
# feature class. Since you used a folder, it's a shapefile path (including the .shp)
arcpy.CopyFeatures(inFC, tmpFC)
## at the end of your script, always clean up
arcpy.Delete_management(tmpFC)
Can anyone enlighten me as to why I would use a scratch workplace over this method? Does it speed up performace in some way?
Tools that you call may use the scratch workspace to write (and delete) their own intermediate files.The most effective way to speed up performance with scratch is to use the "in_memory" workspace. This is very very fast, but only recommended if you know the temporary files will not be large. Do not set the scratch workspace to in_memory, just use it explicitly:tmpFC = arcpy.CreateScratchName("xx1", "", "featureclass", "in_memory")
...
arcpy.Delete_management(tmpFC)
If the files are expected to be large, use the OS TEMP folder (this ensures that your temp files are local, so you aren't processing over the network).:import os
TEMP = os.getenv("TEMP") # this is a folder Windows promises will exist
env.scratchWorkspace = TEMP
tmpFC = arcpy.CreateScratchName("x1", "", "featureclass", env.scratchFolder) # %TEMP%\x10.shp
# to use file GDB instead (not a bad plan) do this:
tmpFC = arcpy.CreateScratchName("x1", "", "featureclass", env.scratchGDB) # %TEMP%\scratch.gdb\x10
Hope this helps.