Skip to content

Commit

Permalink
Fix grdcut tif grids (#7918)
Browse files Browse the repository at this point in the history
* Trust more in the reported data type

* Don't change from grid to image if the output extension is .tif

* Update comment

* Remove commented lines.
  • Loading branch information
joa-quim authored Oct 17, 2023
1 parent be71a07 commit 08b10bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/gmt_grdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -3517,6 +3517,8 @@ int gmt_raster_type (struct GMT_CTRL *GMT, char *file, bool extra) {
struct GMT_GRID_HEADER_HIDDEN *HH = gmt_get_H_hidden (I->header); /* Get pointer to hidden structure */
if (HH->pocket && strchr (HH->pocket, ',') == NULL) /* Got a single band request which we return as a grid */
code = GMT_IS_GRID;
else if (I->type == GMT_FLOAT) /* No doubt in this case */
code = GMT_IS_GRID;
else if (HH->orig_datatype == GMT_UCHAR || HH->orig_datatype == GMT_CHAR) /* Got a gray or RGB image with or without transparency */
code = GMT_IS_IMAGE;
else if (I->header->n_bands > 1) /* Whatever it is we must return multiband as an image */
Expand Down
9 changes: 3 additions & 6 deletions src/grdcut.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,11 @@ static int parse (struct GMT_CTRL *GMT, struct GRDCUT_CTRL *Ctrl, struct GMT_OPT
int ftype = gmt_raster_type(GMT, Ctrl->In.file, true);
if (ftype == GMT_IS_IMAGE) /* Must read file as an image */
Ctrl->In.type = GMT_IS_IMAGE;
else if (ftype == GMT_IS_GRID) { /* Check extension in case of special case */
if (strstr (Ctrl->G.file, ".tif")) /* Want to write a single band (normally written as a grid) to geotiff instead */
Ctrl->In.type = GMT_IS_IMAGE;
else
Ctrl->In.type = GMT_IS_GRID;
}
else if (ftype == GMT_IS_GRID) /* Check extension in case of special case */
Ctrl->In.type = GMT_IS_GRID;
else /* Just have to assume it is a grid */
Ctrl->In.type = GMT_IS_GRID;

if (Ctrl->In.type == GMT_IS_IMAGE) {
n_errors += gmt_M_check_condition (GMT, Ctrl->Z.active, "Option -N: Cannot be used with an image\n");
n_errors += gmt_M_check_condition (GMT, Ctrl->Z.active, "Option -Z: Cannot be used with an image\n");
Expand Down

0 comments on commit 08b10bc

Please sign in to comment.