Skip to content

Commit 09542ec

Browse files
committed
omerc: catch invalid value of gamma (when specified without alpha)
Fixes OSGeo#3749 From the maths of the computation of alpha from gamma, there is a limitation where the maximum (absolute) value of gamma should be roughly less than 90° - |lat_0| New error message: ``` $ bin/proj -I +proj=omerc +lat_0=10 +lonc=10 +gamma=81 proj_create: Error 1027 (Invalid value for an argument): omerc: Invalid value for gamma: given lat_0 value, |gamma| should be <= 80.031869° Rel. 9.3.0, September 1st, 2023 <proj>: projection initialization failure cause: Invalid value for an argument program abnormally terminated ```
1 parent 7e10ddc commit 09542ec

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

docs/source/operations/projections/omerc.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ Central point and azimuth method
122122
bearing of centre line. If :option:`+alpha` is not given, then
123123
:option:`+gamma` is used to determine :option:`+alpha`.
124124

125+
If specifying only :option:`+gamma` without :option:`+alpha`, the maximum
126+
value of the absolute value of :option:`+gamma` is a function of the
127+
absolute value of :option:`+lat_0`, equal to :math:`90° - |\phi_0|` on a
128+
sphere and slightly above on a non-spherical ellipsoid.
129+
125130
.. option:: +lonc=<value>
126131

127132
Longitude of the projection centre. Note that this value is used to

src/projections/omerc.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ PJ *PROJECTION(omerc) {
187187

188188
if (fabs(fabs(P->phi0) - M_HALFPI) <= TOL) {
189189
proj_log_error(
190-
P, _("Invalid value for lat_01: |lat_0| should be < 90°"));
190+
P, _("Invalid value for lat_0: |lat_0| should be < 90°"));
191191
return pj_default_destructor(P,
192192
PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE);
193193
}
@@ -225,12 +225,25 @@ PJ *PROJECTION(omerc) {
225225
gamma0 = aasin(P->ctx, sin(alpha_c) / D);
226226
if (!gam)
227227
gamma = alpha_c;
228-
} else
229-
alpha_c = aasin(P->ctx, D * sin(gamma0 = gamma));
228+
} else {
229+
gamma0 = gamma;
230+
alpha_c = aasin(P->ctx, D * sin(gamma0));
231+
if (proj_errno(P) != 0) {
232+
// For a sphere, |gamma| must be <= 90 - |lat_0|
233+
// On an ellipsoid, this is very slightly above
234+
proj_log_error(P,
235+
("Invalid value for gamma: given lat_0 value, "
236+
"|gamma| should be <= " +
237+
std::to_string(asin(1. / D) / M_PI * 180) + "°")
238+
.c_str());
239+
return pj_default_destructor(
240+
P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE);
241+
}
242+
}
230243

231244
if (fabs(fabs(P->phi0) - M_HALFPI) <= TOL) {
232245
proj_log_error(
233-
P, _("Invalid value for lat_01: |lat_0| should be < 90°"));
246+
P, _("Invalid value for lat_0: |lat_0| should be < 90°"));
234247
return pj_default_destructor(P,
235248
PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE);
236249
}

test/gie/builtins.gie

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4720,6 +4720,32 @@ operation +proj=omerc +lat_2=91
47204720
expect failure errno invalid_op_illegal_arg_value
47214721

47224722

4723+
===============================================================================
4724+
# Test limitations on +gamma when specifying without +alpha
4725+
# cf https://github.com/OSGeo/PROJ/issues/3749
4726+
===============================================================================
4727+
4728+
-------------------------------------------------------------------------------
4729+
operation +proj=omerc +lat_0=10 +R=6400000 +gamma=80
4730+
-------------------------------------------------------------------------------
4731+
# OK
4732+
4733+
-------------------------------------------------------------------------------
4734+
operation +proj=omerc +lat_0=10 +R=6400000 +gamma=80.0000001
4735+
-------------------------------------------------------------------------------
4736+
expect failure errno invalid_op_illegal_arg_value
4737+
4738+
-------------------------------------------------------------------------------
4739+
operation +proj=omerc +lat_0=10 +R=6400000 +rf=300 +gamma=80.01
4740+
-------------------------------------------------------------------------------
4741+
# OK
4742+
4743+
-------------------------------------------------------------------------------
4744+
operation +proj=omerc +lat_0=10 +a=6400000 +rf=300 +gamma=80.1
4745+
-------------------------------------------------------------------------------
4746+
expect failure errno invalid_op_illegal_arg_value
4747+
4748+
47234749
===============================================================================
47244750
# Ortelius Oval
47254751
# Misc Sph, no inv.

0 commit comments

Comments
 (0)