En este articulo veremos como crear funciones específicas para obtener las Coordenadas Geográficas a partir de las Coordenadas UTM.
Esto lograremos insertando código Javascript en la hoja mediante la interfaz Apps Script (Google Apps Script – GAS)
Ver instrucciones en el vídeo.
Codigo a insertar en la interfaz GAS del archivo:
function result(y) { //var y ; var alpha_ ; var beta_ ; var gamma_ ; var delta_ ; var epsilon_ ; var n ; var sm_a ; var sm_b ; //'var y ; var result ; sm_a = 6378137; sm_b = 6356752.314; //' /* Precalculate n (Eq. 10.18) */ n = (sm_a - sm_b) / (sm_a + sm_b); // '/* Precalculate alpha_ (Eq. 10.22) */// // //'/* (Same as alpha in Eq. 10.17) */ alpha_ = ((sm_a + sm_b) / 2) * (1 + (n ** 2) / 4) + (n ** 4) / 64; // '/* Precalculate y_ (Eq. 10.23) */ var y_ = y / alpha_; // '/* Precalculate beta_ (Eq. 10.22) */ beta_ = (3 * n / 2) + (-27 * (n ** 3) / 32) + (269 * (n ** 5) / 512); // ' /* Precalculate gamma_ (Eq. 10.22) */ gamma_ = (21 * (n ** 2) / 16) + (-55 * (n ** 4) / 32); // ' /* Precalculate delta_ (Eq. 10.22) */ delta_ = (151 * (n ** 3) / 96) + (-417 * (n ** 5) / 128); // '/* Precalculate epsilon_ (Eq. 10.22) */ epsilon_ = (1097 * (n ** 4) / 512); // '/* Now calculate the sum of the series (Eq. 10.21) */ result = y_ + (beta_ * Math.sin(2 * y_)) + (gamma_ * Math.sin(4 * y_)) + (delta_ * Math.sin(6 * y_)) + (epsilon_ * Math.sin(8 * y_)); return result; // ' //echo $result; }
function x_geo(x, y) { var zone ; var lamba0 ; var phif ; var Nf ; var Nfpow ; var nuf2 ; var ep2 ; var tf ; var tf2 ; var tf4 ; var cf ; var x1frac ; var x2frac ; var x3frac ; var x4frac ; var x5frac ; var x6frac ; var x7frac ; var x8frac ; var x2poly ; var x3poly ; var x4poly ; var x5poly ; var x6poly ; var x7poly ; var x8poly ; var philambda ; var philambda1 ; var sm_a ; var sm_b ; // ' var x_geo ; var UTMScaleFactor = 0.9996; var zone = 21; x = x - 500000; x = x / UTMScaleFactor; // ' /* If in southern hemisphere, adjust y accordingly. */ // ' /* if ($southhemi) */ y = y - 10000000; y = y / UTMScaleFactor; // ' // $cmeridian = UTMCentralMeridian ($zone); // '//$lambda0 = ((-183.0 + ($zone * 6.0))/180) * 3.14159265358979 ; lambda0 = ((-183 + (zone * 6)) / 180) * 3.141592654; sm_a = 6378137; sm_b = 6356752.314; // '/* Get the value of phif, the footpoint latitude. */ phif = result(y); // '/* Precalculate ep2 */ ep2 = (sm_a ** 2 - sm_b ** 2) / (sm_b ** 2); // '/* Precalculate cos (phif) */ cf = Math.cos(phif); // '/* Precalculate nuf2 */ nuf2 = ep2 * (cf ** 2) // '/* Precalculate Nf and initialize Nfpow */ Nf = (sm_a ** 2) / (sm_b * Math.sqrt(1 + nuf2)); Nfpow = Nf; // '/* Precalculate tf */ tf = Math.tan(phif); tf2 = tf * tf; tf4 = tf2 * tf2; // '/* Precalculate fractional coefficients for x**n in the equations // 'below to simplify the expressions for latitude and longitude. */ x1frac = 1 / (Nfpow * cf); Nfpow = Nfpow * Nf ; /* now equals Nf**2) */ x2frac = tf / (2 * Nfpow); Nfpow = Nfpow * Nf; /* now equals Nf**3) */ x3frac = 1 / (6 * Nfpow * cf); Nfpow = Nfpow * Nf ; /* now equals Nf**4) */ x4frac = tf / (24 * Nfpow); Nfpow = Nfpow * Nf ; /* now equals Nf**5) */ x5frac = 1 / (120 * Nfpow * cf); Nfpow = Nfpow * Nf ; /* now equals Nf**6) */ x6frac = tf / (720 * Nfpow); Nfpow = Nfpow * Nf; /* now equals Nf**7) */ x7frac = 1 / (5040 * Nfpow * cf); Nfpow = Nfpow * Nf ; /* now equals Nf**8) */ x8frac = tf / (40320 * Nfpow); //' /* Precalculate polynomial coefficients for x**n. // ' -- x**1 does not have a polynomial coefficient. */ x2poly = -1 - nuf2; x3poly = -1 - 2 * tf2 - nuf2; x4poly = 5 + 3 * tf2 + 6 * nuf2 - 6 * tf2 * nuf2 - 3 * (nuf2 * nuf2) - 9 * tf2 * (nuf2 * nuf2); x5poly = 5 + 28 * tf2 + 24 * tf4 + 6 * nuf2 + 8 * tf2 * nuf2; x6poly = -61 - 90 * tf2 - 45 * tf4 - 107 * nuf2 + 162 * tf2 * nuf2; x7poly = -61 - 662 * tf2 - 1320 * tf4 - 720 * (tf4 * tf2); x8poly = 1385 + 3633 * tf2 + 4095 * tf4 + 1575 * (tf4 * tf2); // ' /* Calculate latitude */ philambda = phif + x2frac * x2poly * (x * x) + x4frac * x4poly * x ** 4 + x6frac * x6poly * x ** 6 + x8frac * x8poly * x ** 8; // ' /* Calculate longitude */ philambda1 = lambda0 + x1frac * x + x3frac * x3poly * x ** 3 + x5frac * x5poly * x ** 5 + x7frac * x7poly * x ** 7 // '// return $philambda; x_geo = (philambda / 3.141592654) * 180; // '$y_geo= (($philambda1)/3.141592654) * 180.0; // 'Return return x_geo; } function y_geo(x, y) { var zone ; var lamba0 ; var phif ; var Nf ; var Nfpow ; var nuf2 ; var ep2 ; var tf ; var tf2 ; var tf4 ; var cf ; var x1frac ; var x2frac ; var x3frac ; var x4frac ; var x5frac ; var x6frac ; var x7frac ; var x8frac ; var x2poly ; var x3poly ; var x4poly ; var x5poly ; var x6poly ; var x7poly ; var x8poly ; var philambda ; var philambda1 ; var sm_a ; var sm_b ; // ' var x_geo ; var UTMScaleFactor = 0.9996; var zone = 21; x = x - 500000; x = x / UTMScaleFactor; // ' /* If in southern hemisphere, adjust y accordingly. */ // ' /* if ($southhemi) */ y = y - 10000000; y = y / UTMScaleFactor; // ' // $cmeridian = UTMCentralMeridian ($zone); // '//$lambda0 = ((-183.0 + ($zone * 6.0))/180) * 3.14159265358979 ; lambda0 = ((-183 + (zone * 6)) / 180) * 3.141592654; sm_a = 6378137; sm_b = 6356752.314; // '/* Get the value of phif, the footpoint latitude. */ phif = result(y); // '/* Precalculate ep2 */ ep2 = (sm_a ** 2 - sm_b ** 2) / (sm_b ** 2); // '/* Precalculate cos (phif) */ cf = Math.cos(phif); // '/* Precalculate nuf2 */ nuf2 = ep2 * (cf ** 2); // '/* Precalculate Nf and initialize Nfpow */ Nf = (sm_a ** 2) / (sm_b * Math.sqrt(1 + nuf2)); Nfpow = Nf; // '/* Precalculate tf */ tf = Math.tan(phif); tf2 = tf * tf; tf4 = tf2 * tf2; // '/* Precalculate fractional coefficients for x**n in the equations // 'below to simplify the expressions for latitude and longitude. */ x1frac = 1 / (Nfpow * cf); Nfpow = Nfpow * Nf /* now equals Nf**2) */ x2frac = tf / (2 * Nfpow); Nfpow = Nfpow * Nf; /* now equals Nf**3) */ x3frac = 1 / (6 * Nfpow * cf); Nfpow = Nfpow * Nf ; /* now equals Nf**4) */ x4frac = tf / (24 * Nfpow); Nfpow = Nfpow * Nf; /* now equals Nf**5) */ x5frac = 1 / (120 * Nfpow * cf); Nfpow = Nfpow * Nf ; /* now equals Nf**6) */ x6frac = tf / (720 * Nfpow); Nfpow = Nfpow * Nf ; /* now equals Nf**7) */ x7frac = 1 / (5040 * Nfpow * cf); Nfpow = Nfpow * Nf ; /* now equals Nf**8) */ x8frac = tf / (40320 * Nfpow); //' /* Precalculate polynomial coefficients for x**n. // ' -- x**1 does not have a polynomial coefficient. */ x2poly = -1 - nuf2; x3poly = -1 - 2 * tf2 - nuf2; x4poly = 5 + 3 * tf2 + 6 * nuf2 - 6 * tf2 * nuf2 - 3 * (nuf2 * nuf2) - 9 * tf2 * (nuf2 * nuf2); x5poly = 5 + 28 * tf2 + 24 * tf4 + 6 * nuf2 + 8 * tf2 * nuf2; x6poly = -61 - 90 * tf2 - 45 * tf4 - 107 * nuf2 + 162 * tf2 * nuf2; x7poly = -61 - 662 * tf2 - 1320 * tf4 - 720 * (tf4 * tf2); x8poly = 1385 + 3633 * tf2 + 4095 * tf4 + 1575 * (tf4 * tf2); //' /* Calculate latitude */ philambda = phif + x2frac * x2poly * (x * x) + x4frac * x4poly * x ** 4 + x6frac * x6poly * x ** 6 + x8frac * x8poly * x ** 8; // ' /* Calculate longitude */ philambda1 = lambda0 + x1frac * x + x3frac * x3poly * x ** 3 + x5frac * x5poly * x ** 5 + x7frac * x7poly * x ** 7; // '// return $philambda; // 'x_geo = (philambda / 3.141592654) * 180 y_geo = ((philambda1) / 3.141592654) * 180; return y_geo; }