- globalmapper.SaveWorkspace(string aFilename, uint32 aReserved=0) GM_Error_t32
Saves the current list of loaded layers and display options to a workspace (GMW) file. You can load a workspace file using any of the LoadLayer* functions.
- Parameters:
aFilename (str) – Name of workspace file to save.
aReserved (int) – Reserved for future use; defaults to 0
- Returns:
Error Code
- Return type:
GM_Error_t32
Example
The following is an example of SaveWorkspace.
import os
import globalmapper as gm
import_dir = "Z:/GM-20069/single_function_sample_data/"
export_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "../misc/save_workspace_output/")
os.makedirs(export_dir, exist_ok=True)
# Close all layers that may be open
layers_are_open = gm.GetLoadedLayerList()
if layers_are_open:
arr_ptr, arr_size = layers_are_open
initial_layers = gm.GM_LayerHandle_array_frompointer(arr_ptr)
for i in range(arr_size):
gm.CloseLayer(initial_layers[i])
err_LoadLayerList, array_pointer, array_size_param = gm.LoadLayerList(
os.path.join(import_dir, "newShape.shp"),
gm.GM_LoadFlags_HideAllPrompts,
)
### START SAMPLE
err_SaveWorkspace = gm.SaveWorkspace(export_dir + "workspace.gmw", 0)
### END SAMPLE
assert (
gm.GM_Error_None == err_LoadLayerList
), f"LoadLayerList: Expected {gm.GM_Error_None}, got {err_LoadLayerList}"
assert (
gm.GM_Error_None == err_SaveWorkspace
), f"SaveWorkspace: Expected {gm.GM_Error_None}, got {err_SaveWorkspace}"
assert os.path.isdir(export_dir), f"Error creating the export directory: {export_dir}"
assert os.path.isdir(import_dir), f"Import directory doesn't exist: {import_dir}"
assert os.path.exists(
os.path.join(import_dir, "newShape.shp")
), f"Sample data doesn't exist"
# Expected path for file export
exported_filepath = os.path.join(export_dir, "workspace.gmw")
# Assert that the final expected output file exists and is not empty
assert os.path.exists(
exported_filepath
), f"Expected output file does not exist: {exported_filepath}"
assert (
os.path.getsize(exported_filepath) > 0
), f"Exported file is empty: {exported_filepath}"