I am trying to find a code that can convert Lambert72 coordinates to WGS84, so that I can get the same results as I get in this site, going to Menu APPs->Transform Coordinates.
https://mygeodata.cloud/cs2cs/
As an example I tried the following coordinates pair in this site, choosing on the left, the code 31370 (Lambert72) and on the right, WGS84.: 149334.41 167411
The result is: 4.35930680453; 50.817136997
For this result to work on Google Maps, the values must be switched, so the result I need is rather: 50.817136997; 4.35930680453
I tried the code from this answer in a similar post but I converted to C instead of C++/C#:
https://stackoverflow.com/a/40589076/1911497
So, my code, modified to C is this:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
static void Lambert72toWGS84latlong(double X, double Y);
int main(){
double x, y;
x = 149334.41, y = 167411.0;
Lambert72toWGS84latlong(x, y);
return 0;
}
static void Lambert72toWGS84latlong(double X, double Y){
double LongRef = 0.076042943;
double nLamb = 0.7716421928;
double aCarre = pow(6378388.0,2.0);
double bLamb = 6378388.0 * (1.0 - (1.0 / 297.0));
double eCarre = (aCarre - pow(bLamb, 2.0)) / aCarre;
double KLamb = 11565915.812935;
double eLamb = sqrt(eCarre);
double eSur2 = eLamb / 2.0;
double Tan1 = (X - 150000.012) / (5400088.437 - Y);
double Lambda = LongRef + (1.0 / nLamb) * (0.000142043 + atan(Tan1));
double RLamb = sqrt(pow((X - 150000.012) , 2.0) + pow ((5400088.437 - Y) ,2.0));
double TanZDemi = pow((RLamb / KLamb),(1.0 / nLamb));
double Lati1 = 2.0 * atan(TanZDemi);
double eSin;
double Mult1, Mult2, Mult;
double LatiN, Diff;
double lat, lng ;
int i=0;
do{
eSin = eLamb * sin(Lati1);
Mult1 = 1.0 - eSin;
Mult2 = 1.0 + eSin;
Mult = pow((Mult1 / Mult2) , (eLamb / 2.0));
LatiN = (M_PI / 2.0) - (2.0 * (atan(TanZDemi * Mult)));
Diff = LatiN - Lati1;
printf("Diff: %d\n", abs(Diff));
//Lati1 = LatiN;
printf("Iterations: %d\n", i++);
}while (abs(Diff)> 0.0000000277777);
lat=LatiN;
lng=Lambda;
double SinLat = sin(lat);
double SinLng = sin(lng);
double CoSinLat = cos(lat);
double CoSinLng = cos(lng);
double dx = -125.8;
double dy = 79.9;
double dz = -100.5;
double da = -251.0;
double df = -0.000014192702;
double LWf = 1.0 / 297.0;
double LWa = 6378388.0;
double LWb = (1 - LWf) * LWa;
double LWe2 = (2.0 * LWf) - (LWf * LWf);
double Adb = 1.0 / (1.0 - LWf);
double Rn = LWa / sqrt(1.0 - LWe2 * SinLat * SinLat);
double Rm = LWa * (1 - LWe2) /pow((1.0 - LWe2 * lat * lat) ,1.5);
double DLat = -dx * SinLat * CoSinLng - dy * SinLat * SinLng + dz * CoSinLat;
DLat = DLat + da * (Rn * LWe2 * SinLat * CoSinLat) / LWa;
DLat = DLat + df * (Rm * Adb + Rn / Adb) * SinLat * CoSinLat;
DLat = DLat / (Rm + 0.0);
double DLng = (-dx * SinLng + dy * CoSinLng) / ((Rn + 0.0) * CoSinLat);
double Dh = dx * CoSinLat * CoSinLng + dy * CoSinLat * SinLng + dz * SinLat;
Dh = Dh - da * LWa / Rn + df * Rn * lat * lat / Adb;
double LatWGS84 = ((lat + DLat) * 180.0) / M_PI;
double LngWGS84 = ((lng + DLng) * 180.0) / M_PI;
printf("Latitude: %.8f\t Longitude: %.8f\n", LatWGS84, LngWGS84);
}
However I don't get the same result. The results I get are: Latitude: 50.78274764 Longitude: 4.35930689
What would I need to change to be able to get the same result as the one returned by the mentioned site above?
Thanks PsySc0rpi0n