Hello Said
I understand that you are using Mapping Toolbox to read and display elevation data. You are trying to create a callback function that saves the latitude, longitude, and elevation from the last clicked point on the map to a variable in the base workspace.
Let me address the issues you have pointed out -
1. “When I click any point on the map, I get a cursor position value, but not in geodetic format.”
- The “CurrentPoint” property of “Axes” object returned by “gca” function contains X-Y-Z values relative to the axes of the plot.
- You can use the “gcpmap” function to retrieve the current point (the location of last button click) of the current “axesm”-based map in the form “[latitude longitude z-altitude]”.
2. “I get same height value at different locations where I am sure they have different height. get(gca, "CurrentPoint") does not work well.”
- The example you have attached plots the data as a surface map (2 dimensional) with the elevation data represented by a colormap, applied using the “demcmap” function.
- This means that “geoshow” is essentially rendering a 2-dimensional representation of the 3-dimensional data from the “.dt1” file.
- This is why “gcpmap” and “gca” functions return the same height value at all the points on the map.
- I would recommend you query the DEM data directly using “geointerp” function with the latitude and longitude points obtained from “gcpmap”.
Here is a code snippet that accomplishes the task using the above workarounds –
[A,R] = readgeoraster("n39_w106_3arc_v2.dt1", "OutputType", "double");
latlim = R.LatitudeLimits;
lonlim = R.LongitudeLimits;
geoshow(A,R,"DisplayType", "surface", "ButtonDownFcn",{@get_cursor_position, A, R})
function get_cursor_position(varargin)
z_altitude = geointerp(varargin{3}, varargin{4}, lat, lon);
pos = [lat, lon, z_altitude];
assignin("base", "CursorPosition", pos);
Please refer to the following documentation for more information –
- “gcpmap” - https://www.mathworks.com/help/map/ref/gcpmap.html
- “geointerp” - https://www.mathworks.com/help/map/ref/geointerp.html
I hope this helps.
Best regards,
Suraj.