Created
November 17, 2017 16:41
-
-
Save liitfr/723abbfc6b8fefe01f5c918605b4d4e1 to your computer and use it in GitHub Desktop.
Convert LAMBERT93 coordinates to WGS with JS
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
// this function converts LAMBERT93 coordinates used by IGN to lat / lon coordinates | |
// found here https://gist.github.com/will83/5920606 | |
const toWGS = (x, y) => { | |
const b7 = 298.257222101; | |
const b8 = 1 / b7; | |
const b9 = 2 * b8 - b8 * b8; | |
const b10 = Math.sqrt(b9); | |
const b13 = 3; | |
const b14 = 700000; | |
const b15 = 12655612.0499; | |
const b16 = 0.725607765053267; | |
const b17 = 11754255.426096; | |
const delx = x - b14; | |
const dely = y - b15; | |
const gamma = Math.atan(-delx / dely); | |
const r = Math.sqrt(delx * delx + dely * dely); | |
const latiso = Math.log(b17 / r) / b16; | |
const sinphiit0 = Math.tanh(latiso + b10 * Math.atanh(b10 * Math.sin(1))); | |
const sinphiit1 = Math.tanh(latiso + b10 * Math.atanh(b10 * sinphiit0)); | |
const sinphiit2 = Math.tanh(latiso + b10 * Math.atanh(b10 * sinphiit1)); | |
const sinphiit3 = Math.tanh(latiso + b10 * Math.atanh(b10 * sinphiit2)); | |
const sinphiit4 = Math.tanh(latiso + b10 * Math.atanh(b10 * sinphiit3)); | |
const sinphiit5 = Math.tanh(latiso + b10 * Math.atanh(b10 * sinphiit4)); | |
const sinphiit6 = Math.tanh(latiso + b10 * Math.atanh(b10 * sinphiit5)); | |
const longrad = gamma / b16 + b13 / 180 * Math.PI; | |
const latrad = Math.asin(sinphiit6); | |
const lng = longrad / Math.PI * 180; | |
const lat = latrad / Math.PI * 180; | |
return [lat, lng]; | |
}; | |
export default toWGS; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment