[Proj] Proj may give erroneous results depending on locale

Peter S Galbraith psg at debian.org
Tue Jul 20 13:55:42 EDT 2004


Hi, a Debian user (Radoslaw Grzanka <radekg2 at poczta.onet.pl>) reported
the following bug when his locale is set to pl_PL :

: Hello,
:   I have encountered bug which resulted in proj giving different results
: depending on locale set.
:   As you can see in the signature my locale is pl_PL and when used with
: gettext (or gtk+) gives wrong coordinates after transformation.
:   I'm attaching simple testcase that shows the problem.
:   The bug is also occures in testing vesion of package (4.4.7) and was
: really hard to trace.
: 
: Best Regards,
:   Radoslaw Grzanka

When compiling the following C++ code and linking with either 4.4.7 or
4.4.8 versions of proj, the bug appears when running the executable (on
Debian systems).  I'm unfortunately not an expert in proj so cannot
track this down.  I don't think this is Debian-specific (but I could be
wrong).

--------cut-------------------------
//// Simple testcase
#include <locale.h>
#include <string>
#include <iostream>
#include <projects.h>

const std::string projparams("+x_0=115073.415747 +y_0=-6288530.367751"
        " +proj=lcc +lat_1=37.000000 +lat_2=65.000000 +lon_0=8.199763"
        " +ellps=WGS84 +to_meter=63.506519 +no_defs");

projUV proj_input;              // Input Values
projUV proj_output;             // Output Values
projPJ pj;

int main()
{
//////////////////////////////////
//// TEST 1 - without locales set.
        pj = pj_init_plus(projparams.c_str());

        proj_input.v = 53.5736;         // Lattitude
        proj_input.u = 7.42731;         // Longitude
        proj_input.v *= DEG_TO_RAD;     // To Rads
        proj_input.u *= DEG_TO_RAD;     // To Rads

        proj_output = pj_fwd(proj_input, pj);

        std::cout << "Lattitude: " << proj_output.v
                << " Longitude: " << proj_output.u << std::endl;

        pj_free(pj);
//// RESULT - Lattitude: 3197.17 Longitude: 1029.99 - GOOD.
///////////////////////////////////
////     TEST 2 - with locales set!
        setlocale (LC_ALL, "");                 // SETTING LOCALES!

        pj = pj_init_plus(projparams.c_str());

        proj_input.v = 53.5736;         // Lattitude
        proj_input.u = 7.42731;         // Longitude
        proj_input.v *= DEG_TO_RAD;     // To Rads
        proj_input.u *= DEG_TO_RAD;     // To Rads

        proj_output = pj_fwd(proj_input, pj);

        std::cout << "Lattitude: " << proj_output.v
                << " Longitude: " << proj_output.u << std::endl;

        pj_free(pj);
//// RESULT - Lattitude: 3220.56 Longitude: 1242.12 - BAD.
}
--------cut-------------------------

I had to add pl_PL as a possible locale on my system and generate the
proper locale files, then set pl_PL as my locale, then I could reproduce
the bug.

Thanks,
-- 
Peter S. Galbraith, Debian Developer          <psg at debian.org>
                                 http://people.debian.org/~psg
GPG key 1024/D2A913A1 - 97CE 866F F579 96EE  6E68 8170 35FF 799E



More information about the Proj mailing list