Main Content

Reprojection of Graphics Objects

Many Mapping Toolbox™ cartographic functions project features on an axesm-based map based on their designated latitude-longitude positions. The latitudes and longitudes are mathematically transformed to x and y positions using the formulas for the current map projection. If the map projection or its parameters change, objects on an axesm-based map can be automatically reprojected to update the map display accordingly.

The table summarizes the four common use cases for changing a map projection in an axesm-based map with setm or for reprojecting map data plotted on a regular MATLAB® axes.

Mapping Use CaseType of AxesReprojection Behavior
Plot geographic (latitude-longitude) vector coordinate data or data grid using a Mapping Toolbox function from releases prior to Version 2 (e.g., plotm)axesm-based mapAutomatic reprojection
Plot geographic vector data with geoshowaxesm-based mapNo automatic reprojection; delete graphics objects prior to changing the projection and redraw them afterwards.
Plot data grids, images, and contours with geographic coordinates with geoshowaxesm-based mapAutomatic reprojection; this behavior could change in a future release
Plot projected (x-y) vector or raster map data with mapshow or with a MATLAB graphics function (e.g., line, contour, or surf)Regular axesManual reprojection (reproject coordinates with projinv/projfwd); delete graphics objects prior to changing the projection and redraw them afterwards.

You can use handlem to help identify which objects to delete when manual deletion is necessary. See Work with Objects by Name for an example of its use.

Auto-Reprojection of Mapped Objects and Its Limitations

Using the setm function, you can change the current map projection on the fly if the map display was created in a way that permits reprojection. Note that map displays can contain objects that cannot be reprojected, and may need to be explicitly deleted and redrawn. Automatic reprojection will take place when you use setm to modify the MapProjection property, or any other axesm-based map property from the following list:

  • AngleUnits

  • Aspect

  • FalseEasting

  • FalseNorthing

  • FLatLimit

  • FLonLimit

  • Geoid

  • MapLatLimit

  • MapLonLimit

  • MapParallels

  • Origin

  • ScaleFactor

  • TrimLat

  • TrimLon

  • Zone

Auto-reprojection takes place for objects created with any of the following Mapping Toolbox functions:

The above Mapping Toolbox functions are analogous to standard MATLAB graphics functions having the same name, less the trailing m. You can use both types of functions to plot data on an axesm-based map, as long as you are aware that the standard MATLAB graphics functions do not apply map projection transformations, and therefore require you to specify positions in map x-y space.

In general, objects created with geoshow or with a combination of calls to projfwd followed by ordinary MATLAB graphics functions, such as line, patch, or surface, are not automatically reprojected. You should delete such objects whenever you change one or more of the axesm-based map properties listed above, and then redisplay them.

If you have preprojected vector or raster map data or read such data from files, you can display it with mapshow or standard MATLAB graphics functions, such as plot or mesh. If its projection is known and is included in the Mapping Toolbox projection libraries, you can use its parameters to project geodata in geographic coordinates to display it in the same axes.

Reprojectability of Maps Generated Using geoshow

If you want to be able to change the projection of a map on the fly, you should not use geoshow. Some display functions, such as patchm , fillm, displaym, and linem, enable you to reproject vector map data, but geoshow does not. That is, when you change an axesm-based map projection, with setm for example, vector map symbology that was created with geoshow will not be transformed. Gridded data rendered with geoshow (when DisplayType is surface, texturemap, or contour), however, can be reprojected.

For examples of reprojection behavior with vector data and raster data, see Change Map Projections When Using geoshow.