Skip to content

Commit

Permalink
Merge pull request #3878 from rouault/fix_3800
Browse files Browse the repository at this point in the history
cs2cs: fix handling of input coordinates in grad (fixes #3800)
  • Loading branch information
rouault committed Sep 6, 2023
2 parents 7d2ccc8 + 87ae438 commit 10bd129
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/apps/cs2cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static void process(FILE *fid)

if (data.u != HUGE_VAL) {

if (srcIsLongLat) {
if (srcIsLongLat && fabs(srcToRadians - M_PI / 180) < 1e-10) {
/* dmstor gives values to radians. Convert now to the SRS unit
*/
data.u /= srcToRadians;
Expand Down Expand Up @@ -922,10 +922,10 @@ int main(int argc, char **argv) {
}

/* set input formatting control */
if (!srcIsLongLat)
informat = strtod;
else {
if (srcIsLongLat && fabs(srcToRadians - M_PI / 180) < 1e-10)
informat = dmstor;
else {
informat = strtod;
}

if (!destIsLongLat && !oform)
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ proj_add_gie_test("GIGS-5101.4-jhs-etmerc" "gigs/5101.4-jhs-etmerc.gie")
# Same as above, but using etmerc instead of tmerc
#proj_add_gie_test("GIGS-5101.4-jhs" "gigs/5101.4-jhs.gie")
proj_add_gie_test("GIGS-5102.1" "gigs/5102.1.gie")
#proj_add_gie_test("GIGS-5102.2" "gigs/5102.2.gie")
proj_add_gie_test("GIGS-5102.2" "gigs/5102.2.gie")
proj_add_gie_test("GIGS-5103.1" "gigs/5103.1.gie")
proj_add_gie_test("GIGS-5103.2" "gigs/5103.2.gie")
proj_add_gie_test("GIGS-5103.3" "gigs/5103.3.gie")
Expand Down
6 changes: 6 additions & 0 deletions test/cli/testvarious
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ $EXE +proj=utm +zone=11 +datum=WGS84 +pm=3 \
500000 3000000
EOF
echo "##############################################################" >> ${OUT}
echo Test input in grad >> ${OUT}
#
$EXE EPSG:4807 EPSG:27572 -E >>${OUT} <<EOF
64.44444444 2.9586342556
EOF
echo "##############################################################" >> ${OUT}
echo Test geocentric x/y/z generation. >> ${OUT}
#
$EXE +proj=latlong +datum=WGS84 \
Expand Down
3 changes: 3 additions & 0 deletions test/cli/tv_out.dist
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Test support for the lon_wrap switch.
Test simple prime meridian handling within a projection.
500000 3000000 113dW 27d7'20.891"N 0.000
##############################################################
Test input in grad
64.44444444 2.9586342556 760724.02 3457334.86 0.00
##############################################################
Test geocentric x/y/z generation.
0d00'00.001"W 0d00'00.001"N 0.0 6378137.00 -0.03 0.03
0d00'00.001"W 0d00'00.001"N 10.0 6378147.00 -0.03 0.03
Expand Down
34 changes: 24 additions & 10 deletions test/gigs/5102.2.gie.failing → test/gigs/5102.2.gie
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
--------------------------------------------------------------------------------

Test 5102 (part 2), Lambert Conic Conformal (1SP), v2-0_2011-06-28.

--------------------------------------------------------------------------------

<gie>
<gie-strict>

use_proj4_init_rules true

--------------------------------------------------------------------------------
operation +proj=pipeline
+step +init=epsg:4807 +inv
# We need to add this grad->rad step as +init=epsg:4807 assumes
# degrees (if front operation), or radians (if non-front), as this was the case
# in PROJ < 6 era
# Note: "cs2cs EPSG:4807 EPSG:27572" does the right job.
operation +proj=pipeline \
+step +proj=unitconvert +xy_in=grad +xy_out=rad \
+step +init=epsg:4807 +inv \
+step +init=epsg:27572
--------------------------------------------------------------------------------
tolerance 0.03 m
Expand Down Expand Up @@ -88,9 +94,13 @@ accept 9.6253009222 58.8888888889
expect 1183926.705 2923124.876

--------------------------------------------------------------------------------
operation +proj=pipeline
+step +init=epsg:27572 +inv
+step +init=epsg:4807
# We need to add this rad->grad step as +init=epsg:4807 assumes
# degrees (if last operation), or radians (if non-last), as this was the case
# in PROJ < 6 era
operation +proj=pipeline \
+step +init=epsg:27572 +inv \
+step +init=epsg:4807 \
+step +proj=unitconvert +xy_in=rad +xy_out=grad
--------------------------------------------------------------------------------
tolerance 0.03 m
accept 760724.023 3457334.864
Expand Down Expand Up @@ -169,8 +179,12 @@ accept 1183926.705 2923124.876
expect 9.6253009222 58.8888888889

--------------------------------------------------------------------------------
operation +proj=pipeline
+step +init=epsg:4807 +inv
# We need to add this grad->rad step as +init=epsg:4807 assumes
# degrees (if front operation), or radians (if non-front), as this was the case
# in PROJ < 6 era
operation +proj=pipeline \
+step +proj=unitconvert +xy_in=grad +xy_out=rad \
+step +init=epsg:4807 +inv \
+step +init=epsg:27572
--------------------------------------------------------------------------------
tolerance 0.006 m
Expand Down Expand Up @@ -249,4 +263,4 @@ tolerance 0.006 m
accept 9.6253009222 58.8888888889
roundtrip 1000

</gie>
</gie-strict>

0 comments on commit 10bd129

Please sign in to comment.