Changeset 27627
- Timestamp:
- 03/01/23 12:03:43 (2 years ago)
- Location:
- issm/trunk-jpl/src/m/coordsystems
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified issm/trunk-jpl/src/m/coordsystems/ll2utm.m ¶
r18478 r27627 18 18 % meters) and F is flattening of the user-defined ellipsoid. 19 19 % 20 % LL2UTM(...,ZONE) forces the UTM ZONE (scalar integer ) instead of21 % 20 % LL2UTM(...,ZONE) forces the UTM ZONE (scalar integer or same size as 21 % LAT and LON) instead of automatic set. 22 22 % 23 23 % [X,Y,ZONE]=LL2UTM(...) returns also the computed UTM ZONE (negative … … 37 37 % Notes Techniques NT/G 76, janvier 1995. 38 38 % 39 % Acknowledgments: Mathieu .39 % Acknowledgments: Mathieu, Frederic Christen. 40 40 % 41 41 % 42 42 % Author: Francois Beauducel, <beauducel@ipgp.fr> 43 43 % Created: 2003-12-02 44 % Updated: 201 4-08-2445 46 47 % Copyright (c) 2001-201 4, François Beauducel, covered by BSD License.44 % Updated: 2019-05-29 45 46 47 % Copyright (c) 2001-2019, François Beauducel, covered by BSD License. 48 48 % All rights reserved. 49 49 % … … 93 93 end 94 94 95 if isnumeric(varargin{1}) & size(varargin{1},2) == 2 95 if nargin > 1 && isnumeric(varargin{1}) && isnumeric(varargin{2}) ... 96 && (all(size(varargin{1})==size(varargin{2})) ... 97 || isscalar(varargin(1)) || isscalar(varargin{2})) 98 lat = varargin{1}; 99 lon = varargin{2}; 100 v = 2; 101 elseif isnumeric(varargin{1}) && size(varargin{1},2) == 2 96 102 lat = varargin{1}(:,1); 97 103 lon = varargin{1}(:,2); 98 104 v = 1; 99 elseif nargin > 1 & isnumeric(varargin{2})100 lat = varargin{1};101 lon = varargin{2};102 v = 2;103 105 else 104 106 error('Single input argument must be a 2-column matrix [LAT,LON].') … … 109 111 end 110 112 113 if any(abs(lat)>90) 114 error('LAT absolute values must be lower than 90.') 115 end 116 117 % checks for DATUM and/or ZONE syntax 118 % NOTE: the following strategy works in any case except if ZONE argument 119 % has a size of 1x2 (in that case it will be interpreted as a DATUM). To 120 % force the ZONE syntax with 2 elements, just use ZONE(:) to make a colum 121 % vector of 2x1. 111 122 for n = (v+1):nargin 112 123 % LL2UTM(...,DATUM) 113 if ischar(varargin{n}) | (isnumeric(varargin{n}) & numel(varargin{n})==2) 124 if ischar(varargin{n}) || (isnumeric(varargin{n}) ... 125 && all(size(varargin{n})==[1,2])) 114 126 datum = varargin{n}; 115 127 % LL2UTM(...,ZONE) 116 elseif isnumeric(varargin{n}) & isscalar(varargin{n}) 117 zone = round(varargin{n}); 128 elseif isnumeric(varargin{n}) && (isscalar(varargin{n}) ... 129 || (isscalar(lat) || all(size(varargin{n})==size(lat))) ... 130 && (isscalar(lon) || all(size(varargin{n})==size(lon)))) 131 zone = round(varargin{n}); 118 132 else 119 133 error('Unknown argument #%d. See documentation.',n) … … 142 156 F0 = round((l1*D0 + 183)/6); 143 157 else 144 F0 = zone;158 F0 = abs(zone); 145 159 end 146 160 … … 148 162 E1 = sqrt((A1*A1 - B1*B1)/(A1*A1)); 149 163 P0 = 0/D0; 150 L0 = (6*F0 - 183)/D0; 164 L0 = (6*F0 - 183)/D0; % UTM origin longitude (rad) 151 165 Y0 = 1e7*(p1 < 0); % UTM false northern (m) 152 166 N = K0*A1; … … 166 180 % same size as x/y in case of crossed zones 167 181 if nargout > 2 168 fu = unique(F0.*sign(lat)); 182 f = F0.*sign(lat); 183 fu = unique(f); 169 184 if isscalar(fu) 170 185 f = fu; 171 else172 f = F0;173 186 end 174 187 end -
TabularUnified issm/trunk-jpl/src/m/coordsystems/utm2ll.m ¶
r18478 r27627 5 5 % (in degrees). Default datum is WGS84. 6 6 % 7 % X and Ycan be scalars, vectors or matrix. Outputs LAT and LON will7 % X, Y and F can be scalars, vectors or matrix. Outputs LAT and LON will 8 8 % have the same size as inputs. 9 9 % … … 32 32 % Author: Francois Beauducel, <beauducel@ipgp.fr> 33 33 % Created: 2001-08-23 34 % Updated: 2014-04-20 35 36 37 % Copyright (c) 2001-2014, François Beauducel, covered by BSD License. 34 % Updated: 2019-05-29 35 36 % Revision history: 37 % 38 % [2019-05-29] 39 % - fix an issue when X or Y are matrices. 40 41 % Copyright (c) 2001-2019, François Beauducel, covered by BSD License. 38 42 % All rights reserved. 39 43 % … … 74 78 end 75 79 76 if all([numel(x),numel(y)] > 1) && any(size(x) ~= size(y)) 77 error('X and Y must be the same size or scalars.') 78 end 79 80 if ~isnumeric(f) || ~isscalar(f) || f ~= round(f) 81 error('ZONE must be a scalar integer.') 80 % checks if input arguments have compatible sizes using unique(complex) 81 sz = [size(x);size(y);size(f)]; 82 sz = complex(sz(:,1),sz(:,2)); 83 if length(unique(sz(sz~=complex(1,1)))) > 1 84 error('X, Y and ZONE must be scalar or vector/matrix of the same size.') 85 end 86 87 if ~isnumeric(f) || any(f ~= round(f)) 88 error('ZONE must be integer value.') 82 89 end 83 90 … … 101 108 end 102 109 110 % calculations are made on column vectors 111 x = x(:); 112 y = y(:); 113 f = f(:); 114 103 115 % constants 104 116 D0 = 180/pi; % conversion rad to deg … … 133 145 p0 = NaN; 134 146 n = 0; 135 while any(isnan(p0) | abs(p - p0) > eps) & n < maxiter147 while any(isnan(p0) | abs(p - p0) > eps) && n < maxiter 136 148 p0 = p; 137 149 es = E1*sin(p0); … … 141 153 142 154 if nargout < 2 143 lat = D0*[p (:),l(:)];155 lat = D0*[p,l]; 144 156 else 145 lat = p*D0; 146 lon = l*D0; 157 % reshapes vectors to x/y/f original size 158 sz = max([size(x);size(y);size(f)]); 159 lat = reshape(p*D0,sz); 160 lon = reshape(l*D0,sz); 147 161 end 148 162
Note:
See TracChangeset
for help on using the changeset viewer.