[PROJ] Different results from cs2cs vs C API code

Even Rouault even.rouault at spatialys.com
Wed Sep 23 02:48:50 PDT 2020


On mardi 22 septembre 2020 17:13:40 CEST henning at kaarta.com wrote:
> Hi,
> 
> I'm trying to write C++ code referencing the proj7 API, to convert a set of
> lat/lon/alt points to a user-specified target CRS. Following the example in
> the proj documentation, I use proj_create_crs_to_crs() to establish source
> and target CRS, then proj_trans() to transform individual points. I hopes of
> validating the results, I thought I should test by feeding the same input
> coordinates to cs2cs on the command line, with the same CRS definitions
> (using epsg:xxxx+yyyy form in both the code and the cs2cs command), but I
> get different results, not outrageous but as much as dozens of meters. In
> some simpler tests, using only epsg:xxxx, I can get matching results. Is
> there something special about the epsg:xxxx+yyyy format that needs to be
> treated differently in C++ code vs. the command line usage?
> 
> 
> 
> For example:
> 
> 
> 
> echo "-33 151 5" | cs2cs -d 8 EPSG:4326+5773 +to EPSG:7856+5711
> 
> 313152.77721557              6346936.49571435 5.28067830
> 
> 
> 
> But with the same input values in the C++ code, the results are
> 
> 313188.89746084268    6347047.2885914352    4.940935415625713
> 
> 
> 
> Am I missing something fundamental here?

If you look at the output of
projinfo -s EPSG:4326+5773 -t EPSG:7856+5711
you can see that the first operation returned, which will be the one used here, has a time-
dependent transformation.

When you use cs2cs and do not specify it (as the 4th value in the coordinate), the time is sent 
to HUGE_VAL, which makes it not being used at all (so here as the reference epoch for the 
time-dependent Helmert transformation is 2020.0, it will be as if you specified 2020.0).
I assume in your C++ code you don't initialize the .t component of PROJ_COORD and it is by 
luck set to year 0.

see:

echo "-33 151 5 2020" | cs2cs -d 8 EPSG:4326+5773 +to EPSG:7856+5711
313152.77721557	6346936.49571435 5.28067830 2020

vs

echo "-33 151 5 0" | cs2cs -d 8 EPSG:4326+5773 +to EPSG:7856+5711
313188.89746084	6347047.28859144 4.94093542 0


Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/proj/attachments/20200923/a1807f84/attachment.html>


More information about the PROJ mailing list