Skip to content

Instantly share code, notes, and snippets.

@vallettea
Created August 15, 2014 15:29
Show Gist options
  • Select an option

  • Save vallettea/cdcfe33501d7fcae17fd to your computer and use it in GitHub Desktop.

Select an option

Save vallettea/cdcfe33501d7fcae17fd to your computer and use it in GitHub Desktop.
Converter from lambert to longitude latitude
// http://gis.stackexchange.com/questions/70089/lambert93-to-wgs84-ign-algorithms-longitude-problem
// http://fr.wikipedia.org/wiki/Projection_conique_conforme_de_Lambert
function GeoConverter() {
this.M_PI_2 = Math.PI / 2.0;
this.DEFAULT_EPS = 0.000001;
this.E_WGS84 = 0.08181919106;
this.E2 = this.E_WGS84 / 2.0;
this.LON_MERID_IERS = 3.0 * Math.PI / 180.0;
this.N = 0.7256077650;
this.C = 11754255.426;
this.XS = 700000.000;
this.YS = 12655612.050;
}
GeoConverter.prototype.latitudeFromLatitudeISO = function(latISo) {
var phi0 = 2 * Math.atan( Math.exp( latISo ) ) - this.M_PI_2;
var phiI = 2 * atan( pow(( 1 + this.E_WGS84 * sin( phi0 )) / ( 1 - this.E_WGS84 * sin( phi0 )), this.E2) * exp( latISo ) ) - this.M_PI_2;
var delta = abs( phiI - phi0 );
while( delta > this.DEFAULT_EPS ){
phi0 = phiI;
phiI =
2 * atan( pow(
( 1 + this.E_WGS84 * sin( phi0 ) ) /
( 1 - this.E_WGS84 * sin( phi0 ) ) , this.E2)
* exp( latISo ) ) - this.M_PI_2;
delta = abs( phiI - phi0 );
}
return phiI;
}
GeoConverter.prototype.toLatLon = function(x, y) {
var dX = x - this.XS;
var dY = y - this.YS;
var R = Math.sqrt( dX * dX + dY * dY );
var gamma = Math.atan( dX / -dY );
var latIso = -1 / this.N * Math.log( Math.abs( R / this.C ) );
var lon = Math.toDegrees( this.LON_MERID_IERS + gamma / this.N );
var lat = Math.toDegrees( latitudeFromLatitudeISO( latIso ));
return {lon:lon, lat:lat};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment