-3

I'm trying to use Proj4 (dll) to convert from Lambert93 to WGS84 but it always give a wrong answer:

// EPSG:2154 : Lambert 93 definition: https://spatialreference.org/ref/epsg/2154/proj4/
const char* src = "+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs";

// EPSG:4326
const char* dst = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";

if (!(pj_src = pj_init_plus(src)) )
    exit(1);
if (!(pj_dst = pj_init_plus(dst)) )
    exit(1);
while (scanf("%lf %lf", &x, &y) == 2) {    
    p = pj_transform(pj_src, pj_dst, 1, 1, &x, &y, nullptr );
    printf("%.2f\t%.2f\n", x, y);
}

For example: the values 6000 122 returns always -0.02 and -0.10 as same as 4000 10 Anyone know why?


With Proj6, i use the implement from this page : https://proj.org/development/migration.html

closed as unclear what you're asking by Spacedman, Fran Raga, nmtoken, PolyGeo Jun 13 at 22:36

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Can you make a complete minimal example? This is a code fragment that won't run without a lot of stuff around it. – Spacedman Jun 13 at 13:34
1

Modifying the code from here to get a complete runnable example:

https://stackoverflow.com/questions/24950614/abnormal-output-when-using-proj4-to-transform-latlong-to-utm

Your output is in Radians, so converting to degrees and printing to higher precision should show the difference:

  [excerpt]
  double x = 6000.0;
  double y = 122.0;

  [excerpt]
  int  p = pj_transform(pj_src, pj_dst, 1, 1, &x, &y, NULL );
  x *= RAD_TO_DEG;
  y *= RAD_TO_DEG;
  printf("%f\t%f\n", x, y);

Running with 6000,122 gives me: -1.325800,-5.981039, and running with 4000,10 gives me -1.338203,-5.982420. Different. But close because the input units are in metres and so the two points are only a few km apart.

Checking with R, I get transformed points the same as the C code:

> st_transform(st_sfc(st_point(c(6000,122)),crs=src),dst)
Geometry set for 1 feature 
geometry type:  POINT
dimension:      XY
bbox:           xmin: -1.3258 ymin: -5.981039 xmax: -1.3258 ymax: -5.981039
epsg (SRID):    4326
proj4string:    +proj=longlat +datum=WGS84 +no_defs
POINT (-1.3258 -5.981039)

> st_transform(st_sfc(st_point(c(4000,10)),crs=src),dst)
Geometry set for 1 feature 
geometry type:  POINT
dimension:      XY
bbox:           xmin: -1.338203 ymin: -5.98242 xmax: -1.338203 ymax: -5.98242
epsg (SRID):    4326
proj4string:    +proj=longlat +datum=WGS84 +no_defs
POINT (-1.338203 -5.98242)
  • Thank you for the answer, in fact, that code is not for proj6.1 but for proj4. the implement in this page : proj.org/development/migration.html work perfectly. – user144553 Jun 13 at 14:45
  • 3
    What do you mean? What code isn't for proj6? My code? Its using the same API functions as your code, from Proj4. Does my answer (multiply by RAD_TO_DEG and print to higher precision) solve your problem? If it does then click the tick sign to accept the answer, if not please explain in the comments or edit your question to add more details, such as showing a complete code example. – Spacedman Jun 13 at 16:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.