- globalmapper.GetPixelElevation(GM_LayerHandle_t32 aLayer, sint32 aRow, sint32 aCol) GM_Error_t32, float
-
Retrieves the elevation at a given pixel location from a provided elevation layer. If the layer does not contain a valid elevation sample at the provided pixel location (i.e. it is a “no data” value), GM_Error_NoDataAtLocation will be returned.
- Parameters:
-
aLayer (GM_LayerHandle_t32) – Layer to get elevation from
aRow (sint32) – Y coord of pixel (0 is topmost)
aCol (sint32) – X coord of pixel (0 is leftmost)
- Returns:
-
Error Code
- Return type:
-
GM_Error_t32
- Returns:
-
Elevation at location in meters
- Return type:
-
float
Note: To get pixel row/col data, you can select a point feature in Global Mapper:
Right-click -> Attribute/Style Functions -> Add Pixel Coordinates to Selected Point(s)
Example
The following is an example of GetPixelElevation.
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, "Depth_to_Water.tif"),
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_GetPixelElevation, elevation = gm.GetPixelElevation(
layers_list[0], 5858, 4596
)
### 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_GetPixelElevation
), f"GetPixelElevation: Expected {gm.GM_Error_None}, got {err_GetPixelElevation}"
For more context refer to the raster/elevation layer query sample scripts.