Create Your First World Map

This example shows how to use the Mapping Toolbox to create a world map. 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. Geospatial data can be voluminous, complex, and difficult to process.

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 coast

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

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

   241

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 specifies the projection.

plotm(lat, long)

Create a new map axes for plotting data over Europe, specifying a return argument.

h = worldmap('Europe');

Determine which map projection worldmap is using.

getm(h,'MapProjection')
ans =

eqdconic

Add data to the map of Europe by using the geoshow function to import and display several shapefiles in the toolbox/map/mapdata folder. 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?