Documentation Center

  • Trial Software
  • Product Updates

Displaying Data Grids

Types of Data Grids and Raster Display Functions

Mapping Toolbox™ functions and GUIs display both regular and geolocated data grids originating in a variety of formats. Recall that regular data grids require a referencing vector or matrix that describes the sampling and location of the data points, while geolocated data grids require matrices of latitude and longitude coordinates.

The data grid display functions are geographic analogies to the MATLAB® surface drawing functions, but operate specifically on map axes objects. Like the line-plotting functions discussed in the previous chapter, some Mapping Toolbox grid function names correspond to their MATLAB counterparts with an m appended.

    Note   Mapping Toolbox functions beginning with mesh are used for regular data grids, while those beginning with surf are reserved for geolocated data grids. This usage differs from the MATLAB definition; mesh plots are used for colored wire-frame views of the surface, while surf displays colored faceted surfaces.

Surface map objects can be displayed in a variety of different ways. You can assign colors from the figure colormap to surfaces according to the values of their data. You can also display images where the matrix data consists of indices into a colormap or display the matrix as a three-dimensional surface, with the z-coordinates given by the map matrix. You can use monochrome surfaces that reflect a pseudo-light source, thereby producing a three-dimensional, shaded relief model of the surface. Finally, you can use a combination of color and light shading to create a lighted shaded relief map.

The following table lists the available Mapping Toolbox surface map display functions.


Used For


Display map data gridded in latitude and longitude in 2-D


Display gridded map data without projection in 2-D


Regular data grid warped to projected graticule mesh


Geolocated data grid projected on map axes


Projected data grid in z = 0 plane


Data grid warped to projected graticule mesh


3-D shaded surface with lighting projected on map axes


3-D lighted shaded relief of regular data grid


3-D lighted shaded relief of geolocated data grid

Fitting Gridded Data to the Graticule

The toolbox projects surface objects in a manner similar to the traditional methods of mapmaking. A cartographer first lays out a grid of meridians and parallels called the graticule. Each graticule cell is a geographic quadrangle. The cartographer calculates or interpolates the appropriate x-y locations for every vertex in the graticule grid and draws the projected graticule by connecting the dots. Finally, the cartographer draws the map data freehand, attempting to account for the shape of the graticule cells, which usually change shape across the map. Similarly, the toolbox calculates the x-y locations of the four vertices of each graticule cell and warps or samples the matrix data to fit the resulting quadrilateral.

In mapping data grids using the toolbox, as in traditional cartography, the finer the mesh (analogous to using a graticule with more meridians and parallels), the greater precision the projected map display will have, at the cost of greater effort and time. The graticule in a printed map is analogous to the spacing of grid elements in a regular data grid, the Mapping Toolbox representation of which is two-element vectors of the form [number-of-parallels, number-of-meridians]. The graticule for geolocated data grids is similar; it is the size of the latitude and longitude coordinate matrices: number-of-parallels = mrows-1 and number-of-meridians = ncols-1. However, because geolocated data grids have arbitrary cell corner locations, spacing can vary and thus their graticule is not a regular mesh.

The topo regular data grid can be displayed quickly using a coarse graticule, at a cost of precision in terms of positioning the grid on the map. Observe the map that results from the following commands:

% Get data grid
load topo

% Create referencing matrix
topoR = makerefmat('RasterSize', size(topo), ...
   'Latlim', [-90 90], 'Lonlim', [0 360]);

% Set up Robinson proj
figure; axesm robinson

% Specify a 10x20 cell graticule
spacing = [10 20];

% Display data mapped to the graticule
h = meshm(topo,topoR,spacing);

% Set DEM colormap

Notice that for this coarse graticule, the edges of the map do not appear as smooth curves. Previous displays used the default [50 100] graticule, for which this effect is negligible.

Regardless of the graticule resolution, the grid data is unchanged. In this case, the data grid is the 180-by-360 topo matrix, and regardless of where it is positioned, the data values are unchanged.

