Created
February 10, 2025 04:57
-
-
Save jpinasrivera/9d0bb8504d5a89b0e4973346fc2be03b to your computer and use it in GitHub Desktop.
Convierte los valores X Y UTM incluyendo la Zona de una coordenada a valores Latitud y Longitud (JavaScript)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function utmToDeg(Easting, Northing, Zone, isSouthernHemisphere) { | |
const a = 6378137.0; // Radio ecuatorial | |
const f = 1 / 298.257223563; // Aplanamiento | |
const k0 = 0.9996; // Factor de escala | |
const e = Math.sqrt(f * (2 - f)); // Excentricidad | |
const e1sq = e * e / (1 - e * e); // Segunda excentricidad al cuadrado | |
const x = Easting - 500000.0; // Restar el falso este | |
let y = Northing; | |
if (isSouthernHemisphere) { | |
y -= 10000000.0; // Ajuste para el hemisferio sur | |
} | |
const lonOrigin = (Zone - 1) * 6 - 180 + 3; // Meridiano central de la zona | |
const m = y / k0; | |
const mu = m / (a * (1 - e * e / 4 - 3 * e * e * e * e / 64 - 5 * e * e * e * e * e * e / 256)); | |
const phi1Rad = mu + (3 * e / 2 - 27 * e * e * e / 32) * Math.sin(2 * mu) | |
+ (21 * e * e / 16 - 55 * e * e * e * e / 32) * Math.sin(4 * mu) | |
+ (151 * e * e * e / 96) * Math.sin(6 * mu); | |
const n1 = a / Math.sqrt(1 - e * e * Math.sin(phi1Rad) * Math.sin(phi1Rad)); | |
const t1 = Math.tan(phi1Rad) * Math.tan(phi1Rad); | |
const c1 = e1sq * Math.cos(phi1Rad) * Math.cos(phi1Rad); | |
const r1 = a * (1 - e * e) / Math.pow(1 - e * e * Math.sin(phi1Rad) * Math.sin(phi1Rad), 1.5); | |
const d = x / (n1 * k0); | |
const lat = phi1Rad - (n1 * Math.tan(phi1Rad) / r1) * (d * d / 2 - (5 + 3 * t1 + 10 * c1 - 4 * c1 * c1 - 9 * e1sq) * d * d * d * d / 24 | |
+ (61 + 90 * t1 + 298 * c1 + 45 * t1 * t1 - 252 * e1sq - 3 * c1 * c1) * d * d * d * d * d * d / 720); | |
const lon = lonOrigin + (d - (1 + 2 * t1 + c1) * d * d * d / 6 | |
+ (5 - 2 * c1 + 28 * t1 - 3 * c1 * c1 + 8 * e1sq + 24 * t1 * t1) * d * d * d * d * d / 120) / Math.cos(phi1Rad); | |
return { | |
Latitude: lat * 180 / Math.PI, | |
Longitude: lon * 180 / Math.PI | |
}; | |
}; | |
// Ejemplo de uso | |
//const result = utmToDeg(277438.15, 8674510.34, 18, true); // Coordenadas UTM de Lima, Perú | |
//console.log(result); // { Latitude: -12.0464, Longitude: -77.0428 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment