[转载]matlab画地图的工具:worldmap和m_map
2011-05-24 18:28阅读:
matlab画地图的工具:worldmap和m_map
*用MATLAB画世界地图并加散点
clear;clc;
worldmap([-55 -30],[-110 -60]);
h1=axesm('MapProjection','eqdcylin','maplatlimit',[-58
-30],'maplonlimit',[-110
-60],'frame','on','parallellabel','on','meridianlabel','on','flinewidth',1,'plabellocation',5,'mlabellocation',10);
setm(h1,'fedgecolor',[.5 .6 .6],
'fontname','Arial','fontsize',7);
grid off;
h=geoshow('landareas.shp');
x=
y=
scatterm(y,x,'filled','k')
加等值线
clear;clc;
A=xlsread('2010作图2','5','N2:P26');
[x,y]=meshgrid(-106.5:-81.5,-46.5:-35.5);
z=abs(griddata(A(:,1),A(:,2),A(:,3),x,y,'v4'));
subplot(2,2,1)%figure(1)
worldmap([-55 -30],[-110 -60]);
h1=axesm('MapProjection','eqdcylin','maplatlimit',[-58
-30],'maplonlimit',[-110
-60],'frame','on','parallellabel','on','meridianlabel','on','flinewidth',1,'plabellocation',5,'mlabellocation',10);
setm(h1,'fedgecolor',[.5 .6
.6], 'fontname','Arial','fontsize',7);
grid off;
h=geoshow('landareas.shp');
scatterm(A(:,2),A(:,1),'filled','k')
[c,h] =contourm(y,x,z,[0.6,0.8,0.9],'k-');
%等值线
hold
on;[cc,hh]=contourm(y,x,z,[0.1,0.2,0.3,0.4,0.5,0.7],'k-');
clabel(c,h)
title('5月')
1、用matlab画世界地图
[matlab自带的例子]
ax =
worldmap('World'); setm(ax, 'Origin',
[0 180 0]) land = shaperead('landareas', 'UseGeoCoords', true);
geoshow(ax, land, 'FaceColor', [0.5 0.7 0.5]) lakes =
shaperead('worldlakes', 'UseGeoCoords', true); geoshow(lakes,
'FaceColor', 'blue') rivers = shaperead('worldrivers',
'UseGeoCoords', true); geoshow(rivers, 'Color', 'blue') cities =
shaperead('worldcities', 'UseGeoCoords', true); geoshow(cities,
'Marker', '.', 'Color', 'red')
2、
matlab的m_map工具箱及添加行政边界底图
from
http://blog.163.com/ahualian@126/blog/static/2350491720093238409154/
对习惯使用matlab的人来说,m_map是一个很好的绘制地图的免费工具箱。可以选择的投影种类近20种,包括常用的Lambert、Mercator、UTM等。可以测量距离(
m_lldist, m_xydist
),绘制等值线(m_contour),等值线填充图(m_contourf),矢量图(m_quiver),栅格图(m_pcolor)等,并与相应的matlab函数语法类似,很容易使用。
m_map通过m_coast提供1/4
degree分辨率的全球海岸线,通过下载GSHHS可以得到更高分辨率的海岸线数据。
除海岸线外,还可以利用已有的GIS行政边界资料,在地图上添加行政边界底图。具体作法为:下载.shp格式的行政边界文件(
国家基础地理信息系统的下载服务),将下载的.shp文件通过mapinfo转换成.dxf文件,利用已编译好的fortran程序,读取经纬度信息,输出.dat文件。导入matlab空间,可以直接m_plot,也可以调用m_plotbndry()。
通过以上方法可以实现.shp在matlab绘图中的应用。
m_map工具箱的下载和介绍
fortran程序及.mat文件下载
3、[原创ZHOU
Feng]在matlab中利用worldmap画中国区域图时加上台湾和钓鱼岛
from
http://www.sciencenet.cn/m/Print.aspx?id=210235
Matlab是我们常用的一个画图和计算、仿真工具,在我们海洋科研中,经常在画图时需要加上底图(譬如海岸线,国界、省界线等等)。常用的一个工具包是M_map。但这里我要讲的是利用matlab自带的一个画图工具包话底图,这个工具包就是worldmap.
worldmap的一般用法约为:
>> figure; worldmap('china');
polcmap;
或者
>> figure;
worldmap china; polcmap;
如果要加入颜色的画,一般可以这样:
>> figure
worldmap('china','patch')
scaleruler
这时候问题就出来了。因为鬼子偷偷的讲台湾和大陆用两种颜色表示;甚至,如果你放大图片的画,会发现钓鱼岛也是不同颜色。这个是我们不能忍受的!!!!!
于是我就费了一点时间,琢磨这个画图,然后修改。下面是这个脚本程序,在matlab中执行就可,这时候台湾和钓鱼岛和大陆就是一个颜色了^_^。
用兴趣的朋友可以把这个用法举一反三((ZHOU
Feng)zhoufeng@sio.org.cn。matlab版本是6.5)。
不过老实说,我不太用matlab自带的这个画图包,用M_map比较多一点。试验一下,感觉还可以用用。
画上述图的代码如下:
% 把台湾和大陆合成一个文件保存起来,这样画图用patch就是一种颜色(Zhou Feng, 2008-06-30, SOED,
Hangzhou)。
%
% by ZHOU Feng
% zhoufeng@sio.org.cn
% SOED, 2nd Institute of Oceanography
% 2008-06-30
s1 = worldhi('china');
s2 = worldhi('taiwan');
disp(s1);
% add Taiwan together (ZHOU Feng)zhoufeng@sio.org.cn
s = s1;
s.lat = [s1.lat;NaN; s2.lat];
s.long= [s1.long; NaN;s2.long];
% add the Diaoyu Island (钓鱼岛)
% 钓鱼岛群岛由钓鱼岛、黄尾岛、赤尾岛、南小岛、北小岛、大南小岛、大北小岛和飞濑岛等岛屿组成,总面积约7平方公里。
% 地理位置:东经123°-124°34′北纬25°40′-26°。
%
% ---这里的分辨率只有两块 --
s3 = worldhi('japan');
%(ZHOU
Feng)zhoufeng@sio.org.cn
x = s3.long;
y = s3.lat;
idx = find(x>123.0 & x<124.5);
idy = find(y> 25.5 & y< 26.0);
m = length(idy);
id=[];
for i=1:m
tmp=find(idx ==
idy(i));
if isempty(tmp)
else
id = [id; idx(tmp)];
%(ZHOU
Feng)zhoufeng@sio.org.cn
end
end
%%longd = x(id);
%%latd
= y(id);
%
% find nan
dtmp = find(diff(id)>1);
if isempty(dtmp)
disp('no
change')
elseif length(dtmp)==1
idnew = [id(1:dtmp);
id(dtmp+1)-1;id(dtmp+1:end)];
else
for
j=1:length(dtmp)
idnew =
[id(1:dtmp(j)+j-1); id(dtmp(j)+1)+j-1; id(dtmp(j)+j+1:end)];
% 未试验,可能有误
end
end
longd = x(idnew);
latd
= y(idnew);
s.lat = [s.lat; NaN; latd];
s.long= [s.long; NaN; longd];
worldmap china
h = displaym(s);
polcmap
OK!!!!!!!!!!!!!!!