Map Catalog Samples¶
Map catalog functions allow you to manage and organize large collections of map layers efficiently. The created catalog file lets you reference data from external datsets without needing to load all of it. As a result, you can choose to load only the data you need from the catalog based on your current project.
Adding Map Layers¶
Note
Before running this sample, configure these variables:
map_import_dir
: the directory path containing a map catalogdata_import_dir
: the directory path containing the data to add to the catlogsave_dir
: the directory for a map catalog to be saved
Shows how to add a map to a catalog from a loaded layer.
# Loads a pre-existing map catalog as a layer
err_LoadLayerList1, array_pointer, array_size_param = gm.LoadLayerList(
map_import_dir + "Cahokia_Map_Catalog.gmc",
gm.GM_LoadFlags_HideAllPrompts,
)
# Loads the data that you want to add to the map catalog
err_LoadLayerList2, array_pointer, array_size_param = gm.LoadLayerList(
data_import_dir + "map.laz",
gm.GM_LoadFlags_HideAllPrompts,
)
# Get handle for the loaded layers
arr_ptr, arr_size = gm.GetLoadedLayerList()
layers_array = gm.GM_LayerHandle_array_frompointer(arr_ptr)
layers_list = gm.carray_to_list(layers_array, arr_size)
# Add map.laz to the map catalog and then close the layer
err_MapCatalogAddLayer = gm.MapCatalogAddLayer(layers_list[0], layers_list[1])
err_CloseLayer = gm.CloseLayer(layers_list[1])
err_MapCatalogSave = gm.MapCatalogSave(
layers_list[0], save_dir + "MapCatalogAddLayer.gmc"
)
Setup and Management¶
Note
Before running this sample, configure these variables:
resource_dir
: the path to a directory that contains a projection file and map data to add to the catalogsave_dir
: the directory for a map catalog to be saved
This sample details a simple workflow that involves setting up and creating a map catalog. A map catlog is created, assigned a projection, and populated with data files. Then select maps are disbaled and viewing options are updated. Finally, all changes are saved to a specified directory.
# Load the projection data that will be assigned to the maps in the catalog
err_LoadProjectionFile, proj_file = gm.LoadProjectionFile(
resource_dir + "Cahokia_PRJ.prj"
)
catalog_handle = gm.MapCatalogCreate("Cahokia Historical Site Data", proj_file)
# All of the lidar files form one complete lidar view of the Cahokia Mounds State Historic Site
dir_files = os.listdir(resource_dir)
for file in dir_files:
if ".db" not in file:
if ".prj" not in file:
# Add all relevant files to the catalog
err_MapCatalogAddFile = gm.MapCatalogAddFile(
catalog_handle,
resource_dir + file,
gm.GM_LoadFlags_UseDefaultLoadOpts,
)
err_MapCatalogGetInfo, catalog_info = gm.MapCatalogGetInfo(catalog_handle)
num_maps = catalog_info.mNumMaps
# Iterate through each map and grab associated information
for i in range(num_maps):
map_info = gm.MapCatalogGetMapInfo(catalog_handle, i)
# Disable all maps that have max elevations less than 200 meters
if map_info.mMaxElevation < 200:
err_MapCatalogDisableMap = gm.MapCatalogDisableMap(catalog_handle, i, True)
# Now that there are fewer maps displayed
# Adjust display info for increased visibility in Global Mapper
err_MapCatalogSetDisplayInfo = gm.MapCatalogSetDisplayInfo(
catalog_handle, gm.GM_MapCatalog_DisplayTypePercent, 0.05, 0, 0
)
err_MapCatalogSave = gm.MapCatalogSave(
catalog_handle, save_dir + "Cahokia_Map_Catalog.gmc"
)
Removing Maps¶
Note
Before running this sample, configure these variables:
save_dir
: the directory for a map catalog to be saved
Demonstrates how to remove maps from a map catlog based on specified criteria. This sample removes a map by name, but other criteria, such as a maps native projection, layer type, metadata, and more can be used to find and remove maps from a catalog.
err_MapCatalogGetInfo, catalog_info = gm.MapCatalogGetInfo(layers_list[0])
num_maps = catalog_info.mNumMaps
# Iterate through each map to find which one will be removed
for i in range(num_maps):
map_info = gm.MapCatalogGetMapInfo(layers_list[0], i)
map_name = map_info.mDescription
# This removes a map by name, yet there are many criteria that
# can be used to determine map removal by using MapCatalogGetMapInfo()
if map_name == "map.laz":
err_MapCatalogRemoveMap = gm.MapCatalogRemoveMap(layers_list[0], i)
break
err_MapCatalogSave = gm.MapCatalogSave(
layers_list[0], save_dir + "MapCatalogRemoveMap.gmc"
)