Pick Locations Interactively
You can use Mapping Toolbox™ functions to interact with maps in figures created with
axesm
. 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 a map
axes 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=inputm(3)
points = -41.7177 -145.0293 7.9211 -0.5332 38.5492 149.2237
plotm(points,'r*')
Note
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 map axes. 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 = 1.0000 angledef = 85.9284
[areascale,angledef] = distortcalc(points(2,1),points(2,2))
areascale = 1.0000 angledef = 3.1143
[areascale,angledef] = distortcalc(points(3,1),points(3,2))
areascale = 1.0000 angledef = 76.0623
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.