-
Notifications
You must be signed in to change notification settings - Fork 0
/
其他.html
296 lines (240 loc) · 11.5 KB
/
其他.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>
其他 - Road to Geophysics
</title>
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="atom.xml" rel="alternate" title="Road to Geophysics" type="application/atom+xml">
<link href="asset/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<link href="asset/stylesheets/font-awesome.min.css" media="screen, projection" rel="stylesheet" type="text/css">
<script src="asset/javascripts/jquery.min.js"></script>
<script src="asset/highlightjs/highlight.pack.js"></script>
<link href="asset/highlightjs/styles/solarized_dark.css" media="screen, projection" rel="stylesheet" type="text/css">
<script>hljs.initHighlightingOnLoad();</script>
<!--[if lt IE 9]><script src="asset/javascripts/html5.js"></script><![endif]-->
<!-- <link href='http://fonts.googleapis.com/css?family=Nunito:400,300,700' rel='stylesheet' type='text/css'> -->
<style type="text/css">
/* latin */
@font-face {
font-family: 'Nunito';
font-style: normal;
font-weight: 300;
src: local('Nunito-Light'), url(asset/font/1TiHc9yag0wq3lDO9cw0voX0hVgzZQUfRDuZrPvH3D8.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}
/* latin */
@font-face {
font-family: 'Nunito';
font-style: normal;
font-weight: 400;
src: local('Nunito-Regular'), url(asset/font/6TbRXKWJjpj6V2v_WyRbMX-_kf6ByYO6CLYdB4HQE-Y.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}
/* latin */
@font-face {
font-family: 'Nunito';
font-style: normal;
font-weight: 700;
src: local('Nunito-Bold'), url(asset/font/TttUCfJ272GBgSKaOaD7KoX0hVgzZQUfRDuZrPvH3D8.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}
</style>
<style type="text/css">
.container .left-col{ opacity: 1;}
#pagenavi a{ font-size: 1.3em;}
#pagenavi .next:before{ top: 3px;}
#pagenavi .prev:before{ top: 3px;}
.container .mid-col .mid-col-container #content .archives .title{ font-size: 1.5em;}
.container .mid-col .mid-col-container #content article{ padding: 15px 0px;}
#header .subtitle {
line-height: 1.2em;
padding-top: 8px;
}
article pre{ background: none; border: none; padding: 0;}
article .entry-content{text-align: left;}
.share-comment{ padding: 25px 0px; clear: both;}
hr{ margin: 20px 0px;border: 0; border-top:solid 1px #ddd;}
</style>
</head>
<body>
<div class="container">
<div class="left-col">
<div class="intrude-less">
<header id="header" class="inner">
<div class="profilepic">
<img src="asset/icon.jpg" style="width:160px;">
</div>
<h1><a href="index.html">Road to Geophysics</a></h1>
<p class="subtitle"></p>
<nav id="main-nav">
<ul class="main">
<li><a href="index.html">Home</a></li>
<!-- <li><a href="all.html">Blog</a></li>-->
<li><a href="archives.html">Archives</a></li>
</ul>
</nav>
<nav id="sub-nav">
<div class="social">
<!--
<a class="email" href="mailto:" title="Email">Email</a>
<a class="facebook" href="http://www.facebook.com/" title="Facebook">Facebook</a>
<a class="google" href="https://plus.google.com/" rel="author" title="Google+">Google+</a>
<a class="twitter" href="http://twitter.com/" title="Twitter">Twitter</a>
<a class="github" href="https://github.com/" title="GitHub">GitHub</a>
<a class="coderwall" href="https://coderwall.com/" title="Coderwall">Coderwall</a>
<a class="stackoverflow" href="http://stackoverflow.com/users/" title="StackOverflow"></a>
<a class="linkedin" href="http://www.linkedin.com/in/" title="LinkedIn">LinkedIn</a>
<a class="pinterest" href="https://pinterest.com/" title="Pinterest">Pinterest</a>
<a class="delicious" href="http://delicious.com/" title="Delicious">Delicious</a>
<a class="pinboard" href="https://pinboard.in/u:" title="Pinboard">Pinboard</a>
<a class="douban" href="https://www.douban.com/people/" title="Douban">Douban</a>
<a class="quora" href="https://quora.com/" title="Quora">Quora</a>
<a class="instagram" href="https://instagram.com/" title="Instagram">Instagram</a>
<a class="behance" href="https://www.behance.net/" title="Behance">Behance</a>
<a class="facebook" href="http://www.facebook.com/" title="Facebook">Facebook</a>
<a class="twitter" href="http://twitter.com/" title="Twitter">Twitter</a>
<a class="github" href="https://github.com/" title="GitHub">GitHub</a>
-->
<a class="rss" href="atom.xml" title="RSS">RSS</a>
</div>
</nav>
</header>
</div>
</div>
<div class="mid-col">
<div class="mid-col-container"> <div id="content" class="inner">
<div itemscope itemtype="http://schema.org/Blog">
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2016-01-22T10:47:15+08:00" itemprop="datePublished">2016/1/22</time>
</div>
<div class="tags">posted in
<a class='category' href='%E5%85%B6%E4%BB%96.html'>其他</a>
</div>
</div>
<h1 class="title" itemprop="name"><a href="14534308351747.html" itemprop="url">
Matlab与Google earth和GMT格式的交互</a></h1>
<div class="entry-content" itemprop="articleBody">
<h1 id="toc_0">Google earth</h1>
<h2 id="toc_1">使用google-earth获得范围内的点</h2>
<p>一个常见的需求是:怎么样划定一个范围,然后得到范围内的点?这里讲述怎么结合google earth和matlab实现这个功能。<br/>
google earth操作步骤:<br/>
* 1. 打开软件,缩放到合适的视图,然后点击添加路径:<br/>
<img src="media/14534308351747/14534308904208.jpg" alt=""/><br/>
* 2. 如图,我们添加了5个点,大概组成了一个矩形区域<br/>
<img src="media/14534308351747/14534309232558.jpg" alt=""/>
<br/>
可以给这个路径命名为myPath,并改变线条的颜色(样式/颜色),点击确定后会保存这个路径。<br/>
<strong>注意</strong>:已经放置的路径点可以用鼠标拖动修改;滚轮可以缩放调节视图,有利于更细节的修改;键盘的上下左右键可以移动视图;右键删除上一个放置的点(如果要删除中间的某个点,先左键单击它,再右键);如果想插入一个点,先在要插入位置的上一个点左键选中,再在需要插入位置左键点击。<br/>
* 3. 上一步中我们保存了名为myPath的路径,在左侧位置可以找到它,右击,选择将位置另存为<br/>
<img src="media/14534308351747/14534310265726.jpg" alt=""/><br/>
文件类型选择kml<br/>
<img src="media/14534308351747/14534310365955.jpg" alt=""/><br/>
这样我们得到了<code>myPath.kml</code>,用matlab代码可以读取<br/>
* 4. 用<code>read_kml</code>程序获得点的边界txt文件,保存在paths/路径下<br/>
* 5. 用<code>grid_in_bound</code>获得边界内的点,我们寻找所有在边界内的1°×1°的点。<br/>
* 6. 用<code>xyz2kml_points</code>把找到的点转为<code>points_myPath.kml</code>文件,导入到google earth中<br/>
<img src="media/14534308351747/14534310630825.jpg" alt=""/><br/>
可以看到,一共有87个点,每个点的编号标注在旁边。
这3个命令在<code>test_kml_data.m</code>中有具体代码。</p>
<h2 id="toc_2">matlab代码</h2>
<ul>
<li><code>read_kml(ip_kml,op_dir)</code><br/>
ip_kml为kml文件名称,op_dir为输出路径</li>
<li><code>[LLZ_ind,xyz]=grid_in_bound( BD, LLZ )</code><br/>
获得边界内的点</li>
<li><code>read_kml_to_a_single(ip_kml,op_file)</code><br/>
读取kml文件,写入到一个文件中,每个记录用 <code>> 记录名</code>隔开。这种文件适合GMT作图。</li>
<li><code>xyz2kml(op_kml,xy)</code><br/>
将多个线段写成kml文件,输入的xy可以通过命令<code>read_BD_and_name</code>生成。xy包含三个域:<code>xy(ii).x, xy(ii).y, xy(ii).name</code>,当name缺省时,自动转为1:N的字符串</li>
<li><code>xyz2kml_points(op_kml,xy,o_namelist)</code><br/>
将多个点写成kml文件。xy形状为(N,2),<code>o_namelist{ii}</code>为结构体</li>
<li><code>xy=read_BD_and_name(ipdir,namepattern)</code><br/>
例如:<code>read_BD_and_name(‘a/','*txt')</code>,专门供<code>xyz2kml</code>使用,生成其需要的xy</li>
</ul>
<h3 id="toc_3">批量处理模板: 从kml到mask</h3>
<pre><code>clear;
ip_kml = 'wang-Remote-sensing.kml';
bd_dir = 'BD';
op_xy = 'xy_with_nu.mat';
op_mask = 'mask_wang.mat';
iact = 4;
if iact == 1 % 1: kml2xyz
read_kml(ip_kml,bd_dir)
elseif iact == 2 % plot all
xy=read_BD_and_name(bd_dir,'*txt');
% xy = xy([6,7,4,8,2,3,5,1]); % re-order
Nxy = numel(xy);
ik = 0;
for ii = 1:Nxy
xy(ii).group = ii;
end
save( op_xy, 'xy')
elseif iact == 3 % generate group number
load(op_xy);%'xy');
Nxy = numel(xy);
% plot boundary and number
for ii = 1:Nxy
plot(xy(ii).x,xy(ii).y)
h = text(mean(xy(ii).x),mean(xy(ii).y),num2str(xy(ii).group));
set( h,'color','r','fontsize',14)
hold on;
end
all_plot('coast');
hold off
elseif iact == 4 % generate mask
load(op_xy);% 'xy');
OBS = mlonmlat(8);
Nfile = numel(xy);
LLZ_mask = OBS;
LLZ_mask.rg = zeros(size(LLZ_mask.lon));
for ii = 1:Nfile
info(ii).name = xy(ii).name;
info(ii).nu = xy(ii).group;
BD = [xy(ii).x,xy(ii).y];
[LLZ_ind0,vLLZ]=grid_in_bound( BD, OBS );
LLZ_mask.rg(LLZ_ind0.rg==1) = xy(ii).group;
end
LLZ_mask2 = LLZ_mask;
LLZ_mask2.rg(LLZ_mask2.rg==0) = NaN;
rg_plot(LLZ_mask2);
myaxis('tibet-L');
% save(op_mask,'LLZ_mask','info')
end
</code></pre>
<h3 id="toc_4">判断在边界内部:inpolygon</h3>
<p>一个附带的常见需求是求出边界内部的点。matlab自带的函数<code>inpolygon</code>可以解决这个问题<br/>
一个自带的例子:</p>
<pre><code>xv = rand(6,1); yv = rand(6,1);
xv = [xv ; xv(1)]; yv = [yv ; yv(1)];
x = rand(1000,1); y = rand(1000,1);
in = inpolygon(x,y,xv,yv);
plot(xv,yv,x(in),y(in),’.r’,x(~in),y(~in),'.b')
</code></pre>
<p><img src="media/14534308351747/14534323980173.jpg" alt=""/></p>
<h1 id="toc_5">GMT</h1>
<h2 id="toc_6">matlab代码</h2>
<ul>
<li><code>xys=read_segments(ip_xy)</code><br/>
从片段文件中(<code>></code>隔开)读取各个片段,组成<code>xys(ik)</code>,包含域<code>.x, .y, .name</code></li>
</ul>
</div>
</article>
</div>
<nav id="pagenavi">
<div class="center"><a href="archives.html">Blog Archives</a></div>
</nav>
</div>
</div>
<footer id="footer" class="inner">Copyright © 2014
Powered by <a target="_blank" href="http://www.mweb.im">MWeb</a>
Theme by <a href="http://shashankmehta.in/archive/2012/greyshade.html">Shashank Mehta</a>
</footer>
</div>
</div>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script><script type="text/x-mathjax-config">MathJax.Hub.Config({TeX: { equationNumbers: { autoNumber: "AMS" } }});</script>
</body>
</html>