Main Content

Switch Between Projections

Once you create an axesm-based map, whether map data is displayed or not, it is possible to change the current projection as well as many of its parameters. Use setm to reset the projection. The rest of this section describes the considerations and parameters involved in switching projections in an axesm-based map. Additional details are given for doing this with the geoshow function in Change Map Projections When Using geoshow.

When you switch from one projection to another, setm clears out settings that were specific to the earlier projection, updates the map frame and graticule, and generally keeps the map covering the same part of the world—even when switching between azimuthal and non-azimuthal projections. But in some cases, you might need to further adjust the axesm-based map properties to achieve proper appearance. Settings that are suitable for one projection might not be appropriate for another. Most often, you'll need to update the positioning of your meridian and parallel labels.

Change Projection Updating Meridian and Parallel Labels

This example shows how to change the projection of an axesm-based map and update the meridian and parallel labels.

Create a Mercator projection with meridian and parallel labels.

axesm mercator
framem on; gridm on; mlabel on; plabel on
setm(gca,'LabelFormat','signed')
axis off

Figure contains an axes object. The hidden axes object contains 27 objects of type patch, line, text.

Get the default map and frame latitude limits for the Mercator projection. Note that both the frame and map latitude limits are set to 86 degrees north and south for the Mercator projection to maintain a safe distance from the singularity at the poles.

[getm(gca,'MapLatLimit'); getm(gca,'FLatLimit')]
ans = 2×2

   -86    86
   -86    86

Switch the projection to an orthographic azimuthal.

setm(gca,'MapProjection','ortho')

Figure contains an axes object. The hidden axes object contains 3 objects of type patch, line.

Specify new locations for the meridian and parallel labels.

setm(gca,'MLabelParallel',0,'PLabelMeridian',-90, ...
   'PLabelMeridian',-30)

Figure contains an axes object. The hidden axes object contains 19 objects of type patch, line, text.

Change Projection Resetting Frame Limits

This example shows how to switch from one projection to another in an axesm-based map and reset the origin and frame limits, especially when mapping a small portion of the Earth.

Create an axesm-based map for a region of the United States in the Lambert Conformal Conic projection (the default projection for the usamap function).

latlim = [32 42];
lonlim = [-125 -111];
h = usamap(latlim, lonlim);

Figure contains an axes object. The hidden axes object contains 13 objects of type patch, line, text.

Read the usastatehi shapefile and return a subset of the shapefile contents, as defined by the latitude and longitude limits. The shaperead function returns the data in a structure called states.

states = shaperead('usastatehi.shp', 'UseGeoCoords', true, ...
   'BoundingBox', [lonlim', latlim']);

Save the latitude and longitude data from the structure in the vectors lat and lon.

lat = [states.Lat];
lon = [states.Lon];

Project patch objects on the map.

patchm(lat, lon, [0.5 0.5 1])

Figure contains an axes object. The hidden axes object contains 14 objects of type patch, line, text.

Change the projection to Lambert Equal Area Azimuthal and reset the origin and frame limits.

setm(gca,'MapProjection','eqaazim','Origin',[37 -118], ...
   'FLatLimit',[-Inf 6]) 
setm(gca,'mlinelocation',2,'plinelocation',2)
tightmap

Figure contains an axes object. The hidden axes object contains 29 objects of type patch, line, text.