-
Notifications
You must be signed in to change notification settings - Fork 111
/
getextent.m
70 lines (62 loc) · 2.13 KB
/
getextent.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
function ext = getextent(DEM,latlonout)
%GETEXTENT return extent of a GRIDobj
%
% Syntax
%
% ext = getextent(DEM,latlonout)
%
% Description
%
% getextent returns the horizontal extent of the GRIDobj DEM. The
% function will return the maximum extent in WGS84 geographical
% coordinates if latlonout is true.
%
% Input arguments
%
% DEM GRIDobj
% latlonout false (default) or true. If true, getextent will return
% the extent in geographical coordinates. This is, however,
% only possible if DEM has a known projected coordinate
% system (DEM.georef.mstruct must be set), and if the
% mapping toolbox is available.
%
% Output arguments
%
% ext four element row vector with following format
% [west east south north]
%
%
% See also: GRIDobj, readopentopo, GRIDobj/getoutline
%
% Author: Wolfgang Schwanghart (w.schwanghart[at]geo.uni-potsdam.de)
% Date: 9. October, 2018
if nargin == 1
latlonout = false;
end
if ~latlonout
% This is easy. Just return the extent
[x,y] = getcoordinates(DEM);
ext = [min(x) max(x) min(y) max(y)];
else
mstructavailable = isfield(DEM.georef,'mstruct');
if mstructavailable && ~isempty(DEM.georef.mstruct)
% mstruct is available. Great.
[x,y] = getcoordinates(DEM);
% maximum projected extent
extp = [min(x) max(x) min(y) max(y)];
[lat,lon] = minvtran(DEM.georef.mstruct,...
[extp(1) extp(1) extp(2) extp(2)]',...
[extp(3) extp(4) extp(3) extp(4)]');
ext = [min(lon) max(lon) min(lat) max(lat)];
else
[x,y] = getcoordinates(DEM);
ext = [min(x) max(x) min(y) max(y)];
if any(ext(1:2) > 180) || any(ext(1:2) < -180) || ...
any(ext(3:4) > 90) || any(ext(3:4) < -90)
error('TopoToolbox:getextent',...
['GRIDobj does not have a map projection structure.\n' ...
'In addition, coordinates are out of range to be in \n'...
'geographic coordinates.'])
end
end
end