Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cs2cs_emulation_setup: fix issue with non C-locale #1136

Merged
merged 1 commit into from Sep 28, 2018

Conversation

Projects
None yet
3 participants
@rouault
Copy link
Member

rouault commented Sep 27, 2018

in +towgs84 case, we use sprintf() with floating-point formatter to output
the ellipsoid parameters. For a locale with decimal separtor != dot, the
resulting string will not be parsed correctly by proj_atof(), leading to
wrong numeric result.

The fix is similar to the one done in pj_latlong_from_proj()

Note for later: if using C++, we could use a locale-independent formatting
solution to avoid such issue.

@@ -519,6 +519,19 @@ Returns 1 on success, 0 on failure
if (P->is_geocent || P->helmert || do_cart) {
char def[150];
sprintf (def, "break_cs2cs_recursion proj=cart a=%40.20g es=%40.20g", P->a_orig, P->es_orig);
{

This comment has been minimized.

@busstoptaktik

busstoptaktik Sep 27, 2018

Member

This block is stylistically quite different from its surroundings. I would prefer something like this (untested):

if (P->is_geocent || P->helmert || do_cart) {
    char def[150];
    char *next_pos = def;

    sprintf (def, "break_cs2cs_recursion     proj=cart   a=%40.20g  es=%40.20g", P->a_orig, P->es_orig);

    /* In case the current locale does not use dot but comma as decimal */
    /* separator, replace it with dot, so that proj_atof() behaves */
    /* correctly. */
    /* TODO later: use C++ ostringstream with imbue(std::locale::classic()) */
    /* to be locale unaware */
    while ( (next_pos =  strchr (next_pos, ',')))
        *next_pos++ = '.';

    ...

or even a for rather than while:

for (next_pos = def; next_pos = strchr (next_pos, ','); next_pos++)
    *next_pos = '.'

Alternatively, we could build comma-dot agnosticism into the alternative proj_strtod in proj_strtod.c

This comment has been minimized.

@rouault

rouault Sep 27, 2018

Author Member

OK, taken into account

cs2cs_emulation_setup: fix issue with non C-locale
in +towgs84 case, we use sprintf() with floating-point formatter to output
the ellipsoid parameters. For a locale with decimal separtor != dot, the
resulting string will not be parsed correctly by proj_atof(), leading to
wrong numeric result.

The fix is similar to the one done in pj_latlong_from_proj()

Note for later: if using C++, we could use a locale-independent formatting
solution to avoid such issue.

@rouault rouault force-pushed the rouault:fix_locale_issue_cs2cs_emulation_setup branch from 6cc0350 to b65cc5d Sep 27, 2018

@rouault rouault merged commit da0e7f9 into OSGeo:master Sep 28, 2018

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage decreased (-0.003%) to 77.829%
Details

@kbevers kbevers added this to the 6.0.0 milestone Sep 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.