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

Let -Jp|P optionally set what angles"w/e" really are #5124

Merged
merged 16 commits into from
Apr 22, 2021
Merged
3 changes: 2 additions & 1 deletion doc/rst/source/explain_-J.rst_
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ respectively):

.. _-Jp_full:

**-Jp**\|\ **P**\ *scale*\|\ *width*\ [**+a**]\ [**+f**\ [**e**\|\ **p**\|\ *radius*]]\
**-Jp**\|\ **P**\ *scale*\|\ *width*\ [**+a**]\ [**+f**\ [**e**\|\ **p**\|\ *radius*]]\ [**+k**\ *kind*]\
[**+r**\ *offset*][**+t**\ *origin*][**+z**\ [**p**\|\ *radius*]]] (Polar coordinates (*theta*, *r*))

Give *scale* (with **-Jp**; in :ref:`plot-units <plt-units>`/r-unit) or *width* (with **-JP**; in
Expand All @@ -286,6 +286,7 @@ respectively):
- **+f** to flip the radial direction to point inwards, and append **e** to indicate that *r* represents
*elevations* in degrees (requires *south* >= 0 and *north* <= 90), **p** to select current planetary radius
(determined by :term:`PROJ_ELLIPSOID`) as maximum radius [*north*], or *radius* to specify a custom radius.
- **+k** sets the annotation *kind* to be longitudes (*x*) or latitudes (*y*) [Default is unspecified angles].
- **+r**\ *offset* to include a radial offset in measurement units [default is **0**].
- **+t**\ *origin* in degrees so that this angular value is aligned with the positive *x*-axis (or the azimuth to
be aligned with the positive *y*-axis if **+a**) [default is **0**].
Expand Down
2 changes: 1 addition & 1 deletion doc/rst/source/proj-codes.rst_
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
* - :ref:`Polar [azimuthal] <-Jp>` (:math:`\theta, r`) (or cylindrical)
- **-Jp**\|\ **P**
- **-Jpolar/**
- *scale*\|\ *width*\ [**+a**]\ [**+f**\ [**e**\|\ **p**\|\ *radius*]]\
- *scale*\|\ *width*\ [**+a**]\ [**+f**\ [**e**\|\ **p**\|\ *radius*]]\ [**+k**\ *kind*]\
[**+r**\ *offset*][**+t**\ *origin*][**+z**\ [**p**\|\ *radius*]]
* - :ref:`(American) polyconic <-Jpoly>`
- **-Jpoly**\|\ **Poly**
Expand Down
29 changes: 21 additions & 8 deletions src/gmt_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -5026,10 +5026,10 @@ GMT_LOCAL bool gmtinit_parse_J_option (struct GMT_CTRL *GMT, char *args_in) {
gmt_set_column_type (GMT, GMT_IN, GMT_Y, GMT_IS_FLOAT);
GMT->current.proj.got_azimuths = GMT->current.proj.got_elevations = false;
GMT->current.proj.z_down = GMT_ZDOWN_R;
if ((d = gmt_first_modifier (GMT, args, "afrtz"))) { /* Process all modifiers */
if ((d = gmt_first_modifier (GMT, args, "afkrtz"))) { /* Process all modifiers */
unsigned int pos = 0, uerr = 0;
char word[GMT_LEN32] = {""};
while (gmt_getmodopt (GMT, 'J', d, "afrtz", &pos, word, &uerr) && uerr == 0) {
while (gmt_getmodopt (GMT, 'J', d, "afkrtz", &pos, word, &uerr) && uerr == 0) {
switch (word[0]) {
case 'a': /* Using azimuths instead of directions */
GMT->current.proj.got_azimuths = true;
Expand All @@ -5050,6 +5050,16 @@ GMT_LOCAL bool gmtinit_parse_J_option (struct GMT_CTRL *GMT, char *args_in) {
break;
}
break;
case 'k': /* Gave optional +k to indicate angles are longitude (x) or latitude (y) [Just great circle angles] */
switch (word[1]) {
case 'x': GMT->current.proj.angle_kind = GMT_IS_LON; break;
case 'y': GMT->current.proj.angle_kind = GMT_IS_LAT; break;
default:
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Polar projection: +%s not a valid argument\n", word);
error++;
break;
}
break;
case 'r': /* Gave optional +r for a nonzero radial offset [0] */
GMT->current.proj.radial_offset = gmt_M_to_inch (GMT, &word[1]);
break;
Expand Down Expand Up @@ -5083,10 +5093,6 @@ GMT_LOCAL bool gmtinit_parse_J_option (struct GMT_CTRL *GMT, char *args_in) {
if (uerr) return (GMT_PARSE_ERROR);
GMT->current.proj.pars[0] = gmt_M_to_inch (GMT, args);
if (d) d[0] = '+'; /* Restore modifiers */
// if (GMT->current.proj.z_down && GMT->current.proj.flip) {
// GMT_Report (GMT->parent, GMT_MSG_ERROR, "Polar projection: Cannot select both +f and +z modifiers\n");
// error++;
// }
}
else { /* No modifiers, so look for deprecated syntax such as -Jp|p[a|A], slash-separated scale|width and angular offset, and trailing r or z codes */
if (args[0] == 'a' || args[0] == 'A') { /* Using azimuths instead of directions */
Expand All @@ -5113,6 +5119,10 @@ GMT_LOCAL bool gmtinit_parse_J_option (struct GMT_CTRL *GMT, char *args_in) {
else
error++;
}
if (GMT->current.proj.got_azimuths && GMT->current.proj.angle_kind) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Polar projection: Cannot select both +a and +k\n");
error++;
}
if (GMT->current.proj.got_azimuths) GMT->current.proj.pars[1] = -GMT->current.proj.pars[1]; /* Because azimuths go clockwise */
break;

Expand Down Expand Up @@ -7133,14 +7143,17 @@ void gmtlib_explain_options (struct GMT_CTRL *GMT, char *options) {
gmt_message (GMT, "\t Upper-case A|B|C removes enforcement of a northern hemisphere pole.\n");
gmt_message (GMT, "\t Append +v to make the oblique Equator the y-axis [x-axis].\n");

gmt_message (GMT, "\t -Jp|P<scale>|<width>[+a][+f[e|p|<radius>]][+r<offset>][+t<origin>][+z[p|<radius>]] (Polar (theta,radius))\n");
gmt_message (GMT, "\t -Jp|P<scale>|<width>[+a][+f[e|p|<radius>]][+k<kind>][+r<offset>][+t<origin>][+z[p|<radius>]] (Polar (theta,radius))\n");
gmt_message (GMT, "\t Linear scaling for polar coordinates. Give scale in %s/units.\n",
GMT->session.unit_name[GMT->current.setting.proj_length_unit]);
gmt_message (GMT, "\t Append +a to use azimuths (CW from North) instead of directions (CCW from East) [Default].\n");
gmt_message (GMT, "\t Append +f to flip radial direction so that south is on the outside and north is at the center.\n");
gmt_message (GMT, "\t Append e to indicate data are elevations in degrees (s/n must be in 0-90 range).\n");
gmt_message (GMT, "\t Append p to set r = current planetary radius to be the center.\n");
gmt_message (GMT, "\t Append <radius> to indicate the radius at the center.\n");
gmt_message (GMT, "\t Append +k to specify angular kind [angles].\n");
gmt_message (GMT, "\t Append x to indicate angles should be formatted as longitude.\n");
gmt_message (GMT, "\t Append y to indicate angles should be formatted as latitude.\n");
gmt_message (GMT, "\t Append +r to offset the radial values [0].\n");
gmt_message (GMT, "\t Append +t to set <origin> value for angles or azimuths [0].\n");
gmt_message (GMT, "\t Append +z to annotate depths rather than radius [Default]. Alternatively, if you provided depths\n");
Expand Down Expand Up @@ -7257,7 +7270,7 @@ void gmtlib_explain_options (struct GMT_CTRL *GMT, char *options) {

gmt_message (GMT, "\t -Jy|Y[<lon0>/[<lat0>/]]<scl>|<width> (Cylindrical Equal-area)\n");

gmt_message (GMT, "\t -Jp|P<scl>|<width>[+a][+f[e|p|<radius>]][+o<offset>][+r<origin][+z[p|<radius>]] (Polar [azimuth] (theta,radius))\n");
gmt_message (GMT, "\t -Jp|P<scl>|<width>[+a][+f[e|p|<radius>]][+k<kind>][+r<offset>][+t<origin][+z[p|<radius>]] (Polar [azimuth] (theta,radius))\n");

gmt_message (GMT, "\t -Jx|X<x-scl>|<width>[d|l|p<power>|t|T][/<y-scl>|<height>[d|l|p<power>|t|T]] (Linear, log, and power projections)\n");
gmt_message (GMT, "\t (See basemap for more details on projection syntax)\n");
Expand Down
4 changes: 4 additions & 0 deletions src/gmt_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -2794,6 +2794,10 @@ GMT_LOCAL int gmtmap_init_polar (struct GMT_CTRL *GMT, bool *search) {

*search = false;
gmtproj_vpolar (GMT, GMT->current.proj.pars[1]);
if (GMT->current.proj.angle_kind == GMT_IS_LAT && (GMT->common.R.wesn[XLO] < -90.0 || GMT->common.R.wesn[XHI] > 90.0)) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -R: Your +ky modifier for -Jp|P implies angles must be contained in the -90/+90 range (latitudes)\n");
return GMT_PROJECTION_ERROR;
}
if (GMT->current.proj.flip) { /* Check restrictions */
if (GMT->common.R.wesn[YLO] < 0.0 || GMT->common.R.wesn[YHI] > GMT->current.proj.flip_radius) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "-JP...+f requires s >= 0 and n <= %g!\n", GMT->current.proj.flip_radius);
Expand Down
Loading