Documentation Center

  • Trial Software
  • Product Updates

Create a World Map

Spatial data refers to data describing location, shape, and spatial relationships. Geospatial data is spatial data that is in some way georeferenced, or tied to specific locations on, under, or above the surface of a planet.

Geospatial data can be voluminous, complex, and difficult to process. Mapping Toolbox™ functions handle many of the details of loading and displaying data, and built-in data structures facilitate data storage. Nevertheless, the more you understand about your data and the capabilities of the toolbox, the more interesting applications you can pursue, and the more useful your results will be to you and others.

Follow this example to create your first world map.

  1. In the MATLAB® Command Window, type

    worldmap world

    This creates an empty map axes, ready to hold the data of your choice.

    Function worldmap automatically selects a reasonable choice for your map projection and coordinate limits. In this case, it chose a Robinson projection centered on the prime meridian and the equator (0º latitude, 0º longitude).

    If you type worldmap without an argument, a list box appears from which you can select a country, continent, or region. The worldmap function then generates a map axes with appropriate projection and map limits.

  2. Import low-resolution world coastlines—a set of discrete vertices that, when connected in the order given, approximate the coastlines of continents, major islands, and inland seas. The vertex latitudes and longitudes are stored as MATLAB vectors in a MAT-file. First, list the variables in the file:

    whos -file coast.mat

    The output is shown below:

    Name         Size            Bytes  Class     Attributes
      lat       9865x1             78920  double              
      long      9865x1             78920  double              
  3. Load and plot the coastlines on the world map:

    load coast
    plotm(lat, long)

    The plotm function is a geographic equivalent to the MATLAB plot function. It accepts coordinates in latitude and longitude, transforms them to x and y via a specified map projection, and displays them in a figure axes. In this example, worldmap specifies the projection.

      Note:   Certain Mapping Toolbox functions that end with m, such as plotm and textm, are modeled after familiar MATLAB functions that handle non-geographic coordinate data.

  4. Notice how the world coastlines form distinct polygons, even though only a single vector of latitudes and a corresponding vector of longitudes are provided. The display breaks into separate parts like this because in the vectors lat and long the vertices of various coastlines are concatenated together but separated by isolated NaN-valued elements. In other words, "NaN separators" implicitly divide each vector into multiple parts. lat and long include "NaN terminators" as well as separators, showing that the coast data set is organized into precisely 241 polygons.

    Enter the following code to break out your data into its NaN-separated parts:

    [latcells, loncells] = polysplit(lat, long);

    latcells and loncells are cell vectors, with each cell containing the vertices of just one polygon part. The number of parts appears:

    ans =
  5. Now create a new map axes for plotting data over Europe, and this time specify a return argument:

    h = worldmap('Europe');

    For the map of the world, worldmap chose a pseudocylindrical Robinson projection. For Europe, it chose an Equidistant Conic projection. How can you tell which projection worldmap is using?

    When you specify a return argument for worldmap and certain other mapping functions, a handle (e.g., h) to the figure's axes is returned. The axes object on which map data is displayed is called a map axes. In addition to the graphics properties common to any MATLAB axes object, a map axes object contains additional properties covering map projection type, projection parameters, map limits, etc. The getm and setm functions and others allow you to access and modify these properties.

  6. To inspect the MapProjection property for the map of Europe, type:

    getm(h, 'MapProjection')

    The type of projection appears:

    ans =

    If you're not familiar with the abbreviation "eqdconic," type:

    help eqdconic

    To see all the map-specific properties for this map axes, type:

  7. Add data to the map of Europe by using the geoshow function to import and display several shapefiles in the toolbox/map/mapdata folder:

    geoshow('landareas.shp', 'FaceColor', [0.15 0.5 0.15])
    geoshow('worldlakes.shp', 'FaceColor', 'cyan')
    geoshow('worldrivers.shp', 'Color', 'blue')
    geoshow('worldcities.shp', 'Marker', '.',...
                               'Color', 'red')

    Note how geoshow can plot data directly from files onto a map axes without first importing it into the MATLAB workspace.

  8. Finally, place a label on the map to identify the Mediterranean Sea.

    labelLat = 35;
    labelLon = 14;
    textm(labelLat, labelLon, 'Mediterranean Sea')

To learn more about display properties for map axes and how to control them, see Accessing and Manipulating Map Axes Properties.

Was this topic helpful?