Skip to content

Instantly share code, notes, and snippets.

@liitfr
Created November 17, 2017 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liitfr/723abbfc6b8fefe01f5c918605b4d4e1 to your computer and use it in GitHub Desktop.
Save liitfr/723abbfc6b8fefe01f5c918605b4d4e1 to your computer and use it in GitHub Desktop.
Convert LAMBERT93 coordinates to WGS with JS
// 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