Matlab 2014b m_map 工具箱的19种投影projection

很久之前做过mmap的投影代码及图,不过当时自己水平也不行,无论是对图的理解还是对matlab的理解都不足。后来博客搬来搬去的,图也丢了,代码也挂了,正好最近又在用,所以重新做了一遍。

投影主要分四类

1、Azimuthal projection,方位角投影,默认图是圆形的。有的适合极地,有的适合看天球,保角和等面积的特性也不同。看需要了。利用‘rec’, 'on' 可以把圆形改为方形,多图拼接更美观

2、Cylindrical projections,柱状投影。正常就是方形图,具体的有的适合全球,有的适合很小范围。经纬圈也有的直线有的弯曲,弯曲的经线还可以通过clo 来设置图中甚至图外垂直经线的位置。倾斜型的还可以以地球的任意大圆为中心绘图。柱状图在两侧的变形是很厉害的,所以有的适合中纬度有的适合赤道。

3、Conic Projections,椎体投影。默认画的是同心圆环,但可以设置成方形图,就把周围多画点补成方的。适合中纬度地区,东西长条图

4、Miscellaneous global projection,传统全球图,各种漂亮

各个投影适合多大范围的图,大概怎么设置请参考具体代码和后面附图

m_map projections

%% m_map projections
clear;clc
clf
close all
proj = {...                        Azimuthal  Projections
    'Stereographic';               % 1   Polar regions
    'Orthographic';                % 2   resembles the globe
    'Azimuthal Equal-area';        % 3
    'Azimuthal Equidistant';       % 4
    'Gnomonic';                    % 5
    'Satellite';                   % 6
    ...                            Cylindrical Projections                         
    'Mercator';                    % 7  
    'Miller Cylindrical';          % 8
    'Equidistant Cylindrical';     % 9
    'Oblique Mercator';            % 10
    'Transverse Mercator';         % 11
    'UTM';                         % 12
    'Sinusoidal';                  % 13
    'Gall-Peters';                 % 14
    ...                            Conic Projections
    'Albers Equal-Area Conic';     % 15  
    'Lambert Conformal Conic';     % 16
    ...                            Global Projections
    'Hammer-Aitoff';               % 17  
    'Mollweide';                   % 18
    'Robinson'};                   % 19


