10
6

Google Earthに線を描画&アニメーションするMATLABコード🌍

Last updated at Posted at 2024-01-10

Google Earth Toolboxというもので遊ぼうと思います.
image.png
これは,Google Earth上で表示する物を表すフォーマット,"KML"や"KMZ"のファイルを作成するライブラリです.このライブラリでKMLやKMZファイルを作成し,Google Earthに読み込ませます.

線の描画 : ge_plot3

成田空港の滑走路から螺旋を生やしたいと思います.

naritax = 140.38;
naritay = 35.76;

N = 100;
t_s = linspace(0,2*2*pi,N);
r_s = linspace(0,1e-2,N);
X = naritax + r_s .* cos(t_s);
Y = naritay + r_s .* sin(t_s);
Z = linspace(0,1e3,N);

kmlStr = ge_plot3(X,Y,Z, ...
    'lineColor','ffffff00', ...
    'lineWidth',5);

ge_output('a.kml', kmlStr); % KMLファイルへの出力

ge_outputは得られたKMLテキストをKMLやKMZファイルに保存する関数です.
image.png

で,ここで問題なのですが,よく見ると線がガタガタになっています.
image.png
これは,Z座標の基準が地面になっているからです.Z座標の基準は,KMLの属性である「標高モード」として色々と定義されています.

このドキュメントによると,Z座標の基準を海面にしたい場合は,absoluteにすればよいそうです.

ge_plot3では,以下のようにして出力される標高モードを変更できます.

kmlStr = ge_plot3(X,Y,Z, ...
    'lineColor','ffffff00', ...
    'lineWidth',5, ...
    'altitudeMode','absolute'...
    );

image.png
ガタガタが無くなった!

アニメーション機能

先ほどのプロット関数ge_plot3などには,timeSpanStarttimeSpanEnd属性というものがあります.これは,そのKMLオブジェクトが現れる時刻を設定するもので,timeSpanStarttimeSpanEndの間に現れるようになります.

これを使えば,アニメーションを作ることができます.
例えば,以下の例のように,時間経過とともに伸びる線を作りたい場合,

  1. 1つの線を数個の線に分ける.
  2. 各線のKMLオブジェクトを生成する.その際,timeSpanStarttimeSpanEndを前のKMLオブジェクトと比べて少しずらす.

というふうにします.

% 線のデータを作る
naritax = 140.38;
naritay = 35.76;
N = 100;
t_s = linspace(0,2*2*pi,N);
r_s = linspace(0,1e-2,N);
X = naritax + r_s .* cos(t_s);
Y = naritay + r_s .* sin(t_s);
Z = linspace(0,1e3,N);

% 時刻データの準備
S = 'yyyy-MM-dd''T''HH:mm:ss''Z';
tBegin = datetime(2024,1,10);
tBegin.TimeZone = 'Asia/Tokyo';
tBegin.Format = S;
dday = 1/3600/24;

kmlStr = [];
for n=1:N-1
    tStart = tBegin+(n*dday);
    tEnd = tStart+dday;
    kmlStr = [kmlStr ge_plot3(X(n:n+1),Y(n:n+1),Z(n:n+1), ...
        'lineColor','ffffff00', ...
        'lineWidth',10, ...
        'altitudeMode','absolute', ...
        'timeSpanStart',char(tStart),...
        'timeSpanStop',char(tEnd)...
        ) ];
end

ge_output('a.kml', kmlStr);

a.gif

自分の研究で使おうかな!

10
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
6