Last active
February 13, 2024 15:20
-
-
Save will83/5920606 to your computer and use it in GitHub Desktop.
Fonction PHP permettant la conversion de Lambert93 à WGS84 (selon le fichier fourni par l'IGN).
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
<?php | |
function lambert93ToWgs84($x, $y){ | |
$x = number_format($x, 10, '.', ''); | |
$y = number_format($y, 10, '.', ''); | |
$b6 = 6378137.0000; | |
$b7 = 298.257222101; | |
$b8 = 1/$b7; | |
$b9 = 2*$b8-$b8*$b8; | |
$b10 = sqrt($b9); | |
$b13 = 3.000000000; | |
$b14 = 700000.0000; | |
$b15 = 12655612.0499; | |
$b16 = 0.7256077650532670; | |
$b17 = 11754255.426096; | |
$delx = $x - $b14; | |
$dely = $y - $b15; | |
$gamma = atan( -($delx) / $dely ); | |
$r = sqrt(($delx*$delx)+($dely*$dely)); | |
$latiso = log($b17/$r)/$b16; | |
$sinphiit0 = tanh($latiso+$b10*atanh($b10*sin(1))); | |
$sinphiit1 = tanh($latiso+$b10*atanh($b10*$sinphiit0)); | |
$sinphiit2 = tanh($latiso+$b10*atanh($b10*$sinphiit1)); | |
$sinphiit3 = tanh($latiso+$b10*atanh($b10*$sinphiit2)); | |
$sinphiit4 = tanh($latiso+$b10*atanh($b10*$sinphiit3)); | |
$sinphiit5 = tanh($latiso+$b10*atanh($b10*$sinphiit4)); | |
$sinphiit6 = tanh($latiso+$b10*atanh($b10*$sinphiit5)); | |
$longrad = $gamma/$b16+$b13/180*pi(); | |
$latrad = asin($sinphiit6); | |
$long = ($longrad/pi()*180); | |
$lat = ($latrad/pi()*180); | |
return array( | |
'lambert93' => array( | |
'x' => $x, | |
'y' => $y | |
), | |
'wgs84' => array( | |
'lat' => $lat, | |
'long' => $long | |
) | |
); | |
} | |
// Exemple d'utilisation : | |
$x = 955502.7409000024; | |
$y = 6225307.0799999982; | |
print_r(lambert93ToWgs84($x,$y)); | |
/* Résultat en sortie : | |
Array | |
( | |
[lambert93] => Array | |
( | |
[x] => 955502.7409000024 | |
[y] => 6225307.0799999982 | |
) | |
[wgs84] => Array | |
( | |
[lat] => 43.081387131355 | |
[long] => 6.1358573938246 | |
) | |
) | |
*/ |
Merci pour cette version @Lulucmy !
Si vous ne voulez pas importer toutes les fonctions qui sont dans le module math
, vous pouvez rajouter cet import à la place du from math import *
:
from math import sqrt, atan, log, tanh, atanh, sin, pi, asin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Merci pour la fonction. Une version adaptée en Python de celle de niquenen :