⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m_grid.m

📁 m_map是加拿大学者编写的一个在matlab上绘地图的软件
💻 M
📖 第 1 页 / 共 2 页
字号:
  if ltI==size(X,1) & strcmp(gyaxisloc,'right'),  % Check to see if the projection supports this option.   horiz='left';vert='middle';drawticks=1;   xx=utx(1,:);yy=uty(1,:);rotang=atan2(diff(uty),diff(utx))*180/pi+180;  elseif ltI==1 & strcmp(gyaxisloc,'left');   horiz='right';vert='middle';drawticks=1;   xx=ltx(1,:);yy=lty(1,:);rotang=atan2(diff(lty),diff(ltx))*180/pi;  else   horiz='center';vert='top';ltIp1=ltI+1;drawticks=0;   xx=X(ltI,:); yy=Y(ltI,:);rotang=atan2(Y(ltIp1,:)-Y(ltI,:),X(ltIp1,:)-X(ltI,:))*180/pi;  end; else  if ltI==size(X,1) & strcmp(gyaxisloc,'right'),  % Check to see if the projection supports this option.   horiz='center';vert='top';drawticks=1;   xx=utx(1,:);yy=uty(1,:);rotang=atan2(diff(uty),diff(utx))*180/pi+270;  elseif ltI==1 & strcmp(gyaxisloc,'left');   horiz='center';vert='bottom';drawticks=1;   xx=ltx(1,:);yy=lty(1,:);rotang=atan2(diff(lty),diff(ltx))*180/pi+90;  else   horiz='left';vert='middle';ltIp1=ltI+1;drawticks=0;   xx=X(ltI,:); yy=Y(ltI,:);rotang=atan2(Y(ltIp1,:)-Y(ltI,:),X(ltIp1,:)-X(ltI,:))*180/pi+90;  end; end; if strcmp(gbox,'fancy'),    if gtickdir(1)=='i',      fancybox(lt,MAP_VAR_LIST.lats,'ygrid','left',dpatch,gticklen);       drawticks=0;    else          fancybox2(lt,MAP_VAR_LIST.lats,'ygrid','left',dpatch,gticklen);     end; end;     if drawticks,   [n,m]=size(ltx);   line(reshape([ltx;NaN+ones(1,m)],(n+1)*m,1),reshape([lty;NaN+ones(1,m)],(n+1)*m,1),...        'linest','-','color',gcolor,'linewidth',glinewidth,'tag','m_grid_yticks-left','clip','off');   line(reshape([utx;NaN+ones(1,m)],(n+1)*m,1),reshape([uty;NaN+ones(1,m)],(n+1)*m,1),...        'linest','-','color',gcolor,'linewidth',glinewidth,'tag','m_grid_yticks-right','clip','off'); end; % Finally - the labels! ik=1:size(X,2); for k=ik,   [rotang(k), horizk, vertk] = upright(rotang(k), horiz, vert);   text(xx(k),yy(k),labs{k},'horizontal',horizk,'vertical',vertk,...        'rot',rotang(k),'fontsize',gfontsize*scl(k),'color',gcolor,...	'tag','m_grid_yticklabel','fontname',gfontname); end;end;% Give a 1-1 aspect ratio and get rid of the matlab-provided axes stuff.set(gca,'visible','off',...        'dataaspectratio',[1 1 1],...        'xlim',MAP_VAR_LIST.xlims,...        'ylim',MAP_VAR_LIST.ylims);set(get(gca,'title'),'visible','on');set(get(gca,'xlabel'),'visible','on');set(get(gca,'ylabel'),'visible','on');% Set coordinate system backm_coord(Currentmap.name);%-------------------------------------------------------------% upright simply turns tick labels right-side up while leaving% their positions unchanged.% Sat  98/02/21 Eric Firing%function   [rotang, horiz, vert] = upright(rotang, horiz, vert);if rotang > 180, rotang = rotang - 360; endif rotang < -180, rotang = rotang + 360; endif rotang > 90,   rotang = rotang - 180;elseif rotang < -90,   rotang = 180 + rotang;else   return    % no change needed.endswitch horiz(1)   case 'l'      horiz = 'right';   case 'r'      horiz = 'left';endswitch vert(1)   case 't'      vert = 'bottom';   case 'b'      vert = 'top';end  %--------------------------------------------------------------------------function [L,fs]=m_labels(dir,vals,uservals);% M_LONLABEL creates longitude labels%         Default values are calculated automatically when the grid is %         generated. However, the user may wish to specify the labels%         as either numeric values or as strings (in the usual way%         for axes).%%         If auto-labelling occurs, minutes are labelled in a different%         (smaller) fontsize than even degrees.% Rich Pawlowicz (rich@ocgy.ubc.ca) 2/Apr/1997% If the user has specified [] (i.e. no labels), we return blanks.if isempty(uservals),   L=cellstr(char(' '*ones(length(vals),1)));  fs=1.0*ones(length(L),1);  return;end;% If the user has specified strings, we merely need to make% sure that there are enough to cover all ticks.if any(isstr(uservals)),   L=cellstr( uservals((rem([0:length(vals)-1],length(uservals))+1),:) );  fs=1.0*ones(length(L),1);  return;end;% Otherwise we are going to have to generate labels from numeric% data.if length(uservals)==1 & isnan(uservals),  % use default values  vals=vals(:)'; % make it a row.else                                       % or ones provided  lv=length(vals);  vals=uservals(:)';  while length(vals)<lv,    vals=[vals uservals(:)'];  end;end;% longitudes and latitudes have some differences....if findstr(dir,'lat'),   labname=['S';'N';' '];else  labname=['W';'E';' '];  vals=rem(vals+540,360)-180;end;i=[vals<0;vals>0;vals==0];  % get the 'names' (i.e. N/S or E/W)vals=abs(vals);             % Convert to +ve valuesL=cell(length(vals),1);fs=ones(length(vals),1);% For each label we have different options:%  1 - even degrees are just labelled as such.%  2 - ticks that fall on even minutes are just labelled as even minutes%      in a smaller fontsize.%  3 - fractional minutes are labelled to 2 decimal places in the%      smaller fontsize.for k=1:length(vals),  if rem(vals(k),1)==0,    nam=find(i(:,k));    L{k}=sprintf([' %3.0f^o' labname(nam) ' '],vals(k));  elseif abs(vals*60-round(vals*60))<.01,    L{k}=sprintf([' %2.0f'' '],rem(vals(k),1)*60);    fs(k)=0.75;  else    L{k}=sprintf([' %2.2f'' '],rem(vals(k),1)*60);    fs(k)=0.75;  end;end;% In most cases, the map will have at least one tick with an even degree label,% but for very small regions (<1 degree in size) this won't happen so we% want to force one label to show degrees *and* minutes.if ~any(fs==1),   k=round(length(vals)/2); nam=find(i(:,k)); L{k}={sprintf([' %3.0f^o' labname(nam) ' '],fix(vals(k))),...       sprintf([' %2.2f'' '],rem(vals(k),1)*60)}; fs(k)=1;end;%---------------------------------------------------------function [ltx,lty,utx,uty]=maketicks(X,Y,gticklen,gtickdir);% MAKETICKS makes the axis ticks.%           AXes ticks are based on making short lines at%           the end of the grid lines X,Y.% Rich Pawlowicz (rich@ocgy.ubc.ca) 2/Apr/1997global MAP_VAR_LISTtlen=gticklen*max( diff(MAP_VAR_LIST.xlims),diff(MAP_VAR_LIST.ylims));lx=sqrt((X(2,:)-X(1,:)).^2+(Y(2,:)-Y(1,:)).^2);if strcmp(gtickdir,'out'),  ltx=[X(1,:)-tlen*(X(2,:)-X(1,:))./lx;X(1,:)];  lty=[Y(1,:)-tlen*(Y(2,:)-Y(1,:))./lx;Y(1,:)];else  ltx=[X(1,:);X(1,:)+tlen*(X(2,:)-X(1,:))./lx];  lty=[Y(1,:);Y(1,:)+tlen*(Y(2,:)-Y(1,:))./lx];end;lx=sqrt((X(end,:)-X(end-1,:)).^2+(Y(end,:)-Y(end-1,:)).^2);if strcmp(gtickdir,'out'),  utx=[X(end,:)-tlen*(X(end-1,:)-X(end,:))./lx;X(end,:)];  uty=[Y(end,:)-tlen*(Y(end-1,:)-Y(end,:))./lx;Y(end,:)];else  utx=[X(end,:);X(end,:)+tlen*(X(end-1,:)-X(end,:))./lx];  uty=[Y(end,:);Y(end,:)+tlen*(Y(end-1,:)-Y(end,:))./lx];end;%---------------------------------------------------------function fancybox(vals,lims,gridarg1,gridarg2,dpatch,gticklen);%%  FANCYBOX  - draws fancy outlines for either top/bottom or left/right sides,%              depending on calling parameters.global MAP_PROJECTION% Get xlocations including endpointsxval=sort([lims(1) vals(vals>lims(1) & vals<lims(2)) lims(2)]);% Add all half-way points as well.xval=sort([xval,xval(1:end-1)+diff(xval)/2]);	% Interpolate extra points to handle curved boundary conditions.	xval=(xval(1:end-1)'*ones(1,dpatch)+diff(xval)'*[0:dpatch-1]/dpatch)';xval=[xval(:);lims(2)];	% Get lat/long positions for everything	[X2,Y2,lg2,lgI2]=feval(MAP_PROJECTION.routine,gridarg1,xval,gridarg2);[l2x,l2y,u2x,u2y]=maketicks(X2,Y2,gticklen,'in');if gridarg1(1)=='x', sig=1; else sig=-1; end;id=[1:dpatch size(l2x,2)+[-dpatch+1:0]];dx=diff(l2x(:,id));l2x(2,id)=l2x(2,id)+diff(l2y(:,id)).*([dpatch:-1:1 -1:-1:-dpatch]/(dpatch))*sig;l2y(2,id)=l2y(2,id)-dx.*([dpatch:-1:1 -1:-1:-dpatch]/(dpatch))*sig;dx=diff(u2x(:,id));u2x(2,id)=u2x(2,id)-diff(u2y(:,id)).*([dpatch:-1:1 -1:-1:-dpatch]/(dpatch))*sig;u2y(2,id)=u2y(2,id)+dx.*([dpatch:-1:1 -1:-1:-dpatch]/(dpatch))*sig;% Now actually draw the patches.% Added the z-values 16/Oct/05. px=prod(size(l2x));kk=[0:(dpatch*4):px-3]'*ones(1,dpatch*2+2);kk=kk+ones(size(kk,1),1)*[1 2:2:(dpatch*2+2) (dpatch*2+1):-2:3];patch(reshape(u2x(kk),size(kk,1),size(kk,2))',...      reshape(u2y(kk),size(kk,1),size(kk,2))',...      repmat(bitmax  ,size(kk,2),size(kk,1)),'w','edgecolor','k','clip','off','tag','m_grid_fancybox1');patch(reshape(l2x(kk),size(kk,1),size(kk,2))',...      reshape(l2y(kk),size(kk,1),size(kk,2))',...      repmat(bitmax-1,size(kk,2),size(kk,1)),'k','clip','off','tag','m_grid_fancybox1');kk=[dpatch*2:(dpatch*4):px-3]'*ones(1,dpatch*2+2);kk=kk+ones(size(kk,1),1)*[1 2:2:(dpatch*2+2) (dpatch*2+1):-2:3];patch(reshape(l2x(kk),size(kk,1),size(kk,2))',...      reshape(l2y(kk),size(kk,1),size(kk,2))',...      repmat(bitmax  ,size(kk,2),size(kk,1)),'w','edgecolor','k','clip','off','tag','m_grid_fancybox1');patch(reshape(u2x(kk),size(kk,1),size(kk,2))',...      reshape(u2y(kk),size(kk,1),size(kk,2))',...      repmat(bitmax-1,size(kk,2),size(kk,1)),'k','clip','off','tag','m_grid_fancybox1');%---------------------------------------------------------function fancybox2(vals,lims,gridarg1,gridarg2,dpatch,gticklen);%%  FANCYBOX  - draws fancy outlines for either top/bottom or left/right sides,%              depending on calling parameters.global MAP_PROJECTION% Get xlocations including endpointsxval=sort([lims(1) vals(vals>lims(1) & vals<lims(2)) lims(2)]);% Add all half-way points as well.xval=sort([xval,xval(1:end-1)+diff(xval)/2]);	% Interpolate extra points to handle curved boundary conditions.	xval=(xval(1:end-1)'*ones(1,dpatch)+diff(xval)'*[0:dpatch-1]/dpatch)';xval=[xval(:);lims(2)];	% Get lat/long positions for everything	[X2,Y2,lg2,lgI2]=feval(MAP_PROJECTION.routine,gridarg1,xval,gridarg2);[l2x,l2y,u2x,u2y]=maketicks(X2,Y2,gticklen,'in');	if gridarg1(1)=='x', sig=1; else sig=-1; end;id=[1:dpatch size(l2x,2)+[-dpatch+1:0]];dx=diff(l2x(:,id));l2x(2,id)=l2x(2,id)+diff(l2y(:,id)).*([dpatch:-1:1 -1:-1:-dpatch]/(dpatch))*sig;l2y(2,id)=l2y(2,id)-dx.*([dpatch:-1:1 -1:-1:-dpatch]/(dpatch))*sig;dx=diff(u2x(:,id));u2x(2,id)=u2x(2,id)-diff(u2y(:,id)).*([dpatch:-1:1 -1:-1:-dpatch]/(dpatch))*sig;u2y(2,id)=u2y(2,id)+dx.*([dpatch:-1:1 -1:-1:-dpatch]/(dpatch))*sig;% Now actually draw the patches.% Added large z-values 16/Oct/05 px=prod(size(l2x));kk=[0:(dpatch*2):px-3]'*ones(1,dpatch*2+2);kk=kk+ones(size(kk,1),1)*[1 2:2:(dpatch*2+2) (dpatch*2+1):-2:3]; patch(reshape(l2x(kk),size(kk,1),size(kk,2))',...       reshape(l2y(kk),size(kk,1),size(kk,2))',...       repmat(bitmax-1,size(kk,2),size(kk,1)),...       'w','edgecolor','k','clip','off','linewi',.2,'tag','m_grid_fancybox2'); patch(reshape(u2x(kk),size(kk,1),size(kk,2))',...       reshape(u2y(kk),size(kk,1),size(kk,2))',...       repmat(bitmax-1,size(kk,2),size(kk,1)),...       'w','edgecolor','k','clip','off','linewi',.2,'tag','m_grid_fancybox2');kk=[0:(dpatch*2):size(l2x,2)-dpatch-1]'*ones(1,dpatch+1);kk=(kk+ones(size(kk,1),1)*[1:dpatch+1])';[k1,k2]=size(kk);line(reshape(mean(l2x(:,kk)),k1,k2),reshape(mean(l2y(:,kk))',k1,k2),...     repmat(bitmax,k1,k2),'color','k','clip','off','tag','m_grid_fancybox2');kk=[dpatch:(dpatch*2):size(l2x,2)-dpatch-1]'*ones(1,dpatch+1);kk=(kk+ones(size(kk,1),1)*[1:dpatch+1])';[k1,k2]=size(kk);line(reshape(mean(u2x(:,kk))',k1,k2),reshape(mean(u2y(:,kk))',k1,k2),...     repmat(bitmax,k1,k2),'color','k','clip','off','tag','m_grid_fancybox2');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -