arcsmith.ws
arcsmith.ws
Workspace
Helpers for setting up geodatabase workspaces inside 'Tool.execute'.
- Create a file geodatabase with automatic parent folder creation
- Get a workspace path for intermediate outputs, switching between memory and scratch GDB
Functions of the ws module
init_gdb
Creates a file geodatabase at the specified location, creating the parent folder if it does not already exist.
| Parameter | Type | Default | Description |
|---|---|---|---|
folder |
str or Path |
required | Folder in which to create the geodatabase. |
gdb_name |
str |
required | Name of the geodatabase, without the .gdb extension. |
Returns
str: absolute path to the created .gdb.
Examples
# Create a geodatabase
gdb = arcsmith.ws.init_gdb(r"C:/Projects/Output", "results")
# C:/Projects/Output/results.gdb
# Create and set as the arcpy workspace in one line
arcpy.env.workspace = arcsmith.ws.init_gdb(folder, gdb_name)
temp_space
Returns a workspace path for intermediate outputs, either the in-memory workspace or the session scratch geodatabase.
| Parameter | Type | Default | Description |
|---|---|---|---|
use_memory |
bool |
True |
If True, returns 'memory'. If False, returns arcpy.env.scratchGDB for on-disk inspection. |
Returns
str: 'memory' or the absolute path to the scratch geodatabase.
Development workflow
Set use_memory=False while building a tool to inspect intermediate outputs in ArcGIS Pro. Switch back to True (the default) for production runs; no other code changes needed.
Examples
# Production: intermediates go to memory (default)
ws = arcsmith.ws.temp_space()
tmp = f"{ws}/my_intermediate"
# tmp = "memory/my_intermediate"
# Development: intermediates written to scratch GDB for inspection
ws = arcsmith.ws.temp_space(use_memory=False)
tmp = f"{ws}/my_intermediate"
# tmp = "C:/Users/.../scratch.gdb/my_intermediate"