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

Make cs2cs support 4D coordinates. #1355

Merged
merged 1 commit into from
Mar 24, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 15 additions & 4 deletions src/apps/cs2cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,29 @@ static void process(FILE *fid)

z = strtod(s, &s);

/* To avoid breaking existing tests, we read what is a possible t */
/* component of the input and rewind the s-pointer so that the final */
/* output has consistant behaviour, with or without t values. */
/* This is a bit of a hack, in most cases 4D coordinates will be */
/* written to STDOUT (except when using -E) but the output format */
/* speficied with -f is not respected for the t component, rather it */
/* is forward verbatim from the input. */
char *before_time = s;
double t = strtod(s, &s);
s = before_time;

if (data.v == HUGE_VAL)
data.u = HUGE_VAL;

if (!*s && (s > line))
--s; /* assumed we gobbled \n */

if (echoin) {
char t;
t = *s;
char temp;
temp = *s;
*s = '\0';
(void)fputs(line, stdout);
*s = t;
*s = temp;
putchar('\t');
}

Expand All @@ -141,7 +152,7 @@ static void process(FILE *fid)
coord.xyzt.x = data.u;
coord.xyzt.y = data.v;
coord.xyzt.z = z;
coord.xyzt.t = HUGE_VAL;
coord.xyzt.t = t;
coord = proj_trans(transformation, PJ_FWD, coord);
data.u = coord.xyz.x;
data.v = coord.xyz.y;
Expand Down
13 changes: 13 additions & 0 deletions test/cli/testvarious
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,19 @@ $EXE EPSG:32631 EPSG:4326 -E >> ${OUT} <<EOF
EOF


echo "##############################################################" >> ${OUT}
echo "Test EPSG:4896 to EPSG:7930" >> ${OUT}
# Here we test that 4D coordinates are handled by cs2cs. Due to backwards
# compatibility, the t-component is not written to STDOUT as part of the
# coordinate data, but rather as part of the string that follows the xyz
# components. This is only seen by users when the -E option is used. Which
# means that this test also experience that behaviour.
$EXE -f %.4f EPSG:4896 EPSG:7930 -E >> ${OUT} <<EOF
3496737.2679 743254.4507 5264462.9620 2019.0
3496737.2679 743254.4507 5264462.9620 2029.0
EOF


# Done!
# do 'diff' with distribution results
echo "diff ${OUT} with ${OUT}.dist"
Expand Down
4 changes: 4 additions & 0 deletions test/cli/tv_out.dist
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,7 @@ Test EPSG:4326 to EPSG:32631
##############################################################
Test EPSG:32631 to EPSG:4326
400000 5000000 0 45d8'47.014"N 1d43'40.681"E 0.000
##############################################################
Test EPSG:4896 to EPSG:7930
3496737.2679 743254.4507 5264462.9620 3496737.7857 743254.0394 5264462.6437 2019.0
3496737.2679 743254.4507 5264462.9620 3496737.9401 743253.8861 5264462.5497 2029.0