This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

Create Your First World Map

This example shows how to use the Mapping Toolbox to create a world map. Geospatial data can be voluminous, complex, and difficult to process. Mapping Toolbox functions handle many of the details of loading and displaying geospatial data, and use built-in data structures that facilitate data storage. 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.

Create an empty map axes, ready to hold the data of your choice. The function worldmap automatically selects a reasonable choice for your map projection and coordinate limits. To display a world map, the function chose a Robinson projection centered on the prime meridian and the equator (0 degrees latitude, 0 degrees longitude).

worldmap world

Import low-resolution world coastline data. The coastline data is a set of discrete vertices that, when connected in the order given, approximate the coastlines of continents, major islands, and inland seas. The vertex latitues and longitudes are stored as vectors in a MAT-file. Load the MAT-file and view the variables in the workspace.

load coastlines
  Name             Size            Bytes  Class     Attributes

  coastlat      9865x1             78920  double              
  coastlon      9865x1             78920  double              

Determine how many separate elements are in the coastline data vectors. Even though there is only one vector of latitudes, coastlat, and one vector of longitudes, coastlon, each of these vectors contain many distinct polygons, forming the worlds coastlines. These vectors use NaN separators and NaN terminators to divide each vector into multiple parts.

[latcells, loncells] = polysplit(coastlat, coastlon);
ans =


Plot the coastline data on the map axes using the plotm function. plotm is the geographic equivalent of 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 uses the Robinson projection.

plotm(coastlat, coastlon)

Create a new map axes for plotting data over Europe. This time, specify a return argument for the worldmap function to get a handle to the figure's axes. 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.

h = worldmap('Europe');

Determine which map projection worldmap is using.

ans =


Add data to the map of Europe by using the geoshow function to import and display several shapefiles in the toolbox/map/mapdata folder. Note how the geoshow function can plot data directly from files onto a map axes without first importing it into the workspace.

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')

Place a label on the map to identify the Mediterranean Sea.

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

Was this topic helpful?