Map objects displayed as surfaces have all the properties of any MATLAB surface, which can be set at object creation or by using the MATLAB set function. The toolbox setm function allows the MeshGrat graticule property to be changed after a regular data grid has been displayed. Since you saved the handle of the last displayed map, reset its graticule to a very fine grid. Because making the mesh more precise is a trade-off of resolution versus time and memory, doing this takes longer, and requires more memory, to display the map:

setm(h,'MeshGrat',[200 400])

Another way you can reset a graticule is with the meshgrat function:

[latgrat,longrat] = meshgrat(topo,topoR,[200 400]);

The vectors latgrat and longrat produced by meshgrat are vectors containing parallel and meridian values in each mesh direction.

Notice that the result does not appear to be any better than the original display with the default [50 100] graticule, but it took much longer to produce. There is no point to specifying a mesh finer than the data resolution (in this case, 180-by-360 grid cells). In practice, it makes sense to use coarse graticules for development tasks and fine graticules for final graphics production.

Using Raster Data to Create 3-D Displays

The simplest way to display raster data is to assign colors to matrix elements according to their data values and view them in two dimensions. Raster data maps also can be displayed as 3-D surfaces using the matrix values as the z data. Here you explore some basic concepts and operations for setting up surface views, which requires explicit horizontal coordinates.

    Note   The difference between regular raster data and a geolocated data grid is that each grid intersection for a geolocated grid is explicitly defined with (x,y) or (latitude, longitude) matrices or is interpolated from a graticule, while a regular matrix only implies these locations (which is why it needs a georeferencing vector or matrix).

You will use the raster elevation data in the korea MAT-file, which also includes bathymetry data for the region around the Korean peninsula, along with a referencing vector variable, which indicates that the data set is a regular data grid and locates it on the Earth.

  1. Load the MAT-file and transform this representation to a fully geolocated data grid by calculating a mesh via the meshgrat function:

    load korea
    [lat,lon] = meshgrat(map,refvec);
  2. Next use the km2deg function to convert the units of elevation from meters to degrees, so they are commensurate with the latitude and longitude coordinate matrices:

    map = km2deg(map/1000);
  3. Observe the results by typing the whos command:

      Name               Size              Bytes  Class     Attributes
      description        2x64                256  char                
      lat              180x240            345600  double              
      lon              180x240            345600  double              
      map              180x240            345600  double              
      maplegend          1x3                  24  double              
      refvec             1x3                  24  double              
      source             2x76                304  char                

    The lat and lon coordinate matrices form a mesh the same size as the map matrix. This is a requirement for constructing 3-D surfaces, unlike the example given above using the topo raster data set, which was displayed in 2-D using the meshm function. If you inspect lat and lon in the MATLAB Variables editor, you find that in lon, all columns contain the same number for a given row, and in lat, all rows contain the same number for a given column. This is because the mesh produced by meshgrat in this case is regular, but such data grids need not have equal spacing.

  4. Now set up a map axes object with the equal area conic projection:

         'MapLatLimit',[30 45],'MapLonLimit',[115 135])
  5. Instead of using the meshm function to make this map, display the korea geolocated data grid using the surfm function, and set an appropriate colormap:

    surfm(lat,lon,map,map); demcmap(map)

    Here is the result, which is the same as what meshm would produce.

    Be aware, however, that this map is really a 3-D view seen from directly overhead (the default perspective). To appreciate that, all you need to do is to change your viewpoint.

  6. Use the view function to specify a viewing azimuth of 60 degrees (from the east southeast) and a viewing elevation of 30 degrees above the horizon:


    The figure immediately rotates to the specified perspective:

For information on Mapping Toolbox controls over perspective map representations or for additional help on constructing 3-D map displays, see under Concepts section Gridded Terrain and Bathymetry Products and 3-D Map Display .

Was this topic helpful?