-
Notifications
You must be signed in to change notification settings - Fork 9
/
geoquadps.m
109 lines (90 loc) · 2.7 KB
/
geoquadps.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
function h = geoquadps(latlim,lonlim,varargin)
% geoquadps plots a geographic quadrangle in polar stereographic units.
%
%% Syntax
%
% geoquadps(latlim,lonlim)
% geoquadps(...,LineProperty,LineValue)
% geoquadps(...,'meridian',meridian)
% h = geoquadps(...)
%
%% Description
%
% geoquadps(latlim,lonlim) plots a geographic quadrangle bound by the
% limits of the two-element vectors latlim,lonlim. The latlim variable
% must be [SouthernLimit NorthernLimit] and lonlim must be [WesternLimit EasternLimit].
%
% geoquadps(...,LineProperty,LineValue) specifies any line properties.
%
% geoquadps(...,'meridian',meridian) specifies a meridian longitude along
% which the polar stereographic projection is centered. Default meridian
% is 0, which puts Fimbul Ice Shelf at the top of the map. To center the
% map on your quandrangle, try mean(lonlim) as the meridian value.
%
% h = geoquadps(...) returns a handle h of the plotted object.
%
%% Examples
% Type
%
% showdemo geoquadps_documentation
%
% for examples.
%
%% Author Info
% This function was written by Chad A. Greene of the University
% of Texas at Austin, August 2018.
%
% See also: plotps, mapzoomps, inset_unproj, and inpsquad.
%% Error checks:
narginchk(2,Inf)
assert(isequal(numel(latlim),numel(lonlim),2)==true,'Error: latlim and lonlim must each be two-element arrays.')
assert(islatlon(latlim,lonlim)==1,'Error: latlim and lonlim must be geographic coordinates.')
%% Input parsing:
% The meridian is the vertical line at the top center of the map:
tmp = strcmpi(varargin,'meridian');
if any(tmp)
meridian = varargin{find(tmp)+1};
tmp(find(tmp)+1) = true;
varargin = varargin(~tmp);
else
meridian = 0;
end
% Plot in meters by default, unless user wants kilometers:
tmp = strcmpi(varargin,'km');
if any(tmp)
plotkm = true;
varargin = varargin(~tmp);
else
plotkm = false;
end
%% Build a "quadrangle":
% Unwrap phase if necessary:
if diff(lonlim)<0
lonlim(2) = lonlim(2)+360;
end
% Estimate the curve along constant latitudes with 300 points per segment,
% but of course the line along constant longitudes will be straight, so no
% need to approximate with many points.
lat = [linspace(latlim(1),latlim(1),200),linspace(latlim(2),latlim(2),200),latlim(1)];
lon = [linspace(lonlim(1),lonlim(2),200),linspace(lonlim(2),lonlim(1),200),lonlim(1)];
[x,y] = ll2ps(lat,lon,'meridian',meridian);
if plotkm
x = x/1000;
y = y/1000;
end
%% Get initial conditions of the plot:
da = daspect;
da = [1 1 da(3)];
hld = ishold;
hold on
%% Plot the quadrangle:
h = plot(x,y,varargin{:});
%% Put things back the way we found them and clean up:
daspect(da)
if ~hld
hold off
end
if nargout==0
clear h
end
end