| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Mapping Toolbox |
| Contents | Index |
| Learn more about Mapping Toolbox |
| On this page… |
|---|
Adding Graphic Objects to Map Axes |
If you cannot find a Mapping Toolbox display function that makes the kind of display that you need, you might be able to use MATLAB functions. When placing graphic objects on a map axes, you can use the MATLAB function to add the graphic objects to the display, using latitude and longitude as x and y, and then project the data afterwards.
Note Before applying MATLAB functions to geodata, you should take into consideration that performing Cartesian geometric operations on geographic coordinates can yield inaccurate results when the data covers large regions of a planet or lies near one of its poles. |
There is no Mapping Toolbox function that displays a triangulated surface from random data points, a structure generally known as a triangulated irregular network (TIN). However, MATLAB does have a function to create Delaunay triangles, a method that is often used to form TINs from projected point coordinate data. Explore triangulating some point data and bringing the result into a Mapping Toolbox map axes:
Use the seamount data provided as MATLAB demo data:
load seamount
Determine the bounds of the coordinates and add a degree of white space:
latlim = [min(y)-.5 max(y)+.5]; lonlim = [min(x)-.5 max(x)+.5];
Create map axes to contain the seamount region (worldmap selects a projection for you):
worldmap(latlim,lonlim)
Create a Delaunay triangulation of x and y (longitude and latitude):
tri = delaunay(y,x);
Generate a 3-D surface that combines the triangulation and z-values:
h = trisurf(tri,y,x,z);
Map the surface onto the axes by projecting to the x-y plane (project is a Mapping Toolbox function especially for this purpose):
project(h,'yx')
Note that even though the triangulated surface appears on the map, it does not have a geostruct (see Mapping Toolbox Geographic Data Structures).
Add a default graphic scale to the display:
scaleruler on

If, as in this example, the displayed objects are already in the right place and do not need to be projected, you can trim them to the map frame and convert them to mapped objects using trimcart and makemapped. They can then be manipulated as if they had been created with map display functions.
As was briefly described for text objects in Projected and Unprojected Graphic Objects, you can also combine Mapping Toolbox and MATLAB functions to mix spherical and Cartesian coordinates. An example would be a quiver plot (sometimes known as a vector field) in which the locations of the vectors are geographic, but the lengths, being specified by attributes, are not. In that case, you can use Mapping Toolbox map projection calculations and MATLAB graphics functions. Cylindrical projections are the simplest to use because north is up, south is down, and east and west are on an orthogonal axis.
In this example, you will impose a quiver map of the slope of a surface on a world map. The surface is a Gaussian field generated by the MATLAB peaks function.
figure; axesm mercator; framem; gridm load coast plotm(lat,long,'color',[.75 .75 .75]) [u,v] = gradient(peaks(13)/10); [mlat,mlon] = meshgrat(-90:15:90,-180:30:180); [x,y] = mfwdtran(mlat,mlon); h = quiver(x,y,u,v,.2,'r'); trimcart(h) tightmap

An extra step might be required for noncylindrical projections. In these projections, compass directions vary with location. To make the directions agree with the map grid, vectors should be rotated to bring them into alignment. This can be done with the vector transformation function vfwdtran. Consider the same data displayed on a conic projection.
load coast; figure
axesm('lambert','MapLatLimit',[-20 80])
framem; gridm
plotm(lat,long,'color',[.75 .75 .75])
[u,v] = gradient(peaks(13)/10);
[mlat,mlon] = meshgrat(-90:15:90,-180:30:180);
[x,y] = mfwdtran(mlat,mlon);
thproj = degtorad(vfwdtran(mlat,mlon,90*ones(size(mlat))));
[th,r] = cart2pol(u,v);
[uproj,vproj] = pol2cart(th+thproj,r);
h = quiver(x,y,uproj,vproj,0,'r') ;
trimcart(h)
tightmap

Conformal projections, such as this Lambert conformal conic, are often the best choice for quiver displays. They preserve angles, ensuring that the difference between north and east will always be 90 degrees in projected coordinates.
![]() | Thematic Maps | Using Colormaps and Colorbars | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |