image thumbnail
from Conversion of UTM Coordinates to Spherical Coordinates by Gabriel Ruiz
Little GUI allows you convert UTM coordinates to spherical coordinates.

UTMIP(instruccion)
function  [long,lonm,lons,latg,latm,lats,Direction] = UTMIP(instruccion)
% -------------------------------------------------------------------------
% 0. Syntax:
% [long,lonm,lons,latg,latm,lats,Direction] = UTMIP(instruccion)
%
% 1. With this little routine, you can get the transformation
% or the conversion of UTM coordinates to spherical 
% coordinates, You can choose different ellipsoids to execute
% the conversion.
%
% I'm using the Alberto Cotticia and Luciano Saruce's
% equations, these equations appear in  "Bolletino di
% Geodesia e Science Affini", num. 1.
% The different ellipsoids that I got them, you can
% find them on:
% http://www.aec2000.it/geodesy/geodesy.htm
%
% 2. Inputs:
% x, y , utm zone, and hemisphere.
% 
% 3. Outputs:
% Latitude, Longitude and the reference of the Longitude.
%
%  4. Notes:
% It's only necessary to run the function.
% I designed the window in order to display in a screen of
% 1024 x 768.
% This is the "inverse problem" of Spherical coordinates  
% to UTM coordinates. You can also see the routine:
% Conversion of Spherical Coordinates to UTM Coordinates.
% on Matlab Central -File Exchange, ID File: 8043.
%
% 5. Reference:
% http://recursos.gabrielortiz.com/
%
% Author: Gabriel Ruiz Martinez, Civil Engineer (defops@yahoo.com)
% This routine is provided "as is" without warranty of any kind. 
% Please, you don't attribute it.
% If you'll detect any mistake or bug, may you communicate me?
% September 2006
% v1.2.
% Modifications:
% I add the lines 305 and 308.
 %-------------------------------------------------------------------------


   if nargin == 0
                 instruccion = 'iniciar';
   end

   % &&&&& Defining variables which will store the handles as variable global &&&&&
   global xutm yutm zoneutm hemi ListaElips          

    % &&&&&Start the graphical interfase of user &&&&&
    if strcmp(instruccion,'iniciar')
    
                    marcocal = figure('name','Conversion of UTM Coordinates to Spherical Coordinates', 'color' , [0.92549 0.913725 0.847059] , ...
                                                   'menubar' , 'none' , 'units' , 'normalized' , 'position' , [0.24 0.40 0.54 0.24 ] , 'numbertitle' , 'off', 'resize' , 'off');

	                % &&&&& Create the frames &&&&&.
	                      uicontrol(marcocal , 'Style' , 'frame' , 'Units' ,'normalized', 'Position', [ 0.01 0.25 0.98 0.7 ] ); 
	                          uicontrol(marcocal , 'Style' , 'frame' , 'Units' , 'normalized' , 'Position' , [0.01 0.01 0.98 0.2 ]  );
    
                                 % &&&&& Create all the text &&&&&
                                         uicontrol(marcocal, 'Style' , 'Text' , 'String' , 'Spherical Coordinates' , 'Units' , ' Normalized' , 'Position' , [ 0.08 0.92 0.25 0.07] , ...
                                                                       'FontWeight' , 'Bold' , 'ForegroundColor' ,  [0.5 0 0] );
                                             uicontrol(marcocal, 'Style' , 'Text' , 'String' , 'Longitude:' , 'Units' , ' Normalized' , 'Position' , [ 0.08 0.83 0.11 0.07] , ...
                                                                           'FontWeight' , 'Bold', 'ForegroundColor' ,  [0 0 0.48] );
	                                                uicontrol(marcocal, 'Style' ,  'text' ,  'String' , 'Degrees =' , 'Units' , 'normalized' , 'Position' , [ 0.08 0.70 0.12 0.07 ] , ...
                                                                             'ForegroundColor' ,  [0 0 0.48] , 'FontWeight' , 'Bold' );
	                                         uicontrol(marcocal, 'Style' ,  'text' ,  'String' , 'Minutes =' , 'Units' , 'normalized' , 'Position' , [ 0.08 0.57 0.12 0.07 ] , ...
                                                                      'ForegroundColor' ,  [0 0 0.48] , 'FontWeight' , 'Bold' );
                                          uicontrol(marcocal, 'Style' , 'text' ,  'String' , 'Seconds =' , 'Units' , 'normalized' , 'Position' , [ 0.08 0.44 0.12 0.07]  , ...
                                                                  'ForegroundColor' ,  [0 0 0.48] , 'FontWeight' , 'Bold' );
                                  uicontrol(marcocal, 'Style' , 'Text' , 'String' , 'Direction =' , 'Units' , 'normalized' , 'Position' , [ 0.08 0.31 0.12 0.07] , ...
                                                              'ForegroundColor' ,  [0 0 0.48] , 'FontWeight' , 'Bold' );
                             uicontrol(marcocal, 'Style' , 'Text' , 'String' , 'Latitude:' , 'Units' , ' Normalized' , 'Position' , [ 0.35 0.83 0.1 0.07] , ...
                                                           'FontWeight' , 'Bold' , 'ForegroundColor' ,  [0 0 0.48] );
	                     uicontrol(marcocal, 'Style' ,  'text' ,  'String' , 'Degrees =' , 'Units' , 'normalized' , 'Position' , [ 0.35 0.70 0.12 0.07 ] , ...
                                                    'ForegroundColor' ,  [0 0 0.48] , 'FontWeight' , 'Bold' );
	                 uicontrol(marcocal, 'Style' ,  'text' ,  'String' , 'Minutes =' , 'Units' , 'normalized' , 'Position' , [ 0.35 0.57 0.12 0.07 ] , ...
                                                    'ForegroundColor' ,  [0 0 0.48] , 'FontWeight' , 'Bold' );
                        uicontrol(marcocal, 'Style' , 'text' ,  'String' , 'Seconds =' , 'Units' , 'normalized' , 'Position' , [ 0.35 0.44 0.12 0.07] , ...
                                                    'ForegroundColor' ,  [0 0 0.48] , 'FontWeight' , 'Bold' );
                                   uicontrol(marcocal, 'Style' , 'Text' , 'String' ,  'Ellipsoid:' , 'Units' , 'normalized' , 'Position' , [ 0.62 0.8 0.09 0.07] );
                                                uicontrol(marcocal, 'Style' , 'Text' , 'String' , 'Universal Transverse Mercator Coordinates' , 'Units' , ...
                                                                        ' Normalized' , 'Position' , [ 0.08 0.18 0.5 0.06] , 'ForegroundColor' ,  [0.5 0 0] , 'FontWeight' , 'Bold' );                                                                     
                                           uicontrol(marcocal, 'Style' , 'Text' , 'String' , 'X : ' , 'Units' , ' Normalized' , 'Position' , [ 0.02 0.09 0.09 0.06] );
                                    uicontrol(marcocal, 'Style' , 'Text' , 'String' , 'Y : ' , 'Units' , ' Normalized' , 'Position' , [ 0.28 0.09 0.09 0.06] ); 
                        uicontrol(marcocal, 'Style' , 'Text' , 'String' , 'Zone : ' , 'Units' , ' Normalized' , 'Position' , [ 0.57 0.09 0.09 0.06] );
	                 uicontrol(marcocal, 'Style' , 'Text' , 'String' , 'Hemisphere : ' , 'Units' , ' Normalized' , 'Position' , [ 0.78 0.09 0.12 0.06] );
                                                          
    % Create the edit boxes for the coordinates data.
	                                         xutm = uicontrol(marcocal, 'Style' , 'Edit' , 'String' , '435157.59', 'Units' , 'Normalized' , ...
                                                                             'Position' , [ 0.10 0.06 0.15 0.1] ,  'Callback' , 'UTMIP(''calcular'');' );
                        yutm = uicontrol(marcocal, 'Style' , 'Edit' , 'String' , '4815453.64'  , 'Units' , 'Normalized' , ...
                                                                         'Position' , [ 0.37 0.06 0.15 0.1] , 'Callback' , 'UTMIP(''calcular'');' );
                               zoneutm =   uicontrol(marcocal, 'Style' , 'Edit' , 'String' , '30' , 'Units' , 'Normalized' , ...
                                                                        'Position' , [ 0.67 0.06 0.05 0.1] , 'Callback' , 'UTMIP(''calcular'');' ); 
                                       hemi =   uicontrol(marcocal, 'Style' , 'Edit' , 'String' , 'N' , 'Units' , 'Normalized' , ...
                                                                        'Position' , [ 0.92 0.06 0.05 0.1] , 'Callback' , 'UTMIP(''calcular'');' );                             
                                             ListaElips = uicontrol(marcocal , 'Style' , 'listbox' , 'String' , ...
                                                           'Airy 1830|Airy 1849|Airy Modified 1965|Australian National|Average Terrestrial System 1977|Bessel (Namibia 1841)|Bessel (Ethiopia, Indonesia 1841)|Bessel (Japan 1841)|Modified Bessel|Bessel NGO|Bessel RT90|Clarke 1858|Clarke 1858 (AUSLIG)|Clarke 1858-1|Clarke 1866|Clarke Michigan|Clarke 1880|Clarke 1880 ARC50|Clarke 1880 Benoit|Clarke 1880 Benoit|Clarke 1880 IGN|Clarke 1880 Jamaica|Clarke 1880 Merchich|Clarke 1880 Palestine|Clarke 1880 RGS|Clarke 1880 SGA 1922|Everest (India 1830)|Everest (Sabah & Sarawak)|Everest (India 1956)|Everest (W. Malaysia 1969)|Everest (W. Malaysia & Singapure 1948)|Everest (Pakistan)|Everest (Timbalai)|Everest 1967|Fischer 1960|Fischer 1968|Modified Fischer 1966|GEM 10C|GRS67|GRS80|Hayford 1909|Helmert 1906|Hough 1960|IAG 75|Indonesian 1974|International 1909|International 1924|IUGG 67|IUGG 75|Kaula|Krasovsky 1940|Merit 83|Mercury 1960|Modified Mercury 1968|New International 1967|NWL 10D|NWL 9D|OSU86F|OSU91A|Plessis 1817|SGS85|South American 1969|South Asia|Struve (Spain) 1860|Walbeck 1817|War Office|WGS60|WGS66|WGS72|WGS84' , ...
                                                           'Units' , 'normalized', 'Position' ,  [ 0.63 0.30 0.34 0.49 ] , 'BackgroundColor' , [1 1 1]  );
                                                       
	    % Beginning subfunction.
	     UTMIP('calcular');

     % Callback to the event of computing
    elseif strcmp(instruccion,'calcular')
        testing = 0;
            eval( [ 'x = ' get(xutm, 'string') ';' ]  );
                eval( [ 'y = ' get(yutm, 'string') ';' ]  );
                  eval( [ 'zone = ' get(zoneutm, 'string') ';' ]  );
                  
                  hemis = get(hemi, 'string');
                  ListaElip = get(ListaElips, 'value');
                       
% x =  435157.59;  y = 4815453.64;  zone = 30;  hemis = 'N'; ListaElip = 41;     

              if testing == 0     
                  switch ListaElip
                              case {1}
                                       sa = 6377563.396000 ; sb = 6356256.909237;    
                              case {2}
                                       sa = 6377340.189000 ; sb = 6356034.447897;
                              case {3}
                                       sa = 6377340.189000 ; sb = 6356034.447939;
                              case {4}
                                       sa = 6378160.000000 ; sb = 6356774.719195;
                              case {5}
                                       sa = 6378135.000000 ; sb = 6356750.304922;
                              case {6}
                                       sa = 6377483.865000 ; sb = 6356165.382967;         
                              case {7}
                                       sa = 6377397.155000 ; sb = 6356078.962819;
                              case {8}
                                       sa =6377397.155000  ; sb = 6356078.963000;   
                              case {9}
                                       sa = 6377492.018000 ; sb = 6356173.508713;
                              case {10}
                                       sa = 6377492.018000 ; sb = 6356173.508516;
                              case {11}
                                       sa = 6377397.154000 ; sb =6356078.962024;
                              case {12}
                                       sa = 6378294.000000 ; sb = 6356621.237513;
                              case {13}
                                       sa = 6378293.645000 ; sb = 6356617.937649;
                              case {14}
                                       sa = 6378293.639000 ; sb = 6356617.981760 ;
                              case {15}
                                       sa = 6378206.400000 ; sb = 6356583.799999;
                              case {16}
                                       sa = 6378450.047000  ; sb = 6356826.621424;         
                              case {17}
                                       sa = 6378249.136000  ; sb = 6356514.860580;
                              case {18}
                                       sa = 6378249.145000  ; sb = 6356514.966716 ;   
                              case {19}
                                       sa = 6378300.790000  ; sb = 6356566.429659;
                              case {20}
                                       sa = 6378300.790000  ; sb = 6356566.434997;          
                              case {21}
                                       sa = 6378249.200000  ; sb = 6356515.000000;
                              case {22}
                                       sa = 6378249.136000  ; sb = 6356514.957600;
                              case {23}
                                       sa = 6378249.200000  ; sb = 6356514.996942;
                              case {24}
                                       sa = 6378300.790000 ; sb =  6356566.429662;
                              case {25}
                                       sa = 6378249.145000  ; sb = 6356514.869550;
                              case {26}
                                       sa = 6378249.200000  ; sb = 6356514.996942 ;         
                              case {27}
                                       sa = 6377276.345000 ; sb =  6356075.413138;
                              case {28}
                                       sa = 6377298.556000 ; sb =  6356097.550301;   
                              case {29}
                                       sa = 6377301.243000 ; sb =  6356100.228366;
                              case {30}
                                       sa = 6377295.664000 ; sb =  6356094.667913; 
                              case {31}
                                       sa = 6377304.063000 ; sb =  6356103.038991;         
                              case {32}
                                       sa = 6377309.613000 ; sb = 6356108.570542;
                              case {33}
                                       sa = 6377298.561000 ; sb = 6356097.555284; 
                              case {34}
                                       sa = 6377298.556000 ; sb = 6356097.550299;
                              case {35}
                                       sa = 6378166.000000 ; sb = 6356784.283607;
                              case {36}
                                       sa = 6378150.000000 ; sb = 6356768.337244;
                              case {37}
                                       sa = 6378155.000000 ; sb = 6356773.320483;
                              case {38}
                                       sa = 6378137.000000 ; sb = 6356752.313990;
                              case {39}
                                       sa = 6378160.000000 ; sb = 6356774.516091;
                              case {40}
                                       sa = 6378137.000000 ; sb = 6356752.314140;
                              case {41}
                                       sa = 6378388.000000 ; sb = 6356911.946128;
                              case {42}
                                       sa = 6378200.000000 ; sb = 6356818.169628;         
                              case {43}
                                       sa = 6378270.000000 ; sb = 6356794.343434;
                              case {44}
                                       sa = 6378140.000000 ; sb = 6356755.304075;   
                              case {45}
                                       sa = 6378160.000000 ; sb = 6356774.508046;
                              case {46}
                                       sa = 6378388.000000 ; sb = 6356911.949128;
                              case {47}
                                       sa = 6378388.000000 ; sb =  6356911.949128;
                              case {48}
                                       sa = 6378160.000000 ; sb = 6356774.719195;
                              case {49}
                                       sa = 6378140.000000 ; sb = 6356755.288158;
                              case {50}
                                       sa = 6378165.000000 ; sb = 6356344.387615;
                              case {51}
                                       sa = 6378245.000000 ; sb = 6356863.018773;
                              case {52}
                                       sa = 6378137.000000 ; sb = 6356752.298216;         
                              case {53}
                                       sa = 6378166.000000 ; sb = 6356748.283666;
                              case {54}
                                       sa = 6378150.000000 ; sb = 6356768.337303;   
                              case {55}
                                       sa = 6378157.500000 ; sb = 6356772.227578;
                              case {56}
                                       sa = 6378135.000000 ; sb = 6356750.520016;          
                              case {57}
                                       sa = 6378145.000000 ; sb = 6356759.769489;
                              case {58}
                                       sa = 6378136.200000 ; sb = 6356751.516672;
                              case {59}
                                       sa = 6378136.300000 ; sb = 6356751.616337;
                              case {60}
                                       sa = 6376523.000000 ; sb = 6355862.933256;
                              case {61}
                                       sa = 6378136.000000 ; sb = 6356774.719201;
                              case {62}
                                       sa = 6378160.000000 ; sb = 6356774.719195;         
                              case {63}
                                       sa = 6378155.000000 ; sb = 6356773.320497;
                              case {64}
                                       sa = 6378298.300000 ; sb = 6356657.142670;   
                              case {65}
                                       sa = 6376896.000000 ; sb = 6355834.846687;
                              case {66}
                                       sa = 6378300.583000 ; sb = 6356752.270220; 
                              case {67}
                                       sa = 6378165.000000 ; sb = 6356783.286969;         
                              case {68}
                                       sa = 6378145.000000 ; sb = 6356759.769489;
                              case {69}
                                       sa = 6378135.000000 ; sb = 6356750.520016;   
                              case {70}
                                       sa = 6378137.000000 ; sb = 6356752.314245;
                          end
                          
                    e = ( ( ( sa ^ 2 ) - ( sb ^ 2 ) ) ^ 0.5 ) / sa;
                        e2 = ( ( ( sa ^ 2 ) - ( sb ^ 2 ) ) ^ 0.5 ) / sb;
                              e2cuadrada = e2 ^ 2;
                                   c = ( sa ^ 2 ) / sb;
                                       alpha = ( sa - sb ) / sa;             %f
                                             ablandamiento = 1 / alpha;   % 1/f

                                             X = x - 500000;
                                             
                                        if hemis == 'S' || hemis == 's'
                                            Y = y - 10000000;
                                        else
                                            Y = y;
                                        end
                                        
                                     S = ( ( zone * 6 ) - 183 ); 
                                     lat =  Y / ( 6366197.724 * 0.9996 );                                    
                                     v = ( c / ( ( 1 + ( e2cuadrada * ( cos(lat) ) ^ 2 ) ) ) ^ 0.5 ) * 0.9996;
                                     a = X / v;
                                     a1 = sin( 2 * lat );
                                     a2 = a1 * ( cos(lat) ) ^ 2;
                                     j2 = lat + ( a1 / 2 );
                                     j4 = ( ( 3 * j2 ) + a2 ) / 4;
                                     j6 = ( ( 5 * j4 ) + ( a2 * ( cos(lat) ) ^ 2) ) / 3;
                                     alfa = ( 3 / 4 ) * e2cuadrada;
                                     beta = ( 5 / 3 ) * alfa ^ 2;
                                     gama = ( 35 / 27 ) * alfa ^ 3;
                                     Bm = 0.9996 * c * ( lat - alfa * j2 + beta * j4 - gama * j6 );
                                     b = ( Y - Bm ) / v;
                                     Epsi = ( ( e2cuadrada * a^ 2 ) / 2 ) * ( cos(lat) )^ 2;
                                     Eps = a * ( 1 - ( Epsi / 3 ) );
                                     nab = ( b * ( 1 - Epsi ) ) + lat;
                                     senoheps = ( exp(Eps) - exp(-Eps) ) / 2;
                                     Delt = atan(senoheps / (cos(nab) ) );
                                     TaO = atan(cos(Delt) * tan(nab));
                                     longitude = (Delt *(180 / pi ) ) + S;
                                     latitude = ( lat + ( 1 + e2cuadrada* (cos(lat)^ 2) - ( 3 / 2 ) * e2cuadrada * sin(lat) * cos(lat) * ( TaO - lat ) ) * ( TaO - lat ) ) * ...
                                                      (180 / pi);
                                     
                                     if sign(longitude) == -1
                                          Direction = 'W';
                                          longi = longitude * -1; 
                                     else
                                           Direction = 'E';
                                           longi = longitude;
                                     end
                                    
                                          [latg, latm, lats] =dms2mat(deg2dms(latitude));
                                          [long, lonm, lons] =dms2mat(deg2dms(longi));
                                
                                   longG = num2str(long);
                                   longM = num2str(lonm);
                                   longS = num2str(lons);
                                   latG = num2str(latg);
                                   latM = num2str(latm);
                                   latS = num2str(lats);
                           
                        uicontrol(gcf, 'Style' , 'text' ,  'BackGroundColor' , [0.92549 0.913725 0.847059] , ...
                                                                     'String' , longG  , 'Units' , 'Normalized' , 'Position' , [ 0.20 0.67 0.1 0.1 ] , ... 
                                                                     'FontWeight' , 'bold', 'HorizontalAlignment' , 'center' , 'ForegroundColor' , [0 0 0.48] );
                        uicontrol(gcf, 'Style' , 'text' ,  'BackGroundColor' , [0.92549 0.913725 0.847059] , ...
                                                                     'String' , longM  , 'Units' , 'Normalized' , 'Position' , [ 0.20 0.54 0.1 0.1 ] , ... 
                                                                     'FontWeight' , 'bold', 'HorizontalAlignment' , 'center' , 'ForegroundColor' , [0 0 0.48] );
                        uicontrol(gcf, 'Style' , 'text' ,  'BackGroundColor' , [0.92549 0.913725 0.847059] , ...
                                                                     'String' , longS  , 'Units' , 'Normalized' , 'Position' , [ 0.20 0.41 0.1 0.1 ] , ... 
                                                                     'FontWeight' , 'bold', 'HorizontalAlignment' , 'center' , 'ForegroundColor' , [0 0 0.48] );
                        uicontrol(gcf, 'Style' , 'text' ,  'BackGroundColor' , [0.92549 0.913725 0.847059] , ...
                                                                     'String' , Direction  , 'Units' , 'Normalized' , 'Position' , [ 0.20 0.28 0.05 0.1 ] , ... 
                                                                     'FontWeight' , 'bold', 'HorizontalAlignment' , 'center' , 'ForegroundColor' , [0 0 0.48] );
                        uicontrol(gcf, 'Style' , 'text' ,  'BackGroundColor' , [0.92549 0.913725 0.847059] , ...
                                                                     'String' , latG  , 'Units' , 'Normalized' , 'Position' ,  [ 0.47 0.67 0.1 0.1 ] , ... 
                                                                     'FontWeight' , 'bold', 'HorizontalAlignment' , 'center' , 'ForegroundColor' , [0 0 0.48] );
                        uicontrol(gcf, 'Style' , 'text' ,  'BackGroundColor' , [0.92549 0.913725 0.847059] , ...
                                                                     'String' , latM  , 'Units' , 'Normalized' , 'Position' ,  [ 0.47 0.54 0.1 0.1 ] , ... 
                                                                     'FontWeight' , 'bold', 'HorizontalAlignment' , 'center' , 'ForegroundColor' , [0 0 0.48] );                                                                              
                        uicontrol(gcf, 'Style' , 'text' ,  'BackGroundColor' , [0.92549 0.913725 0.847059] , ...
                                                                     'String' , latS  , 'Units' , 'Normalized' , 'Position' , [ 0.47 0.41 0.1 0.1 ]  , ... 
                                                                     'FontWeight' , 'bold', 'HorizontalAlignment' , 'center' , 'ForegroundColor' , [0 0 0.48] ); 

               end
 end % END command_str comparison checks.

Contact us at files@mathworks.com