Changeset 18478
- Timestamp:
- 09/02/14 12:05:17 (11 years ago)
- Location:
- issm/trunk-jpl/src/m/coordsystems
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/coordsystems/ll2utm.m
r18460 r18478 1 function [x,y,f]=ll2utm( lat,lon,datum)1 function [x,y,f]=ll2utm(varargin) 2 2 %LL2UTM Lat/Lon to UTM coordinates precise conversion. 3 % 3 % [X,Y]=LL2UTM2(LAT,LON) or LL2UTM([LAT,LON]) converts coordinates 4 4 % LAT,LON (in degrees) to UTM X and Y (in meters). Default datum is WGS84. 5 5 % … … 7 7 % have the same size as inputs. 8 8 % 9 % LL2UTM( LAT,LON,DATUM) uses specific DATUM for conversion. DATUM can be10 % a string in the following list:9 % LL2UTM(...,DATUM) uses specific DATUM for conversion. DATUM can be one 10 % of the following char strings: 11 11 % 'wgs84': World Geodetic System 1984 (default) 12 12 % 'nad27': North American Datum 1927 … … 18 18 % meters) and F is flattening of the user-defined ellipsoid. 19 19 % 20 % [X,Y,ZONE]=LL2UTM(...) returns also computed UTM ZONE (negative value 21 % stands for southern hemisphere points). 22 % 23 % 24 % XY = LL2UTM(...) or without any output argument returns a 2-column 20 % LL2UTM(...,ZONE) forces the UTM ZONE (scalar integer) instead of 21 % automatic set. 22 % 23 % [X,Y,ZONE]=LL2UTM(...) returns also the computed UTM ZONE (negative 24 % value for southern hemisphere points). 25 % 26 % 27 % XY=LL2UTM(...) or without any output argument returns a 2-column 25 28 % matrix [X,Y]. 26 29 % 27 % Not ice:30 % Note: 28 31 % - LL2UTM does not perform cross-datum conversion. 29 32 % - precision is near a millimeter. … … 34 37 % Notes Techniques NT/G 76, janvier 1995. 35 38 % 36 % Author: Francois Beauducel, <beauducel@ipgp.fr> 37 % Created: 2003-12-02 38 % Updated: 2014-04-20 39 % Acknowledgments: Mathieu. 40 % 41 % 42 % Author: Francois Beauducel, <beauducel@ipgp.fr> 43 % Created: 2003-12-02 44 % Updated: 2014-08-24 39 45 40 46 … … 74 80 ]; 75 81 76 if nargin == 1 77 if size(lat,2) ~= 2 78 error('Single input argument must be a 2-column matrix [LAT,LON].') 79 end 80 lon = lat(:,2); 81 lat = lat(:,1); 82 end 83 82 % constants 83 D0 = 180/pi; % conversion rad to deg 84 K0 = 0.9996; % UTM scale factor 85 X0 = 500000; % UTM false East (m) 86 87 % defaults 88 datum = 'wgs84'; 89 zone = []; 90 84 91 if nargin < 1 85 92 error('Not enough input arguments.') 86 93 end 87 94 95 if isnumeric(varargin{1}) & size(varargin{1},2) == 2 96 lat = varargin{1}(:,1); 97 lon = varargin{1}(:,2); 98 v = 1; 99 elseif nargin > 1 & isnumeric(varargin{2}) 100 lat = varargin{1}; 101 lon = varargin{2}; 102 v = 2; 103 else 104 error('Single input argument must be a 2-column matrix [LAT,LON].') 105 end 106 88 107 if all([numel(lat),numel(lon)] > 1) && any(size(lat) ~= size(lon)) 89 108 error('LAT and LON must be the same size or scalars.') 90 109 end 91 110 92 if nargin < 3 93 datum = 'wgs84'; 111 for n = (v+1):nargin 112 % LL2UTM(...,DATUM) 113 if ischar(varargin{n}) | (isnumeric(varargin{n}) & numel(varargin{n})==2) 114 datum = varargin{n}; 115 % LL2UTM(...,ZONE) 116 elseif isnumeric(varargin{n}) & isscalar(varargin{n}) 117 zone = round(varargin{n}); 118 else 119 error('Unknown argument #%d. See documentation.',n) 120 end 94 121 end 95 122 96 123 if ischar(datum) 124 % LL2UTM(...,DATUM) with DATUM as char 97 125 if ~any(strcmpi(datum,datums(:,1))) 98 126 error('Unkown DATUM name "%s"',datum); … … 102 130 F1 = datums{k,3}; 103 131 else 104 if numel(datum) ~= 2 105 error('User defined DATUM must be a vector [A,F].'); 106 end 132 % LL2UTM(...,DATUM) with DATUM as [A,F] user-defined 107 133 A1 = datum(1); 108 134 F1 = datum(2); 109 135 end 110 136 111 % constants 112 D0 = 180/pi; % conversion rad to deg 113 114 K0 = 0.9996; % UTM scale factor 115 X0 = 500000; % UTM false East (m) 137 p1 = lat/D0; % Phi = Latitude (rad) 138 l1 = lon/D0; % Lambda = Longitude (rad) 139 140 % UTM zone automatic setting 141 if isempty(zone) 142 F0 = round((l1*D0 + 183)/6); 143 else 144 F0 = zone; 145 end 116 146 117 147 B1 = A1*(1 - 1/F1); 118 148 E1 = sqrt((A1*A1 - B1*B1)/(A1*A1)); 119 120 p1 = lat/D0; % Phi = Latitude (rad)121 l1 = lon/D0; % Lambda = Longitude (rad)122 F0 = round((l1*D0 + 183)/6); % UTM zone123 149 P0 = 0/D0; 124 L0 = (6*F0 - 183)/D0; 125 Y0 = 1e7*(p1 < 0); 150 L0 = (6*F0 - 183)/D0; % UTM origin longitude (rad) 151 Y0 = 1e7*(p1 < 0); % UTM false northern (m) 126 152 N = K0*A1; 127 153 -
issm/trunk-jpl/src/m/coordsystems/utm2ll.m
r18460 r18478 1 1 function [lat,lon]=utm2ll(x,y,f,datum,varargin) 2 2 %UTM2LL UTM to Lat/Lon coordinates precise conversion. 3 % 3 % [LAT,LON]=UTM2LL(X,Y,ZONE) converts UTM coordinates X,Y (in meters) 4 4 % defined in the UTM ZONE (integer) to latitude LAT and longitude LON 5 5 % (in degrees). Default datum is WGS84. … … 30 30 % Notes Techniques NT/G 76, janvier 1995. 31 31 % 32 % Author: Francois Beauducel, <beauducel@ipgp.fr> 33 % Created: 2001-08-23 34 % Updated: 2014-04-20 32 % Author: Francois Beauducel, <beauducel@ipgp.fr> 33 % Created: 2001-08-23 34 % Updated: 2014-04-20 35 35 36 36 37 % Copyright (c) 2001-2014, François Beauducel, covered by BSD License. … … 105 106 eps = 1e-11; % minimum residue for latitude computation 106 107 107 K0 = 0.9996; 108 X0 = 500000; 109 Y0 = 1e7*(f < 0); 110 P0 = 0; 111 L0 = (6*abs(f) - 183)/D0; 108 K0 = 0.9996; % UTM scale factor 109 X0 = 500000; % UTM false East (m) 110 Y0 = 1e7*(f < 0); % UTM false North (m) 111 P0 = 0; % UTM origin latitude (rad) 112 L0 = (6*abs(f) - 183)/D0; % UTM origin longitude (rad) 112 113 E1 = sqrt((A1^2 - (A1*(1 - 1/F1))^2)/A1^2); % ellpsoid excentricity 113 114 N = K0*A1;
Note:
See TracChangeset
for help on using the changeset viewer.