- globalmapper.CalcWorldRectSize(GM_Rectangle_t aWorldBounds) GM_Error_t32, float, float
-
Calculates the width and height of a rectangle in the current projection. The rectangle can either be specified or the last drawn rectangle can be used.
- Parameters:
-
aWorldBounds (GM_Rectangle_t) – World bounds to calc size of or None for last drawn
- Returns:
-
Error Code
- Return type:
-
GM_Error_t32
- Returns:
-
Width of rectangle in meters
- Return type:
-
float
- Returns:
-
Height of rectangle in meters
- Return type:
-
float
Example
The following is an example of CalcWorldRectSize.
import os
import globalmapper as gm
import_dir = "Z:/GM-20069/single_function_sample_data/"
# 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,
)
# 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)
### START SAMPLE
err_CalcWorldRectSize, width, height = gm.CalcWorldRectSize(
gm.GetLayerInfo(layers_list[0]).mGlobalRect
)
### 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_CalcWorldRectSize
), f"CalcWorldRectSize1: Expected {gm.GM_Error_None}, got {err_CalcWorldRectSize}"
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")
), "Sample data doesn't exist"