How to get cursor position in geodetic format on terrain map?

3 Ansichten (letzte 30 Tage)
Said Kemal
Said Kemal am 30 Mär. 2023
Beantwortet: Suraj am 17 Nov. 2023
I have following code to draw terrain map
[A,R] = readgeoraster("n39_w106_3arc_v2.dt1", "OutputType", "double");
latlim = R.LatitudeLimits;
lonlim = R.LongitudeLimits;
usamap(latlim,lonlim)
geoshow(A,R,"DisplayType", "surface", "ButtonDownFcn", @get_cursor_position)
demcmap(A)
where
function get_cursor_position(varargin)
XYZ = get(gca, "CurrentPoint");
pos = [XYZ(1, 1), XYZ(1, 2), XYZ(1, 3)] % cursor position
assignin("base", "CursorPosition", pos); % save variable to workspace
end
I want to get the cursor position position in geodetic format whenever I click on the figure.
2 problems I have:
  1. When I click any point on the map, I get a cursor position value, but not in geodetic format.
  2. I get same height value at different locations where I am sure they have different height. get(gca, "CurrentPoint") does not work well.

Antworten (1)

Suraj
Suraj am 17 Nov. 2023
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;
usamap(latlim,lonlim)
geoshow(A,R,"DisplayType", "surface", "ButtonDownFcn",{@get_cursor_position, A, R})
demcmap(A)
function get_cursor_position(varargin)
pt = gcpmap;
lat = pt(1,1);
lon = pt(1,2);
z_altitude = geointerp(varargin{3}, varargin{4}, lat, lon);
pos = [lat, lon, z_altitude];
assignin("base", "CursorPosition", pos);
end
Please refer to the following documentation for more information –
  1. “gcpmap” - https://www.mathworks.com/help/map/ref/gcpmap.html
  2. “geointerp” - https://www.mathworks.com/help/map/ref/geointerp.html
I hope this helps.
Best regards,
Suraj.

Produkte


Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by