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

    %% Specify Map Projection Origin and Frame Limits Automatically
% This example shows how to specify the map projection origin and frame
% limits using the two map limit properties: |MapLatLimit| and
% |MapLonLimit|. While the map axes supports properties to set these values
% directly, |Origin|, |FLatLimit|, and |FLonLimit|, it is easier and more
% intuitive to use the map limit properties, especially when creating a new
% map axes with |axesm|.  This example highlights the interdependency of
% the map axes limits and the map limit properties.
%%
% Create a map using a cylindrical projection or pseudo-cylindrical
% projection showing all or most of the Earth, with the Equator running as
% a straight horizontal line across the center of the map. The map is
% bounded by a geographic quadrangle and the projection origin is located
% on the Equator, centered between the longitude limits you specify using
% the map projection limits.

% Copyright 2015 The MathWorks, Inc.

latlim = [-80 80];
lonlim = [100 -120];
figure
axesm('robinson','MapLatLimit',latlim,'MapLonLimit',lonlim,...
    'Frame','on','Grid','on','MeridianLabel','on','ParallelLabel','on')
axis off
setm(gca,'MLabelLocation',60)
load coastlines
plotm(coastlat,coastlon)
%%
% Check that the |axesm| function set the origin and frame limits based on
% the values you specified using the |MapLatLim| and |MapLonLim|
% properties. The longitude of the origin should be located halfway between
% the longitude limits of 100 E and 120 W. Since the map spans 140 degrees,
% adding half of 140 to the western limit, the origin longitude should be
% 170 degrees. The frame is centered on this longitude with a half-width of
% 70 degrees and the origin latitude is on the Equator.
origin = getm(gca,'Origin')
flatlim = getm(gca,'FLatLimit')
flonlim = getm(gca,'FLonLimit')
%%
% Shift the western longitude to 40 degrees E (rather than 100 degrees) to
% include a little more of Asia. Use the |setm| function to assign a new
% value to the |MapLonLimit| property. Note the asymmetric appearance of
% the map.
setm(gca,'MapLonLimit',[40 -120])
%%
% To correct the asymmetry, shift the western longitude again, this time
% specifying the origin. While the |MapLatLimit| and |MapLonLimit|
% properties are convenient, the values of the |Origin|, |FLatLimit|, and
% |FLonLimit| properties take precedence. You must specify the value of the
% origin to achieve the map you intended. The best way to do this is to
% specify an empty value for the |Origin| property and let the |setm|
% command calculate the value.
setm(gca,'MapLonLimit',[40 -120],'Origin',[])