for kp = 1:19
    disp(proj{kp})
    name = [num2str(kp,'%02d'),' - ', proj{kp}];
    switch kp
        % Azimuthal Projections
        case 1 
            % Stereographic
            % conformal but not equal area, often used for polar regions
            figure
            m_proj(proj{kp},'lon', 10, 'lat', 85, 'rad', 25,'rec','on')
            m_coast;  m_grid;

        case 2
            % Orthographic
            % neither equal nor conformal, resemble the global
            figure
            m_proj(proj{kp},'lon',110, 'lat',30','rad',90)
            m_coast;  m_grid;
        case 3
            % Azimuthal Equal-Area
            % equal area but not conformal, also called lambert azimuthal
            % equal-area projection
            figure
            m_proj(proj{kp},'lon',110, 'lat',30','rad',90)
            m_coast;  m_grid;
        case 4 
            % Azimuthal Equidistant
            % neither equal nor conformal,
            % all distance from the centre point is true
            figure
            m_proj(proj{kp},'lon',110, 'lat',30','rad',30)
            m_coast;  m_grid;
        case 5
            % Gnomonic
            % neither equal nor conformal
            % all straight lines are great circle routes
            % cause distortion at the edge of map
            % max radii 20~30 at most
            figure
            m_proj(proj{kp},'lon',110, 'lat',30','rad',20)
            m_coast;  m_grid;
        case 6
            % Satellite
            % perspective view of the earth
            % viewpoint altitude is required
            figure
            m_proj(proj{kp},'lon',-20, 'lat',60','alt',2)
            m_coast;  m_grid;

        % Cylindrical and Pseudo-cylindrical Projections 
        
        case 7
            % Mercator
            % conformal, straight lines are thumb lines
            % 'lon',([min max]| center), in center means global map
            % 'lat',[maxlat|[min max]), usually the same in both N and S latitude    
            figure
            m_proj(proj{kp},'lon',-20, 'lat',60)
            m_coast;  m_grid;
        case 8
            % Miller Cylindrical
            % neither equal nor conformal
            % looks nice for world maps
            figure
            m_proj(proj{kp},'lon',-20, 'lat',[-85,85])
            m_coast;  m_grid;
        case 9
            % Equidistant cylindrical
            % neither equal nor conformal
            % equally-spaced lat and lon lines
            % often used for quick plotting 
            figure
            m_proj(proj{kp},'lon',-20, 'lat',[-85,85])
            m_coast;  m_grid;
        case 10
            % Oblique Mercator
            % conformal not equal-area, around an arbitrary great circle
            % used for very short-wide or tall-thin map, i.e. long coast lines
            % two specified point lie in the middle (vertical or horizontal
            figure
            m_proj(proj{kp},'lon',[130,100], 'lat',[20,30],'dir','horizontal','asp',0.5)
            m_plot([130,100],[20,30],'marker','x','color','r')
            m_gshhs_l;  m_grid;
        case 11
            % Transverse Mercator
            % special case of 10, 
            % only meridian of longitude acts as the great circle
            % the meridian can be fixed by 'clo'
            figure
            m_proj(proj{kp},'lon',[110 130],'lat',[0 30],'clo',115,'rec','on')
            m_gshhs_l;  m_grid;
        case 12
            % Universal Transverse Mercator (UTM)
            % special case of 10
            % only for high-quality maps of small regions
            % ellipsodial projection
            % set 'ell' other than normal, 'rec','on',and omit m_grid
            % grid will be shown in meters
            figure
            m_proj(proj{kp},'lon',[115,125], 'lat',[30,40],'ell','sphere','rec','on')
%             m_plot([130,100],[20,30],'marker','x','color','r')
            m_gshhs_i;  m_grid;
        case 13
            % Sinusoidal
            % latitude as straight lines
            % meridians curve
            % equal-area
            figure
            m_proj(proj{kp},'lon',[80,150], 'lat',[0,60],'rec','on')
            m_coast('patch',[.9 .9 .9]);
            m_grid('ytick',[0:10:60],'backcolor',[184 215 245]/255);
        case 14
            % Gall-Peters 
            % parallel latitude and meridians
            % vertical scale distorted to preserve area
            % useful for tropical areas
            figure
            m_proj(proj{kp},'lon',[-80,150], 'lat',[-20,15])
            m_coast('patch',[.9 .9 .9]);
            m_grid('ytick',[-60:10:60],'backcolor',[184 215 245]/255);
            
        % Conic Projections    
        % mid-latitude areas of large east-west extent
        case 15
            % Albers Equal-Area Conic 
            % equal area, not conformal
            % 'clo', as center longitude
            % 'rec', on off
            figure
            m_proj(proj{kp},'lon',[0,180], 'lat',[20,60],'rec','on')
            m_coast('patch',[.9 .9 .9]);
            m_grid('ytick',[-60:10:60],'backcolor',[184 215 245]/255);
        case 16
            % Lambert Conformal Conic 
            % conformal, not equal-area
            figure
            m_proj(proj{kp},'lon',[0,180], 'lat',[20,60],'rec','on')
            m_coast('patch',[.9 .9 .9]);
            m_grid('ytick',[-60:10:60],'backcolor',[184 215 245]/255);
            
        % Miscellaneous Global Projections    
        % <,'lon<gitude>',[min max]>      
        % <,'lat<itude>',[min max]>       
        % <,'clo<ngitude>',value>         
        % <,'rec<tbox>', ( 'on' | 'off' )>
        case 17
            % Hammer-Aitoff
            % equal area
            % curved meridians and parallels
            figure
            m_proj(proj{kp})
            m_coast;m_grid('xaxislocation','middle');
        case 18
            % Mollweide
            % Parallels are straight
            % Also called the Elliptical or Homolographic Equal-Area Projection
            figure
            m_proj(proj{kp})
            m_coast;m_grid('xaxislocation','middle');
        case 19
            figure
            m_proj(proj{kp})
            m_coast;m_grid;
            
    end
    
    
    title(name)
    saveas(gcf,[name,'.png'])
end

% MP_AZIM Azimuthal projections
%           This function should not be used directly; instead it is
%           is accessed by various high-level functions named M_*.
%   Stereographic  - conformal
%   Orthographic   - neither conformal nor equal-area, but looks like globe
%                    with viewpoint at infinity.
%   Az Equal-area  - equal area, but not conformal (by Lambert)
%   Az Equidistant - distance and direction from center are true 
%   Gnomonic       - all great circles are straight lines.
%   Satellite      - a perspective view from a finite distance

% Cylindrical
%   Mercator - conformal
%   Miller - "looks" nice.
%   Equidistant - basically plotting by lat/long, with distances stretched.
% Conic Projections
%    Albers equal-area - has an equal-area property
%    Lambert conformal - is conformal

% Azimuthal projections 
% Azimuthal projections are those in which points on the globe are projected 
% onto a flat tangent plane. Maps using these projections have the property
% that direction or azimuth from the center point to all other points is shown 
% correctly. Great circle routes passing through the central point appear as 
% straight lines (although great circles not passing through the central point 
% may appear curved). These maps are usually drawn with circular boundaries. 
% The following parameters are needed to define an azimuthal projection:
% <,'lon<gitude>',center_long> 
% <,'lat<itude>', center_lat> 
% These parameters define the center point of the map. Maps are aligned so 
% that the specified longitude is vertical at the map center, with its 
% northern end at the top (but see option rotangle below). 
% <,'rad<ius>', ( degrees | [longitude latitude] )> 
% This defines the extent of the map. Either an angular distance in degrees 
% can be given (e.g. 90 for a hemisphere), or the coordinates of a point on 
% the boundary can be specified. 
% <,'rec<tbox>', ( 'on' | 'off' | 'circle' )> 
% The default is to enclose the map in a circular boundary (chosen using 
% either of the latter two options), but a rectangular one can also be 
% specified. However, rectangular maps are usually better drawn using a 
% cylindrical or conic projection of some sort. 
% <,'rot<angle>', degrees CCW> 

% 1 Stereographic 
    % The stereographic projection is conformal, but not equal-area. This 
    % projection is often used for polar regions. 
% 2 Orthographic 
    % This projection is neither equal-area nor conformal, but resembles a 
    % perspective view of the globe. 
% 3 Azimuthal Equal-Area 
    % Sometimes called the Lambert azimuthal equal-area projection, this mapping 
    % is equal-area but not conformal. 
% 4 Azimuthal Equidistant 
    % This projection is neither equal-area nor conformal, but all distances and 
    % directions from the central point are true. 
% 5 Gnomonic 
    % This projection is neither equal-area nor conformal, but all straight lines
    % on the map (not just those through the center) are great circle routes. 
    % There is, however, a great degree of distortion at the edges of the map, 
    % so maximum radii should be kept fairly small - 20 or 30 degrees at most. 
% 6 Satellite 
    % This is a perspective view of the earth, as seen by a satellite at a 
    % specified altitude. Instead of specifying a radius for the map, the 
    % viewpoint altitude is specified:
    
%     
% Cylindrical and Pseudo-cylindrical Projections 
% Cylindrical projections are formed by projecting points onto a plane wrapped around the globe, touching only along some great circle. These are very useful projections for showing regions of great lateral extent, and are also commonly used for global maps of mid-latitude regions only. Also included here are two pseudo-cylindrical projections, the sinusoidal and Gall-Peters, which have some similarities to the cylindrical projections (see below). 
% These maps are usually drawn with rectangular boundaries (with the exception of the sinusoidal and sometimes the transverse mercator). 
% 
% 
% 7 Mercator 
%     This is a conformal map, based on a tangent cylinder wrapped around the
%     equator. Straight lines on this projection are rhumb lines (i.e. the 
%     track followed by a course of constant bearing). The following properties affect this projection: 
%     <,'lon<gitude>',( [min max] | center)> 
%     Either longitude limits can be set, or a central longitude defined 
%     implying a global map. 
%     <,'lat<itude>', ( maxlat | [min max])> 
%     Latitude limits are most usually the same in both N and S latitude, 
%     and can be specified with a single value, but (if desired) unequal 
%     limits can also be used. 
% 8 Miller Cylindrical 
%     This projection is neither equal-area nor conformal, but "looks nice" 
%     for world maps. Properties are the same as for the Mercator, above. 
% 9 Equidistant cylindrical 
%     This projection is neither equal-area nor conformal. It consists of 
%     equally-spaced latitude and longitude lines, and is very often used for
%     quick plotting of data. It is included here simply so that such maps 
%     can take advantage of the grid generation routines. Also known as the 
%     Plate Carree. Properties are the same as for the Mercator, above. 
% 10 Oblique Mercator 
%     The oblique mercator arises when the great circle of tangency is 
%     arbitrary. This is a useful projection for, e.g., long coastlines or 
%     other awkwardly shaped or aligned regions. It is conformal but not 
%     equal area. The following properties govern this projection: 
%     <,'lon<gitude>',[ G1 G2 ]> 
%     <,'lat<itude>', [ L1 L2 ]> 
%     Two points specify a great circle, and thus the limits of this map 
%     (it is assumed that the region near the shortest of the two arcs is 
%     desired). The 2 points (G1,L1) and (G2,L2) are thus at the center of 
%     either the top/bottom or left/right sides of the map (depending on the 
%     'direction' property). 
%     <,'asp<ect>',value> 
%     This specifies the size of the map in the direction perpendicular to 
%     the great circle of tangency, as a proportion of the length shown. An 
%     aspect ratio of 1 results in a square map, smaller numbers result in 
%     skinnier maps. Aspect ratios >1 are possible, but not recommended. 
%     <,'dir<ection>',( 'horizontal' | 'vertical' ) 
%     This specifies whether the great circle of tangency will be horizontal 
%     on the page (for making short wide maps), or vertical (for tall thin 
%     maps). 
% 11 Transverse Mercator 
%     The Transverse Mercator is a special case of the oblique mercator when 
%     the great circle of tangency lies along a meridian of longitude, and 
%     is therefore conformal. It is often used for large-scale maps and 
%     charts. The following properties govern this projection: 
%     <,'lon<gitude>',[min max]> 
%     <,'lat<itude>',[min max]> 
%     These specify the limits of the map. 
%     <,'clo<ngitude>',value> 
%     Although it makes most sense in general to specify the central meridian 
%     as the meridian of tangency (this is the default), certain map 
%     classification systems (noteably UTM) use only a fixed set of central 
%     longitudes, which may not be in the map center. 
%     <,'rec<tbox>', ( 'on' | 'off' )> 
%     The map limits can either be based on latitude/longitude (the default), 
%     or the map boundaries can form an exact rectangle. The difference is 
%     small for large-scale maps. Note: Although this projection is similar 
%     to the Universal Transverse Mercator (UTM) projection, the latter is 
%     actually ellipsoidal in nature. 
% 12 Universal Transverse Mercator (UTM) 
%     UTM maps are needed only for high-quality maps of small regions of the 
%     globe (less than a few degrees in longitude). This is an ellipsoidal 
%     projection. Options are similar to those of the Transverse Mercator, 
%     with the addition of 
%     <,'zon<e>', value 1-60> 
%     <,'hem<isphere>',value 0=N,1=S> 
%     These are computed automatically if not specified. The ellipsoid 
%     defaults to 'normal', a spherical earth of radius 1 unit, but other 
%     options can also be chosen using the following property: 
%     <,'ell<ipsoid>', ellipsoid> 
%     For a list of available ellipsoids try m_proj('set','utm'). 
%     The big difference between UTM and all the other projections is that 
%     for ellipsoids other than 'normal' the projection coordinates are in 
%     meters of easting and northing. To take full advantage of this it 
%     is often useful to call m_proj with 'rectbox' set to 'on' and not 
%     to use the long/lat grid generated by m_grid (since the regular 
%     matlab grid will be in units of meters). 
% 13 Sinusoidal 
%     This projection is usually called "pseudo-cylindrical" since parallels 
%     of latitude appear as straight lines, similar to their appearance in 
%     cylindrical projections tangent to the equator. However, meridians 
%     curve together in this projection in a sinusoidal way (hence the name), 
%     making this map equal-area. 
% 14 Gall-Peters 
%     Parallels of latitude and meridians both appear as straight lines, but 
%     the vertical scale is distorted so that area is preserved. This is 
%     useful for tropical areas, but the distortion in polar areas is extreme. 



% Conic Projections
% 
% Conic projections result from projecting onto a cone wrapped around the 
% sphere. The vertex of the cone lies on the rotational axis of the sphere. 
% The cone is either tangent at a single latitude, or can intersect the 
% sphere at two separated latitudes. It is a useful projection for 
% mid-latitude areas of large east-west extent. The following properties 
% affect these projections: 
% <,'lon<gitude>',[min max]> 
% <,'lat<itude>',[min max]> 
% These specify the limits of the map. 
% <,'clo<ngitude>',value> 
% The central longitude appears as a vertical on the page. The default value 
% is the mean longitude, although it may be set to any value (even one 
% outside the limits). 
% <,'par<allels>',[lat1 lat2]> 
% The standard parallels can be specified. Either one or two parallels can 
% be given, the default is a single parallel at the mean latitude 
% <,'rec<tbox>', ( 'on' | 'off' )> 
% The map limits can either be based on latitude/longitude (the default), 
% or the map boundaries can form an exact rectangle which contain the given 
% limits. Unless the region being mapped is small, it is best to leave this 
% 'off' . 
% The default is to use a spherical earth model for the mapping transformations. 
% However, ellipsoidal coordinates can also be specified. This tends to be 
% useful only for doing coordinate transformations (e.g., if a particular 
% gridded database in in this kind of projection, and you want to find 
% lat/long data), since the difference would be impossible to see by eye on 
% a plot. The particular ellipsoid used can be chosen using the following 
% property: 
% <,'ell<ipsoid>', ellipsoid> 
% For a list of available ellipsoids try m_proj('set','albers'). 
% 
% 15 Albers Equal-Area Conic 
%     This projection is equal-area, but not conformal 
% 16 Lambert Conformal Conic 
%     This projection is conformal, but not equal-area. 

% 
% Miscellaneous global projections 
% 
% There are a number of projections which don't really fit into any of the 
% above categories. Mostly these are global projections (i.e. they show the 
% whole world), and they have been designed to be "pleasing to the eye". 
% I'm not sure what use they are in general, but they make nice logos! 
% 
% 17 Hammer-Aitoff 
%     An equal-area projection with curved meridians and parallels. 
% 18 Mollweide 
%     Also called the Elliptical or Homolographic Equal-Area Projection. 
%     Parallels are straight (and parallel) in this projection. Note that 
%     example 4 shows a rather sophisticated use designed to reduce 
%     distortion, a more standard map can be made using 
%     m_proj('mollweide');m_coast('patch','r');m_grid('xaxislocation','middle');
% 19 Robinson 
%     Not equal-area OR conformal, but supposedly "pleasing to the eye". 

 

 

  • 26
    点赞
  • 112
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
“No map projection initialized - call m_proj first!”是一个错误提示信息,通常在使用地理信息系统软件或地图相关的编程代码时会遇到。该错误的意思是在进行地图投影前未进行地图投影的初始化操作。 在地图投影中,地球的三维表面需要转换为二维平面以便进行地图绘制和分析等操作。不同的地图投影方法会通过数学模型来近似地球的形状,并将地球的曲面映射到平面上。在进行地图绘制之前,需要先配置和初始化地图投影,以确定使用哪投影方法以及投影参数等相关信息。 若出现“No map projection initialized - call m_proj first!”的错误提示,说明在进行地图绘制或相关操作前没有先调用相应的地图投影初始化函数。可以通过在代码中添加合适的地图投影初始化函数来解决该问题,例如使用m_proj函数进行地图投影的初始化。这个初始化函数会根据定义的参数来初始化地图投影。 例如,以下是一个使用Python的Basemap库示例代码,展示了如何初始化地图投影以解决该错误: ```python from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt # 创建一个地图投影对象 m = Basemap(projection='merc', resolution='l', llcrnrlat=-60, urcrnrlat=90, llcrnrlon=-180, urcrnrlon=180) # 初始化地图投影 m.proj() # 在地图上绘制一些内容 m.drawcoastlines() m.drawcountries() m.drawstates() m.fillcontinents(color='coral', lake_color='aqua') # 显示地图 plt.show() ``` 通过调用`m.proj()`函数,我们可以初始化Basemap对象的地图投影,然后可以像上面的示例代码那样在地图上绘制各地理要素。 总之,为了解决“No map projection initialized - call m_proj first!”的错误,我们需要在进行地图绘制或相关操作之前先调用适当的地图投影初始化函数,并配置合适的投影参数。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值