The Map Viewer app is an interactive tool for browsing map data. With it you can:
Assemble layers of vector and raster geodata and render them in 2-D
Import, reorder, symbolize, hide, and delete data layers
Identify coordinate locations
List data attributes
Display selected data attributes as data tips (signposts that identify attribute values, such as place names or route numbers)
The following example illustrates these capabilities.
Open the Map Viewer app. On the Apps
tab, in the Image Processing and Computer Vision
section, click Map Viewer
. You can also start the Map Viewer using
the mapview command. The Map Viewer opens with a blank
canvas. (No data is present.)
Note that The Map Viewer is designed primarily for working with data sets that refer to a projected map coordinate system (as opposed to a geographic, latitude-longitude system), so the coordinate axes are named X and Y.
Import map data. In the Map Viewer, select the
File menu and then choose Import
From File. Navigate to the
folder, where matlabroot/examples/map/datamatlabroot represents your
MATLAB® installation folder, and open the GeoTIFF file
boston.tif.
The file opens in the Map Viewer. The image is a visible red, green, and
blue composite from a georeferenced IKONOS-2 panchromatic/multispectral
product created by GeoEye™. Copyright © GeoEye,
all rights reserved. For further information about the image, refer to the
text files boston.txt and
boston_metadata.txt. To open
boston.txt, type the following at the command
line:
open 'boston.txt'
Set the map scale in the Map Viewer. To do this, you must
first set the map distance units. Click the Map
units menu at the bottom center and select US
Survey Feet.

Set the map scale. Type 1:25000 in the
Scale box, which is above the Map units menu, and press Enter. The Map Viewer
now looks like this.

Get the map coordinates for a location on the map, interactively. Place
the cursor over a location on the map. The example puts the cursor over the
bridge that goes over the pond in Boston Garden. The map coordinates for
this location are shown at the lower left as 772,423.18
feet easting (X), 2,954,372.40 feet
northing (Y), in Massachusetts State Plane
coordinates.
Import a vector data layer. For this example, import a line shapefile that contains data about the streets and highways in the central Boston area.
boston_roads = shaperead('boston_roads.shp');
The shaperead function returns the data as a geographic
data structure.
Convert the X and Y coordinate
fields of boston_roads.shp from meters to U.S. survey
feet. As is frequently the case when overlaying geodata, the coordinate
system used by boston_roads.shp (in units of meters) does
not completely agree with the one for the satellite image,
boston.tif (in units of feet). If you were to ignore
this, the two data sets would be out of registration by a large
distance.
surveyFeetPerMeter = unitsratio('survey feet','meter');
for k = 1:numel(boston_roads)
boston_roads(k).X = surveyFeetPerMeter * boston_roads(k).X;
boston_roads(k).Y = surveyFeetPerMeter * boston_roads(k).Y;
end
unitsratio function computes conversion factors
between a variety of units of length.In the Map Viewer File menu, select Import From Workspace > Vector Data > Geographic Data Structure.

In the Import Vector Data dialog box, select the variable
boston_roads as the data to import from the
workspace, and click OK.

You could clear the workspace now if you wanted, because all the data that the Map Viewer needs is now loaded into it.
After the Map Viewer finishes importing the roads layer, it selects a random color and renders all the shapes with that color as solid lines. The view looks like this.

Being random, the color you see for the road layer may differ.
Explore the attributes of the vector layer. First, make
the vector layer the active layer using the Active layer menu at the bottom right. Select
boston_roads. You can designate any layer to be the
active layer; it does not need to be the topmost
layer. By default, the first layer imported is active. Changing the active
layer has no visual effect on the map. Doing so allows you to query
attributes of the layer you select. For example, once you make the vector
layer the active layer, the Info tool
button near the right end of the toolbar becomes enabled. Select the
Info tool, the cursor changes to a
cross-hairs shape. Click any location on the map to view attributes of the
selected object.

The selected road is Massachusetts Avenue (Route 2A). As the above figure
shows, the boston_roads vectors have six attributes,
including an implicit INDEX attribute added by the Map
Viewer. Use this tool to explore other roads. Dismiss open Info windows by
clicking their close boxes.
Use a data tip to annotate the map with other attribute values. From the Layers menu, select boston_roads > Set Label Attribute.

From the list in the Attribute Names dialog, select
CLASS and click OK.

From the Tools menu, select the Datatip tool. A dialog box appears to remind you how to change attributes. Click OK to dismiss the box.

The cursor assumes a cross-hairs (+) shape. Click on a
road segment in the map and the data tip tool puts a small marker on the
road that contains a numeric identifier that indicates the administrative
class. The class of the road crossing the Charles river we explored earlier
is of class 3.

