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° latitude, 0° longitude).
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 latitudes and longitudes are stored as vectors in a MAT-file. Load the MAT-file and view the variables in the workspace.
load coastlines whos
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); numel(latcells)
ans = 241
Plot the coastline data on the map axes using the
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.
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
setm functions and others allow you to access and modify these properties.
h = worldmap('Europe');
Determine which map projection
worldmap is using.
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. Note how the
geoshow function can plot data directly from files onto a map axes without first importing it into the workspace. To change the color of the marker, use the
MarkerEdgeColor property and, for some markers, the
geoshow('landareas.shp', 'FaceColor', [0.15 0.5 0.15]) geoshow('worldlakes.shp', 'FaceColor', 'cyan') geoshow('worldrivers.shp', 'Color', 'blue') geoshow('worldcities.shp', 'Marker', '.',... 'MarkerEdgeColor', 'magenta')
Place a label on the map to identify the Mediterranean Sea.
labelLat = 35; labelLon = 14; textm(labelLat, labelLon, 'Mediterranean Sea')