Main Content

Pick Locations Interactively

You can use Mapping Toolbox™ functions to interact with axesm-based maps. This section describes two useful graphic input functions, inputm and gcpmap. The inputm function (analogous to the MATLAB® ginput function) allows you to get the latitude-longitude position of a mouse click. The gcpmap function (analogous to the MATLAB function get(gca,'CurrentPoint')) returns the current mouse position, also in latitude and longitude.

Explore inputm with the following commands, which display an axesm-based map with its grid and then request three mouse clicks, the locations of which are stored as geographic coordinates in the variable points. Then the plotm function plots the points you clicked as red markers. The display you see depends on the points you select:

axesm sinusoid
framem on; gridm on
points =
  -41.7177 -145.0293
    7.9211   -0.5332
   38.5492  149.2237

Two star markers plotted using a sinusoidal projection


If you click outside the map frame, inputm returns a valid but incorrect latitude and longitude, even though the point you indicated is off the map.

One reason you might want to manually identify points on a map is to interactively explore how much distortion a map projection has at given locations. For example, you can feed the data acquired with inputm to the distortcalc function, which computes area and angular distortions at any location on a displayed axesm-based map. If you do so using the points variable, the results of the previous three mouse clicks are as follows:

[areascale,angledef] = distortcalc(points(1,1),points(1,2))
areascale =
angledef =
[areascale,angledef] = distortcalc(points(2,1),points(2,2))
areascale =
angledef =
[areascale,angledef] = distortcalc(points(3,1),points(3,2))
areascale =
angledef =

This indicates that the current projection (sinusoidal) has the equal-area property, but exhibits variable angular distortion across the map, less near the equator and more near the poles.

See Also


Related Topics