Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert Lambert 93 to GPS Coordinates Latitude / Longitude (wgs84)
Math.tanh = Math.tanh || function(x) {
if(x === Infinity) {
return 1;
} else if(x === -Infinity) {
return -1;
} else {
return (Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x));
}
};
Math.atanh = Math.atanh || function(x) {
return Math.log((1+x)/(1-x)) / 2;
};
function lambert93toWGPS(lambertE, lambertN) {
var constantes = {
GRS80E: 0.081819191042816,
LONG_0: 3,
XS: 700000,
YS: 12655612.0499,
n: 0.7256077650532670,
C: 11754255.4261
}
var delX = lambertE - constantes.XS;
var delY = lambertN - constantes.YS;
var gamma = Math.atan(-delX / delY);
var R = Math.sqrt(delX * delX + delY * delY);
var latiso = Math.log(constantes.C / R) / constantes.n;
var sinPhiit0 = Math.tanh(latiso + constantes.GRS80E * Math.atanh(constantes.GRS80E * Math.sin(1)));
var sinPhiit1 = Math.tanh(latiso + constantes.GRS80E * Math.atanh(constantes.GRS80E * sinPhiit0));
var sinPhiit2 = Math.tanh(latiso + constantes.GRS80E * Math.atanh(constantes.GRS80E * sinPhiit1));
var sinPhiit3 = Math.tanh(latiso + constantes.GRS80E * Math.atanh(constantes.GRS80E * sinPhiit2));
var sinPhiit4 = Math.tanh(latiso + constantes.GRS80E * Math.atanh(constantes.GRS80E * sinPhiit3));
var sinPhiit5 = Math.tanh(latiso + constantes.GRS80E * Math.atanh(constantes.GRS80E * sinPhiit4));
var sinPhiit6 = Math.tanh(latiso + constantes.GRS80E * Math.atanh(constantes.GRS80E * sinPhiit5));
var longRad = Math.asin(sinPhiit6);
var latRad = gamma / constantes.n + constantes.LONG_0 / 180 * Math.PI;
var longitude = latRad / Math.PI * 180;
var latitude = longRad / Math.PI * 180;
return {longitude: longitude, latitude: latitude};
}
@achouippe

This comment has been minimized.

Copy link

commented Nov 18, 2015

Very useful, thank you !

@blemoine

This comment has been minimized.

Copy link
Owner Author

commented Feb 2, 2016

To convert for other Lambert Projection, you can change constantes with value found here :

http://geodesie.ign.fr/contenu/fichiers/documentation/algorithmes/notice/NTG_71.pdf

LONG_0 == λ0 ; GRS80E == e

@jerkso

This comment has been minimized.

Copy link

commented Jan 23, 2018

THX, u save my life today. I will be forever grateful.

@guillim

This comment has been minimized.

Copy link

commented Feb 28, 2018

work well! Thanks a lot

@Bouguerra-S

This comment has been minimized.

Copy link

commented Jun 26, 2018

Hello blemoine, I am working on a project and I need to write this function in python. I never used javascript therefore I don't understand what you did before the function keyword. Merci d'avance.

@blemoine

This comment has been minimized.

Copy link
Owner Author

commented Jul 24, 2018

if you talk about Math.tanh = ... and Math.atanh = ... , it's only to define the hyperbolic tangent and hyperbolic arctangent if they don't already exist.

Because JavaScript can be run in many different browsers, you never know if every function that you need will already be present or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.