Home > utilities > m_ll2ll.m

m_ll2ll

PURPOSE ^

M_ll2LL Converts LON,LAT to long,lat coordinates using the current projection

SYNOPSIS ^

function [X,Y]=m_ll2ll(lon1,lat1, zone, hemisphere,ellipsoid);

DESCRIPTION ^

 M_ll2LL Converts LON,LAT to long,lat coordinates using the current projection
 and a provided one. I really only want to do UTM to LATLON so keep it
 simple (this is provided to use m_map instead of proj.exe )

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [X,Y]=m_ll2ll(lon1,lat1, zone, hemisphere,ellipsoid);
0002 % M_ll2LL Converts LON,LAT to long,lat coordinates using the current projection
0003 % and a provided one. I really only want to do UTM to LATLON so keep it
0004 % simple (this is provided to use m_map instead of proj.exe )
0005 global MAP_PROJECTION MAP_VAR_LIST
0006 
0007 % define a structure of various ellipsoids. each has a name, and
0008 % a vector consisting of equatorial radius and flattening. the first
0009 % two are somewhat special cases.
0010 
0011 MAP_ELLIP = struct ( 'normal', [1.0, 0], ...
0012     'sphere', [6370997.0, 0], ...
0013     'grs80' , [6378137.0, 1/298.257], ...
0014     'grs67' , [6378160.0, 1/247.247], ...
0015     'wgs84' , [6378137.0, 1/298.257], ...
0016     'wgs72' , [6378135.0, 1/298.260], ...
0017     'wgs66' , [6378145.0, 1/298.250], ...
0018     'wgs60' , [6378165.0, 1/298.300], ...
0019     'clrk66', [6378206.4, 1/294.980], ...
0020     'clrk80', [6378249.1, 1/293.466], ...
0021     'intl24', [6378388.0, 1/297.000], ...
0022     'intl67', [6378157.5, 1/298.250]);
0023 
0024 MAP_VAR_LIST.zone
0025 MAP_VAR_LIST.hemisphere
0026 MAP_VAR_LIST.ellipsoid
0027 getfield(MAP_ELLIP,MAP_VAR_LIST.ellipsoid)
0028 %     [X,Y] = mu_ll2utm(lat1,lon1,MAP_VAR_LIST.zone,MAP_VAR_LIST.hemisphere, ...
0029 %     getfield(MAP_ELLIP,MAP_VAR_LIST.ellipsoid));
0030     [Y,X] = mu_utm2ll(lon1, lat1, MAP_VAR_LIST.zone, ...
0031     MAP_VAR_LIST.hemisphere, getfield(MAP_ELLIP,MAP_VAR_LIST.ellipsoid));
0032 
0033 return
0034 function [x,y] = mu_ll2utm (lat,lon, zone, hemisphere,ellipsoid)
0035 %mu_ll2utm        Convert geodetic lat,lon to X/Y UTM coordinates
0036 %
0037 %    [x,y] = mu_ll2utm (lat, lon, zone, hemisphere,ellipsoid)
0038 %
0039 %    input is latitude and longitude vectors, zone number,
0040 %        hemisphere(N=0,S=1), ellipsoid info [eq-rad, flat]
0041 %    output is X/Y vectors
0042 %
0043 %    see also    mu_utm2ll, utmzone
0044 
0045 
0046 % some general constants
0047 
0048 DEG2RADS    = 0.01745329252;
0049 RADIUS      = ellipsoid(1);
0050 FLAT        = ellipsoid(2);
0051 K_NOT       = 0.9996;
0052 FALSE_EAST  = 500000;
0053 FALSE_NORTH = 10000000;
0054 
0055 % check for valid numbers
0056 
0057 if (max(abs(lat)) > 90)
0058   error('latitude values exceed 89 degree');
0059   return;
0060 end
0061 
0062 if ((zone < 1) | (zone > 60))
0063   error ('utm zones only valid from 1 to 60');
0064   return;
0065 end
0066 
0067 % compute some geodetic parameters
0068 
0069 lambda_not  = ((-180 + zone*6) - 3) * DEG2RADS;
0070 
0071 e2  = 2*FLAT - FLAT*FLAT;
0072 e4  = e2 * e2;
0073 e6  = e4 * e2;
0074 ep2 = e2/(1-e2);
0075 
0076 % some other constants, vectors
0077 
0078 lat = lat * DEG2RADS;
0079 lon = lon * DEG2RADS;
0080 
0081 sinL = sin(lat);
0082 tanL = tan(lat);
0083 cosL = cos(lat);
0084 
0085 T = tanL.*tanL;
0086 C = ep2 * (cosL.*cosL);
0087 A = (lon - lambda_not).*cosL;
0088 A2 = A.*A;
0089 A4 = A2.*A2;
0090 S = sinL.*sinL;
0091 
0092 % solve for N
0093 
0094 N = RADIUS ./ (sqrt (1-e2*S));
0095 
0096 % solve for M
0097 
0098 M0 = 1 - e2*0.25 - e4*0.046875 - e6*0.01953125;
0099 M1 = e2*0.375 + e4*0.09375 + e6*0.043945313;
0100 M2 = e4*0.05859375 + e6*0.043945313;
0101 M3 = e6*0.011393229;
0102 M = RADIUS.*(M0.*lat - M1.*sin(2*lat) + M2.*sin(4*lat) - M3.*sin(6*lat));
0103 
0104 % solve for x
0105 
0106 X0 = A4.*A/120;
0107 X1 = 5 - 18*T + T.*T + 72*C - 58*ep2;
0108 X2 = A2.*A/6;
0109 X3 = 1 - T + C;
0110 x = N.*(A + X3.*X2 + X1.* X0);
0111 
0112 % solve for y
0113 
0114 Y0 = 61 - 58*T + T.*T + 600*C - 330*ep2;
0115 Y1 = 5 - T + 9*C + 4*C.*C;
0116 
0117 y = M + N.*tanL.*(A2/2 + Y1.*A4/24 + Y0.*A4.*A2/720);
0118 
0119 
0120 % finally, do the scaling and false thing. if using a unit-normal radius,
0121 % we don't bother.
0122 
0123 x = x*K_NOT + (RADIUS>1) * FALSE_EAST;
0124 
0125 y = y*K_NOT;
0126 if (hemisphere)
0127   y = y + (RADIUS>1) * FALSE_NORTH;
0128 end
0129 
0130 return
0131 
0132 
0133 
0134 %-------------------------------------------------------------------
0135 
0136 function [lat,lon] = mu_utm2ll (x,y, zone, hemisphere,ellipsoid)
0137 %mu_utm2ll        Convert X/Y UTM coordinates to geodetic lat,lon
0138 %
0139 %    [lat,lon] = mu_utm2ll (x,y, zone, hemisphere,ellipsoid)
0140 %
0141 %    input is X/Y vectors, zone number, hemisphere(N=0,S=1),
0142 %        ellipsoid info [eq-rad, flat]
0143 %    output is lat/lon vectors
0144 %
0145 %    see also    mu_ll2utm, utmzone
0146 
0147 
0148 % some general constants
0149 
0150 DEG2RADS    = 0.01745329252;
0151 RADIUS      = ellipsoid(1);
0152 FLAT        = ellipsoid(2);
0153 K_NOT       = 0.9996;
0154 FALSE_EAST  = 500000;
0155 FALSE_NORTH = 10000000;
0156 
0157 if ((zone < 1) | (zone > 60))
0158   error ('utm zones only valid from 1 to 60');
0159   return;
0160 end
0161 
0162 % compute some geodetic parameters
0163 
0164 e2  = 2*FLAT - FLAT*FLAT;
0165 e4  = e2 * e2;
0166 e6  = e4 * e2;
0167 eps = e2 / (1-e2);
0168 em1 = sqrt(1-e2);
0169 e1  = (1-em1)/(1+em1);
0170 e12 = e1*e1;
0171 
0172 lambda_not  = ((-180 + zone*6) - 3) * DEG2RADS;
0173 
0174 % remove the false things
0175 
0176 x = x - (RADIUS>1)*FALSE_EAST;
0177 if (hemisphere)
0178   y = y - (RADIUS>1)*FALSE_NORTH;
0179 end
0180 
0181 % compute the footpoint latitude
0182 
0183 M = y/K_NOT;
0184 mu = M/(RADIUS * (1 - 0.25*e2 - 0.046875*e4 - 0.01953125*e6));
0185 foot = mu + (1.5*e1 - 0.84375*e12*e1)*sin(2*mu) ...
0186     + (1.3125*e12 - 1.71875*e12*e12)*sin(4*mu) ...
0187     + (1.57291666667*e12*e1)*sin(6*mu) ...
0188     + (2.142578125*e12*e12)*sin(8*mu);
0189 
0190 % some other terms
0191 
0192 sinF = sin(foot);
0193 cosF = cos(foot);
0194 tanF = tan(foot);
0195 
0196 N = RADIUS ./ sqrt(1-e2*(sinF.*sinF));
0197 T = tanF.*tanF;
0198 T2 = T.*T;
0199 C = eps * cosF.*cosF;
0200 C2 = C.*C;
0201 denom = sqrt(1-e2*(sinF.*sinF));
0202 R = RADIUS * em1*em1 ./ (denom.*denom.*denom);
0203 D = x./(N*K_NOT);
0204 D2 = D.*D;
0205 D4 = D2.*D2;
0206 
0207 % can now compute the lat and lon
0208 
0209 lat = foot - (N.*tanF./R) .* (0.5*D2 - (5 + 3*T + 10*C - 4*C2 - 9*eps).*D4/24 ...
0210     + (61 + 90*T + 298*C + 45*T2 - 252*eps - 3*C2) .* D4 .* D2/720);
0211 
0212 lon = lambda_not + (D - (1 + 2*T +C).*D2.*D/6 + ...
0213     (5 - 2*C + 28*T - 3*C2 + 8*eps + 24*T2).*D4.*D./120)./cosF;
0214 
0215 
0216 % convert back to degrees;
0217 
0218 lat=lat/DEG2RADS;
0219 lon=lon/DEG2RADS;
0220 
0221 return

Generated on Wed 20-Feb-2019 16:06:01 by m2html © 2005