当前位置: 首页 > news >正文

plotm matlab,MATLAB画地图的工具:worldmap和m_map

Mapping

Toolbox是Matlab提供的,一整套包含许多函数跟图形用户界面的工具箱;它可以帮助用户分析几何空间方面的数据;并以地图的形式显示出来!

worldmap命令

help worldmap WORLDMAP 创建世界上给定区域的坐标

WORLDMAP 区域 或 WORLDMAP(区域名) 新建一个空的地图坐标,这个投影模型和限制与此区域相适应 . REGION

可能是一个字符串或则 cell array of strings. Permissible strings 包括大陆,

国家,岛屿,比如 'World', 'North Pole', 'South Pole', and

'Pacific'.

>> worldmap world

%绘制世界地图坐标或

>> worldmap ('world)

a4c26d1e5885305701be709a3d33442f.png

1、示例一:带有海岸线的世界地图

coast.m在目录D:Program

FilesMATLABR2010atoolboxmapmapdemos

>> %

worldmap('World')

load coast

plotm(lat, long)

coast中包含lat和long两个double型向量9865*1,9865*1

>> help plotm

PLOTM 投影二维直线和点到地图坐标

PLOTM(lat,lon)将线型对象投影到最近使用的地图坐标.

输入的维度(latitude)和经度(longitude)数据必须与最近使用地图坐标单位一致。

PLOTM will clear

the current map if the hold state is off.

a4c26d1e5885305701be709a3d33442f.png

>> help load

LOAD 从 MAT-file加载数据到工作空间.

S =

LOAD(FILENAME) 加载来自a MAT-file

文件的变量到结构数组或来自ascii文件的数据到双精度数组.

2、实例二:带有陆地、主要湖泊河流和城市和人口密集区的世界地图

landareas

landareas.shp

shx、dbf在D:Program

FilesMATLABR2010atoolboxmapmapdemos目录下

>> % Worldmap with land areas, major lakes and rivers, and cities and

% populated places

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')

a4c26d1e5885305701be709a3d33442f.png

geoshow(ax,

land, 'FaceColor', [0.5 0.7 0.5])

陆地的表面颜色

geoshow(cities, 'Marker', '.',

'Color', 'red')

城市用'.'标记

H =

WORLDMAP(...)返回地图投影的句柄

>> help setm

SETM 设置地图坐标和图形对象的属性

SETM(H,'MapAxesPropertyName',PropertyValue,...)

H 有效的地图坐标句柄,

sets the map properties specified in the input list.

The

map properties

must be recognized by AXESM.

SETM(H, 'MapPosition', POSITION)

H 为有效的地图

text object, uses a two or three element

position vector

specifying[维度,经度,海拔] [latitude, longitude,

altitude].  对于两个元素的向量, altitude = 0 is

assumed.

SETM(H, 'Graticule', LAT, LON, ALT)

where H is a valid projected surface

object, uses LAT and LON 相同大小的矩阵specify the 格网点.

The input ALT can be either a scalar to

specify the altitude plane, a matrix of the same size as LAT and

LON, or an empty matrix.  If omitted, ALT =

0 is assumed.

>>

help shaperead

SHAPEREAD

从shapefile中读取向量特征和属性

S = SHAPEREAD(FILENAME)

返回 N×1 结构数组, S,

containing one

element for each non-null geographic feature in

the shapefile.  S

is a "mapstruct" geographic data structure array

and combines

coordinates/geometry, expressed in terms of map X and Y,

with non-spatial feature

attributes.

Name  Description of Value

Purpose

Attributes  Cell array of

attribute  Omit attributes

that are

names

not listed. Use

{} to omit

all attributes. Also sets

the order of attributes in

the structure array.

UseGeoCoords  Scalar logical  如果为true,

替换X和Y field names with 'Lon'

and 'Lat', respectively.默认为

false.

>> help geoshow

GEOSHOW

显示地图纬度和经度数据

>> help geoshow

GEOSHOW Display map latitude and longitude data

GEOSHOW(LAT, LON) or

GEOSHOW(LAT, LON, ..., 'DisplayType', DISPLAYTYPE, ...)

投影并显示纬度和经度向量,

LAT and LON, 使用存储在地图坐标系中的投影模型.如果无投影模型, 纬度和经度使用默认Plate Carree 投影.LAT

and LON may contain embedded NaNs, delimiting individual lines or

polygon parts. DISPLAYTYPE can be 'point', 'line', or 'polygon'

anddefaults to 'line'.

projects and displays the latitude

and longitude vectors, LAT and LON, using

the projection stored in the axes. If there is no

projection, the latitudes and longitudes

are projected using a default Plate Carree projection.LAT and LON

may contain embedded NaNs, delimiting individual lines

or polygon parts. DISPLAYTYPE can be 'point',

'line', or 'polygon' anddefaults to 'line'.

*用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')

a4c26d1e5885305701be709a3d33442f.png

2、matlab的m_map工具箱及添加行政边界底图

对习惯使用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绘图中的应用。

3、[原创ZHOU

Feng]在matlab中利用worldmap画中国区域图时加上台湾和钓鱼岛

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!!!!!!!!!!!!!!!

相关文章:

  • matlab不能盗版吗,matlab为了防止盗版,会不会篡改程序运行结果?这是明证
  • matlab 复权数据,〖Matlab〗基于通达信股价数据的复权处理(fantuanxiaot版本)
  • 微信小程序向php传递数据,微信小程序 跳转传递数据的方法
  • mysql8默认存储,MySQL 8.0安装
  • php berkeleydb,berkeleydb-5.1
  • matlab vs 打包exe文件路径,Matlab中調用VS編譯的exe文件並傳遞變量 的方法
  • php 访问受保护的属性,php – 我们应该直接访问受保护的属性还是使用getter?
  • PHP限制请求类型,Laravel :API 请求频率限制(Throttle中间件),自定义返回JSON类型,自定义时间...
  • oracle归档增长快,归档日志增长过快的问题
  • oracle 行转列 顺序,Oracle PIVOT 行转列的单行小计如何实现?
  • oracle asm安装详情,oracle ASM安装记录
  • oracle in _all和any的区别,英语all和any的用法区别
  • linux用户隔离,CentOS下实现用户隔离模式的SFTP
  • linux kdump保存的目录,学习猿地-Linux中的Kdump服务
  • linux文件拆分,Linux文件分割和合并
  • ES6指北【2】—— 箭头函数
  • CSS魔法堂:Absolute Positioning就这个样
  • JavaScript新鲜事·第5期
  • js
  • Spark VS Hadoop:两大大数据分析系统深度解读
  • spring boot 整合mybatis 无法输出sql的问题
  • 初探 Vue 生命周期和钩子函数
  • 力扣(LeetCode)21
  • 容器化应用: 在阿里云搭建多节点 Openshift 集群
  • 线性表及其算法(java实现)
  • 阿里云ACE认证之理解CDN技术
  • # Maven错误Error executing Maven
  • # Swust 12th acm 邀请赛# [ E ] 01 String [题解]
  • #1015 : KMP算法
  • #define
  • #FPGA(基础知识)
  • #我与Java虚拟机的故事#连载01:人在JVM,身不由己
  • #我与Java虚拟机的故事#连载06:收获颇多的经典之作
  • ( 用例图)定义了系统的功能需求,它是从系统的外部看系统功能,并不描述系统内部对功能的具体实现
  • (2)nginx 安装、启停
  • (8)STL算法之替换
  • (博弈 sg入门)kiki's game -- hdu -- 2147
  • (附源码)基于ssm的模具配件账单管理系统 毕业设计 081848
  • (解决办法)ASP.NET导出Excel,打开时提示“您尝试打开文件'XXX.xls'的格式与文件扩展名指定文件不一致
  • (转载)跟我一起学习VIM - The Life Changing Editor
  • .bat批处理(四):路径相关%cd%和%~dp0的区别
  • .NET delegate 委托 、 Event 事件
  • .Net 高效开发之不可错过的实用工具
  • .net 中viewstate的原理和使用
  • .NET/C# 编译期能确定的字符串会在字符串暂存池中不会被 GC 垃圾回收掉
  • .NET/C# 解压 Zip 文件时出现异常:System.IO.InvalidDataException: 找不到中央目录结尾记录。
  • .NET中 MVC 工厂模式浅析
  • /etc/fstab 只读无法修改的解决办法
  • ::什么意思
  • @kafkalistener消费不到消息_消息队列对战之RabbitMq 大战 kafka
  • @synthesize和@dynamic分别有什么作用?
  • [ C++ ] STL---string类的使用指南
  • [2008][note]腔内级联拉曼发射的,二极管泵浦多频调Q laser——
  • [3D基础]理解计算机3D图形学中的坐标系变换
  • [ABC294Ex] K-Coloring