I'm having an issue with modelbuilder workspaces. I have created a simple model to clip a raster, run focal statistics on it, and create contours. I have a workspace variable as an input. If I run the tool with a folder as a workspace, it works just fine. (Overall model is attached as "Overview")
However, If I run it with a geodatabase workspace, I get an error (see "Error" attachment)
I know what is causing the error. Within the Contour tool in modelbuilder, the output is set to add the ".shp" suffix (see "Contour Tool" attachment below). When I try to delete the ".shp", it automatically populates it in the output once I click apply or ok. I assume modelbuilder defaults a workspace to be a folder.
So I have two workarounds-
I suppose I'm wondering if it's possible to leave the workspace area blank, and use a geodatabase as a workspace.
There is a built-in model builder variable: %scratchFolder% and %scratchGDB%. These are set up to allow you to force the use of a folder or geodatabase for intermediate datasets, whether the current workspace is a folder or GDB.
I don't think it is that obvious that file GDBs being the best place to store rasters. I think it really varies a lot depending on the tool being used and how big the dataset is. Temporary rasters created using arcpy map algebra are always stored as grids (in the scratchFolder!). Personally I usually set the scratch and current workspace to a folder, but of course do whatever works with your processing flow. This way when I do an arcpy <raster>.save() all it has to do is rename the raster, not copying it (important if it's a big raster!).
After playing around with it, it doesn't seem like I can override the location of the scratch geodatabase in my user folder. Even if I specify it in the tool dialog box, or alter the tool environment properties.
It's a good point about rasters in the scratch folder. However, saving storage space is a big deal for me. GDBs are just so much better when working with rasters that are multiple GBs large (as much as 70% smaller for me). It's also nice to not have a restriction on name length, which is useful when running an iterator that takes the name of the input and adds to it.
I wasn't suggesting using the environment, I was suggesting setting the name of the intermediate raster in your model to:
%scratchGDB%\tempRaster
If the current scratch workspace is a folder, a file gdb names "scratch.gdb" will be created in that folder. Otherwise it will just use the current workspace.