forked from GERSL/Fmask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Readopentopo.m
121 lines (104 loc) · 3.55 KB
/
Readopentopo.m
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
function DEM = Readopentopo(varargin)
%READOPENTOPO read DEM using the opentopography.org API
%
% Syntax
%
% DEM = readopentopo(pn,pv,...)
%
% Description
%
% readopentopo reads DEMs from opentopography.org using the API
% described on:
% http://www.opentopography.org/developers
% The DEM comes in geographic coordinates (WGS84) and should be
% projected to a projected coordinate system (use reproject2utm) before
% analysis in TopoToolbox.
%
% Input arguments
%
% Parameter name values
% 'filename' provide filename. By default, the function will save
% the DEM to a temporary file in the system's temporary
% folder.
% 'north' northern boundary in geographic coordinates (WGS84)
% 'south' southern boundary
% 'west' western boundary
% 'east' eastern boundary
% 'demtype' The global raster dataset - SRTM GL3 (90m) is
% 'SRTMGL3', SRTM GL1 (30m) is 'SRTMGL1', SRTM GL1
% (Ellipsoidal) is 'SRTMGL1_E', and ALOS World 3D 30m
% is 'AW3D30'
% 'deletefile' 'true' or false. True, if file should be deleted
% after it was downloaded and added to the workspace.
%
% Output arguments
%
% DEM Digital elevation model in geographic coordinates
% (GRIDobj)
%
% See also: GRIDobj, websave
%
% Reference: http://www.opentopography.org/developers
%
% Author: Wolfgang Schwanghart (w.schwanghart[at]geo.uni-potsdam.de)
% Date: 19. June, 2017
p = inputParser;
addParameter(p,'filename',[tempname '.tif']);
% addParameter(p,'interactive',false);
addParameter(p,'north',37.091337);
addParameter(p,'south',36.738884);
addParameter(p,'west',-120.168457);
addParameter(p,'east',-119.465576);
addParameter(p,'demtype','SRTMGL3');
addParameter(p,'deletefile',true);
parse(p,varargin{:});
demtype = validatestring(p.Results.demtype,{'SRTMGL3','SRTMGL1','SRTMGL1_E','AW3D30'},'readopentopo');
url = 'http://opentopo.sdsc.edu/otr/getdem';
% create output file
f = fullfile(p.Results.filename);
% save to drive
options = weboptions('Timeout',inf);
west = p.Results.west;
east = p.Results.east;
south = p.Results.south;
north = p.Results.north;
% if any([isempty(west) isempty(east) isempty(south) isempty(north)]) || p.Results.interactive;
% wm = webmap;
% % get dialog box
% messagetext = ['Zoom and resize the webmap window to choose DEM extent. ' ...
% 'Click the close button when you''re done.'];
% d = waitdialog(messagetext);
% uiwait(d);
% [latlim,lonlim] = wmlimits(wm);
% west = lonlim(1);
% east = lonlim(2);
% south = latlim(1);
% north = latlim(2);
% end
websave(f,url,'west',west,...
'east',east,...
'north',north,...
'south',south,...
'outputFormat', 'GTiff', ...
'demtype', demtype, ...
options);
DEM = GRIDobj(f);
DEM.name = demtype;
if p.Results.deletefile
delete(f);
end
end
% function d = waitdialog(messagetext)
% d = dialog('Position',[300 300 250 150],'Name','Choose rectangle region',...
% 'WindowStyle','normal');
%
% txt = uicontrol('Parent',d,...
% 'Style','text',...
% 'Position',[20 80 210 40],...
% 'String',messagetext);
%
% btn = uicontrol('Parent',d,...
% 'Position',[85 20 70 25],...
% 'String','Close',...
% 'Callback','delete(gcf)');
% end