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

Add support for Degree Sign on input #2791

Merged
merged 8 commits into from
Aug 15, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/apps/cs2cs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ The following script
::

cs2cs +proj=latlong +datum=NAD83 +to +proj=utm +zone=10 +datum=NAD27 -r <<EOF
45d15'33.1" 111.5W
45°15'33.1" 111.5W
mwtoews marked this conversation as resolved.
Show resolved Hide resolved
45d15.551666667N -111d30
+45.25919444444 111d30'000w
EOF
Expand Down
20 changes: 14 additions & 6 deletions src/dmstor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ dmstor(const char *is, char **rs) {

double
dmstor_ctx(PJ_CONTEXT *ctx, const char *is, char **rs) {
int n, nl;
int n, nl, adv;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be better to move the declaration of the variable with its initialization at line 68

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, thanks @rouault I've updated my branch today with this change.

char *s, work[MAX_WORK];
const char* p;
double v, tv;

if (rs)
*rs = (char *)is;
/* copy sting into work space */
/* copy string into work space */
while (isspace(*is)) ++is;
n = MAX_WORK;
s = work;
p = (char *)is;
while (isgraph(*p) && --n)
while ((isgraph(*p) || *p == (char) 0xc2 || *p == (char) 0xb0) && --n)
rouault marked this conversation as resolved.
Show resolved Hide resolved
*s++ = *p++;
*s = '\0';
/* it is possible that a really odd input (like lots of leading
Expand All @@ -48,17 +48,25 @@ dmstor_ctx(PJ_CONTEXT *ctx, const char *is, char **rs) {
if (sign == '+' || sign == '-') s++;
else sign = '+';
v = 0.;
for (nl = 0 ; nl < 3 ; nl = n + 1 ) {
for (nl = 0 ; nl < 3 ; nl = n + 1) {
if (!(isdigit(*s) || *s == '.')) break;
if ((tv = proj_strtod(s, &s)) == HUGE_VAL)
return tv;
adv = 1;
switch (*s) {
case 'D': case 'd':
n = 0; break;
case '\'':
n = 1; break;
case '"':
n = 2; break;
/* degree symbol ("\xc2\xb0" in UTF-8) */
case (char) 0xc2:
if (s[1] == (char) 0xb0) {
n = 0;
adv = 2;
break;
}
rouault marked this conversation as resolved.
Show resolved Hide resolved
case 'r': case 'R':
if (nl) {
proj_context_errno_set( ctx, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE );
Expand All @@ -77,9 +85,9 @@ dmstor_ctx(PJ_CONTEXT *ctx, const char *is, char **rs) {
return HUGE_VAL;
}
v += tv * vm[n];
++s;
s += adv;
}
/* postfix sign */
/* postfix sign */
if (*s && (p = strchr(sym, *s))) {
sign = (p - sym) >= 4 ? '-' : '+';
++s;
Expand Down
3 changes: 3 additions & 0 deletions test/unit/gie_self_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,9 @@ TEST(gie, info_functions) {
/* we can't expect perfect numerical accuracy so testing with a tolerance */
ASSERT_NEAR(-2.0, proj_dmstor(&buf[0], NULL), 1e-7);

/* test degree sign on DMS input */
ASSERT_NEAR(0.34512432, proj_dmstor("19°46'27\"E", NULL), 1e-7);

/* test proj_derivatives_retrieve() and proj_factors_retrieve() */
P = proj_create(PJ_DEFAULT_CTX, "+proj=merc +ellps=WGS84");
a = proj_coord(0, 0, 0, 0);
Expand Down