www.gusucode.com > map 案例源码 matlab代码程序 > map/CreateSimpleMapsUsingUsamapExample.m

    %% Create Simple Maps Using usamap
% This example shows how to create maps of the United States using the
% |usamap| function. The |usamap| function lets you make maps of the United
% States as a whole, just the conterminous portion (the "lower 48" states),
% groups of states, or a single state. The map axes you create with the
% |usamap| function has a labelled grid fitted around the area you specify
% but contains no data, allowing you to generate the kind of map you want
% using display functions such as the |geoshow| function.
%%
% Specify map limits and set up a map axes object. This example creates a
% map of the Chesapeake Bay region. 

% Copyright 2015 The MathWorks, Inc.

latlim = [37 40];
lonlim = [-78 -74];
figure
ax = usamap(latlim, lonlim)
axis off
%%
% Determine the map projection used by the |usamap| function. The Lambert
% Conformal Conic projection is often used for maps of the conterminous
% United States.
getm(gca,'MapProjection')
%%
% Use the |shaperead| function to read U.S. state polygon boundaries from
% the |usastatehi| shapefile. The function returns the data in a geostruct.
states = shaperead('usastatehi',...
    'UseGeoCoords',true,'BoundingBox',[lonlim',latlim']);
%%
% Make a symbolspec to create a political map using the |polcmap| function.
faceColors = makesymbolspec('Polygon',...
    {'INDEX',[1 numel(states)],'FaceColor',polcmap(numel(states))});
%%
% Display the filled polygons with the geoshow function.
geoshow(ax,states,'SymbolSpec',faceColors)
%%
% Extract the names for states within the window from the geostruct and use
% the |textm| function to plot them at the label points provided by the
% geostruct. Because |polcmap| assigns random pastel colors to patches,
% your map might look different than this example.
for k = 1:numel(states)
    labelPointIsWithinLimits = ...
        latlim(1) < states(k).LabelLat &&...
        latlim(2) > states(k).LabelLat &&...
        lonlim(1) < states(k).LabelLon &&...
        lonlim(2) > states(k).LabelLon;
    if labelPointIsWithinLimits
        textm(states(k).LabelLat,...
            states(k).LabelLon, states(k).Name,...
            'HorizontalAlignment','center')
    end
end
textm(38.2,-76.1,' Chesapeake Bay ',...
    'fontweight','bold','Rotation',270)