Skip to content

Commit 325fe4a

Browse files
authored
A better fix for: grdimage -Jq -R0/360/-90/90 fails to plot map (#9056)
This fix no longer causes failures in tests due to missing tickmarks at 90 degrees N
1 parent 7b70493 commit 325fe4a

2 files changed

Lines changed: 22 additions & 20 deletions

File tree

src/gmt_init.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16570,7 +16570,8 @@ void gmt_detect_oblique_region (struct GMT_CTRL *GMT, char *file) {
1657016570
* We wish to "do no harm" as well, so only some situations will get through this function.
1657116571
*/
1657216572
int k_data;
16573-
double d_inc, wesn[4];
16573+
double d_inc, wesn[4], pars[16]; /* pars[] backs up the raw projection parameters since gmt_map_setup below mutates them in place */
16574+
bool units_pr_degree;
1657416575
struct GMTAPI_CTRL *API = GMT->parent; /* Shorthand */
1657516576

1657616577
if (gmt_M_is_cartesian (GMT, GMT_IN)) return; /* This check only applies to geographic data */
@@ -16580,19 +16581,30 @@ void gmt_detect_oblique_region (struct GMT_CTRL *GMT, char *file) {
1658016581
if (!(gmt_M_360_range (GMT->common.R.wesn[XLO], GMT->common.R.wesn[XHI]) && gmt_M_180_range (GMT->common.R.wesn[YLO], GMT->common.R.wesn[YHI]))) return; /* Gave -Rd or -Rg so need to probe more*/
1658116582
if (gmt_M_is_azimuthal (GMT) && doubleAlmostEqual (fabs (GMT->current.proj.lat0), 90.0) && !GMT->common.R.oblique) return; /* Nothing to do */
1658216583
if (GMT->current.proj.projection == GMT_PROJ4_SPILHAUS) return; /* This is one is square */
16583-
gmt_M_memcpy (wesn, GMT->common.R.wesn, 4, double); /* Save the region we were given */
16584-
16585-
if (gmt_map_setup (GMT, GMT->common.R.wesn)) /* Set up projection */
16584+
gmt_M_memcpy(wesn, GMT->common.R.wesn, 4, double); /* Save the region we were given */
16585+
/* This is a throwaway probe: gmt_map_setup scales the projection parameters (e.g. pars[2] /= M_PR_DEG for -Jq scale),
16586+
* so we must restore the raw pars and units_pr_degree flag afterwards or the caller's real gmt_map_setup will scale them
16587+
* a second time and collapse the map (https://github.com/GenericMappingTools/gmt issue #8963). */
16588+
gmt_M_memcpy(pars, GMT->current.proj.pars, 16, double);
16589+
units_pr_degree = GMT->current.proj.units_pr_degree;
16590+
16591+
if (gmt_map_setup (GMT, GMT->common.R.wesn)) { /* Set up projection */
16592+
gmt_M_memcpy(GMT->current.proj.pars, pars, 16, double); GMT->current.proj.units_pr_degree = units_pr_degree;
1658616593
return; /* Something went wrong */
16587-
if (gmt_map_perimeter_search (GMT, GMT->common.R.wesn, false)) /* Refine without 0.1 degree padding */
16594+
}
16595+
if (gmt_map_perimeter_search(GMT, GMT->common.R.wesn, false)) { /* Refine without 0.1 degree padding */
16596+
gmt_M_memcpy(GMT->current.proj.pars, pars, 16, double); GMT->current.proj.units_pr_degree = units_pr_degree;
1658816597
return; /* Something went wrong */
16598+
}
16599+
gmt_M_memcpy(GMT->current.proj.pars, pars, 16, double); /* Restore raw projection parameters clobbered by the probe map_setup */
16600+
GMT->current.proj.units_pr_degree = units_pr_degree;
1658916601
if (GMT->common.R.wesn[XHI] < GMT->common.R.wesn[XLO] || GMT->common.R.wesn[YHI] < GMT->common.R.wesn[YLO])
16590-
gmt_M_memcpy (GMT->common.R.wesn, wesn, 4, double); /* Reset to give region if junk resulted */
16591-
else if (gmt_M_360_range (wesn[XLO], wesn[XHI]) && gmt_M_360_range (GMT->common.R.wesn[XLO], GMT->common.R.wesn[XHI]))
16592-
gmt_M_memcpy (GMT->common.R.wesn, wesn, 2, double); /* Reset to given global w/e in the same format */
16593-
gmt_M_memcpy (API->tile_wesn, GMT->common.R.wesn, 4, double); /* Save the region we found */
16602+
gmt_M_memcpy(GMT->common.R.wesn, wesn, 4, double); /* Reset to give region if junk resulted */
16603+
else if (gmt_M_360_range(wesn[XLO], wesn[XHI]) && gmt_M_360_range (GMT->common.R.wesn[XLO], GMT->common.R.wesn[XHI]))
16604+
gmt_M_memcpy(GMT->common.R.wesn, wesn, 2, double); /* Reset to given global w/e in the same format */
16605+
gmt_M_memcpy(API->tile_wesn, GMT->common.R.wesn, 4, double); /* Save the region we found */
1659416606
d_inc = API->tile_inc; /* Increment in degrees, if set */
16595-
if (d_inc == 0.0 && file && file[0] == '@' && (k_data = gmt_remote_dataset_id (API, file)) != GMT_NOTSET) { /* Got a remote file to work on */
16607+
if (d_inc == 0.0 && file && file[0] == '@' && (k_data = gmt_remote_dataset_id(API, file)) != GMT_NOTSET) { /* Got a remote file to work on */
1659616608
d_inc = API->remote_info[k_data].d_inc; /* Increment in degrees */
1659716609
}
1659816610
if (d_inc > 0.0) {

src/grdimage.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,16 +1495,6 @@ EXTERN_MSC int GMT_grdimage(void *V_API, int mode, void *args) {
14951495
Ctrl = New_Ctrl (GMT); /* Allocate and initialize a new control structure */
14961496
if ((error = parse (GMT, Ctrl, options)) != 0) Return (error);
14971497

1498-
if (GMT->common.R.active[RSET] && gmt_M_is_geographic(GMT, GMT_IN) && !gmt_M_is_nonlinear_graticule(GMT) && GMT->common.R.wesn[YHI] == 90.0) {
1499-
/* Plotting a global pixel-registered grid with a linear/cylindrical (rectangular graticule) projection and a
1500-
* north boundary of exactly +90 makes a later gmt_map_setup collapse the y-scale, producing a degenerate plot
1501-
* (https://github.com/GenericMappingTools/gmt issue). Nudge the north boundary just below the pole, which is
1502-
* what passing -R.../89.999999999999 does and avoids the problem with no visible difference.
1503-
*/
1504-
GMT->common.R.wesn[YHI] = 90.0 - GMT_CONV12_LIMIT;
1505-
GMT_Report(API, GMT_MSG_DEBUG, "Nudged north boundary from 90 to %.12g to avoid degenerate projection scaling\n", GMT->common.R.wesn[YHI]);
1506-
}
1507-
15081498
/*---------------------------- This is the grdimage main code ----------------------------*/
15091499

15101500
if ((Conf = gmt_M_memory (GMT, NULL, 1, struct GRDIMAGE_CONF)) == NULL) {

0 commit comments

Comments
 (0)