Entering such a long dataset name is tedious, frustrating, and error-prone. That's why geoprocessing allows you to drag and drop datasets or layers onto a tool parameter, use the Browse button () to navigate to a dataset, or select a layer from a drop-down list.Additionally, there are two features designed to make specifying input and outputs datasets much easier; the current and scratch workspace environment settings.
Current workspaceThe key idea behind the current workspace is that you set a workspace once and then use only the base name when entering input and output pathnames. Borrowing from the example above, you would set your current workspace to:
Once set, you can enter the base name of the dataset in the parameter. For example, you could enter
for an input (or output) parameter, and it will be expanded to
Scratch workspaceThe scratch workspace is meant to contain temporary data. Scratch workspace is used by model tools to write intermediate data. You need to set the scratch workspace environment only when using ModelBuilder.
- Start ArcCatalog or ArcMap and expose the ArcToolbox window by clicking Show/Hide ArcToolbox ().
- In the ArcToolbox window, right-click on the ArcToolbox entry and click Environments, as shown below. There are several other methods to set environments, and you can set environments so that they apply for all tools, for the execution of one tool, for a model, a model process, or a script.Learn more about environment settings
- Expand the General Settings category, as shown below.
- In the Current Workspace parameter, enter the path to the workspace. As shown below, the workspace is D:\ArcTutor\BuildingaGeodatabase\Montgomery.gdb\Landbase, a feature dataset within the geodatabase. You can specify any valid workspace, such as a system folder containing shapefiles, a file geodatabase, a coverage workspace, or a connection to an ArcSDE workspace. As shown above, a workspace can be a feature dataset within a geodatabase.
- Click OK.
- Open the Clip tool. Clip is found in the Analysis Tools toolbox under the Extract toolset. Alternatively, you can open any tool with a feature class as input.
- In the Input Features parameter, enter "Blocks", the base name of a feature class in the current workspace. After entering the base name, click the mouse anywhere else in the dialog box. This causes the dialog to refresh. Two things happen on refresh, as shown in the illustration below:
- The base name (Blocks) is joined with the current workspace to form the dataset name (D:\ArcTutor\BuildingaGeodatabase\Montgomery.gdb\Landbase\Blocks). The Input Features parameter is then replaced with this dataset name.
- A unique output dataset name is auto-generated. The base name is the same as the input base name (Blocks) appended with an underscore and the name of the tool (Clip), and, if necessary to ensure a unique name, a number.
# Purpose: Determine the type of vegetation within 100 meters of all stream crossings # Create the Geoprocessor object import arcgisscripting gp = arcgisscripting.create() try: # Set the workspace (to avoid having to type in the full path to the data every time) gp.Workspace = "c:/projects/RedRiverBasin/data.mdb" # Process: Find all stream crossings (points) gp.Intersect("roads ; streams ", "stream_crossings", "#", 1.5, "point") # Process: Buffer all stream crossings by 100 meters gp.Buffer("stream_crossings","stream_crossings_100m", "100 meters") # Process: Clip the vegetation feature class to stream_crossing_100m gp.Clip_analysis("vegetation", "stream_crossings_100m", "veg_within_100m_of_crossings") # Process: Summarize how much (area) of each type of vegetation is found within 100 meters of the stream crossings gp.Statistics("veg_within_100m_of_crossings", "veg_within_100m_of_crossings_stats","shape_area sum","veg_type") except: # If an error occurred while running a tool print the messages print gp.GetMessages()
NOTE: Because the scratch workspace is meant for temporary data, do not set it to an ArcSDE geodatabase. This could cause performance problems—you'll be writing temporary scratch data to an enterprise database. It's suggested that you always use a file geodatabase (rather than a personal geodatabase or a shapefile workspace) for the scratch workspace.If you set the scratch workspace environment, tools will use it to auto-generate output dataset names, as shown below.
NOTE: If you enter a base name for an output, the current workspace is used to construct the dataset name, not the scratch workspace, as shown below.The rule is that anytime a base name is used, it is joined with the current workspace. Be aware of this when writing scripts. In the code snippet below, the output dataset, "stream_crossings", will be written to the current workspace, not the scratch workspace.
gp.Workspace = "c:/projects/RedRiverBasin/data.mdb" gp.scratchWorkspace = "c:/projects/Scratch/scratch.gdb" gp.Intersect("roads ; streams ", "stream_crossings", "#", 1.5, "point")
Although you are allowed to set the scratch workspace within a script, there is no reason to do so. In the Command Line window, you can set the scratch workspace using the scratchWorkspace command.
- If the scratch workspace environment is set, output will be written to the scratch workspace.
- If the scratch workspace environment is not set, the current workspace environment is checked. If current workspace is set, output will be written to the current workspace.
- If neither the scratch or current workspace is set, output will be written to the workspace of one of the inputs. In this case, certain restrictions apply. For example, if the workspace is a coverage workspace and the output is a new feature class, the output will be a shapefile to the directory above the coverage workspace. There are other restrictions as well, such as write access. In some cases, the output will be written to the system temp directory.