You can change how the roads are rendered by identifying
an attribute to which to key line symbology. Color roads according to their
CLASS attribute, which takes on the values 1:6. Do
this by creating a symbolspec in the workspace. A
symbolspec is a cell array that associates attribute names and values to
graphic properties for a specified geometric class
('Point', 'MultiPoint',
'Line', 'Polygon', or
'Patch'). To create a symbolspec for line objects (in
this case roads) that have a CLASS attribute,
type:
roadcolors = makesymbolspec('Line', ...
{'CLASS',1,'Color',[1 1 1]}, {'CLASS',2,'Color',[1 1 0]}, ...
{'CLASS',3,'Color',[0 1 0]}, {'CLASS',4,'Color',[0 1 1]}, ...
{'CLASS',5,'Color',[1 0 1]}, {'CLASS',6,'Color',[0 0 1]})
The following output appears:
roadcolors =
ShapeType: 'Line'
Color: {6x3 cell}The Map Viewer recognizes and imports symbolspecs from
the workspace. To apply the one you just created, from the Layers menu, select boston_roads > Set Symbol Spec. From the Layer Symbols dialog, select the
roadcolors symbolspec you just created and click
OK.

After the Map Viewer has read and applied the symbolspec, the map looks like this.

Remove the data tips before going on. To dismiss data tips, right-click one of them and select Delete all data tips from the menu that appears.
Add another layer, a set of points that identifies 13 Boston landmarks. As
you did with the boston_roads layer, import it from a
shapefile:
boston_placenames = shaperead('boston_placenames.shp');
Convert the coordinates of these landmarks to units of survey feet before importing them into Map Viewer. The locations for these landmarks are given in meters.
surveyFeetPerMeter = unitsratio('survey feet','meter');
for k = 1:numel(boston_placenames)
boston_placenames(k).X = ...
surveyFeetPerMeter * boston_placenames(k).X;
boston_placenames(k).Y = ...
surveyFeetPerMeter * boston_placenames(k).Y;
end
From the File menu, select Import From Workspace > Vector Data > Geographic Data Structure. Choose boston_placenames as the data to
import from the workspace and click OK.
The boston_placenames markers are
symbolized as small x markers, but these markers do not
show up over the orthophoto. To solve this problem, create a symbolspec for
the markers to represent them as red filled circles. At the MATLAB command line, type:
places = makesymbolspec('Point',{'Default','Marker','o', ...
'MarkerEdgeColor','r','MarkerFaceColor','r'})The Default keyword causes the specified symbol to be
applied to all point objects in a given layer unless specifically overridden
by an attribute-coded symbol in the same or a different symbolspec.
To activate this symbolspec, pull down the Layers menu, select
boston_placenames, slide right, and select
Set Symbol Spec. In the Layer Symbols dialog
that appears, highlight places and click
OK. The Map Viewer reads the workspace variable
places; the cross marks turn into red circles. Note
that a layer need not be active in order for you to apply a symbolspec to
it.
To see the name of a Boston place name, make
boston_placenames the currently active layer (using
the Active layer menu, and then select Datatip from the Tools menu. The cursor changes to a
cross-hair shape. Click any red circle and the tool places a data tip
annotation on the map with the name of the location.

Zoom in on Beacon Hill for a closer view of the
Massachusetts State House and Boston Common. Select the Zoom in tool; move the (magnifier) cursor until
the X readout is approximately
774,011 and the Y
readout is roughly 2,955,615; and click once to enlarge
the view. The scale changes to about 1:12,500 and the map
appears as below.

From the Tools menu, choose Select Annotations to change from the Datatip tool back to the original cursor. Right-click any of the data tips and select Delete all datatips from the pop-up context menu. This clears the place names you added to the map.
Select an area of interest to save as an image file. Click the Select area tool, and then hold the mouse button down as you draw a selection rectangle. If you do not like the selection, repeat the operation until you are satisfied. If you know what ground coordinates you want, you can use the coordinate readouts to make a precise selection. The selected area appears as a red rectangle.
Note
The Select area tool
is not supported in MATLAB
Online™. To view a particular region on the map, use the
Zoom in, Zoom out, and
Pan tools instead.

In order to be able to save a file in the next step, change your working folder to a writable folder.
Save your selection as an image file. From the File menu, select Save As Raster Map > Selected Area to open an Export to File dialog.
In the Export to File dialog, navigate to a folder where you want to save
the map image, and save the selected area's image as a
.tif file, calling it
central_boston.tif. (PNG and JPG formats are also
available.) A world file, central_boston.tfw, is created
along with the TIF.
Whenever you save a raster map in this manner, two files are created:
An image file
(file.tif,
file.png, or
file.jpg)
An accompanying world file that
georeferences the image
(file.tfw,
file.pgw, or
file.jgw)
The following steps show you how to read world files and display a
georeferenced image outside of mapview.
Read in the saved image and its colormap with the
MATLAB function imread, create a reference
object for it by reading in central_boston.tfw with
worldfileread, and display the
map with mapshow:
[X,cmap] = imread('central_boston.tif');
R = worldfileread('central_boston.tfw','planar',size(X));
figure
mapshow(X,cmap,R);
See the documentation for mapshow for another example
of displaying a georeferenced image.
Experiment with other tools and menu items. For example, you can annotate the map with lines, arrows, and text; fit the map to the window; draw a bounding box for any layer; and print the current view. You can also spawn a new Map Viewer using New View from the File menu. A new view can duplicate the current view, cover the active layer's extent, cover all layer extents, or include only the selected area, if any.
When you are through with a viewing session, close the Map Viewer using
the window's close box or select Close from the
File menu. For more information about
the Map Viewer, see the mapview reference
page.