Internal call gdal_translate from grdcut, source grid filename with spaces not working

Hi, source grid filename with spaces not working when calling grdcut on a geotiff. The internal gdal_translate receives filename not quoted so spaces in the file name cause an error. Extract from the debug output below.

Calling gdal_translate instead directly with filenames surrounded by quotes works.
Problematic filename in my case is:
"Canadian Hydrographic Service NONNA bathymetry/NONNAP_9_TIFF/TIFF/NONNAP10_4400N06400W.tiff"

I think this may be a bug in filename handling.

Relevant debug output from grdcut:

grdcut [INFORMATION]: The gdal_translate command: 
gdal_translate -projwin -63.6834 44.7334 -63.6 44.65 -of netCDF -co COMPRESS=DEFLATE -co FORMAT=NC4 -co ZLEVEL=3 -a_nodata NaN Canadian Hydrographic Service NONNA bathymetry/NONNAP_9_TIFF/TIFF/NONNAP10_4400N06400W.tiff BB_Bathymetry.nc
ERROR 6: Too many command options 'Service'
Usage: gdal_translate [--help-general] [--long-usage]
       [-ot {Byte/Int16/UInt16/UInt32/Int32/UInt64/Int64/Float32/Float64/
             CInt16/CInt32/CFloat32/CFloat64}] [-strict]
       [-if format]* [-of format]
       [-b band] [-mask band] [-expand {gray|rgb|rgba}]
       [-outsize xsize[%]|0 ysize[%]|0] [-tr xres yres]
       [-r {nearest,bilinear,cubic,cubicspline,lanczos,average,mode}]
       [-unscale] [-scale[_bn] [src_min src_max [dst_min dst_max]]]* [-exponent[_bn] exp_val]*
       [-srcwin xoff yoff xsize ysize] [-epo] [-eco]
       [-projwin ulx uly lrx lry] [-projwin_srs srs_def]
       [-a_srs srs_def] [-a_coord_epoch epoch]
       [-a_ullr ulx uly lrx lry] [-a_nodata value]
       [-a_scale value] [-a_offset value]
       [-nogcp] [-gcp pixel line easting northing [elevation]]*
       |-colorinterp{_bn} {red|green|blue|alpha|gray|undefined}]
       |-colorinterp {red|green|blue|alpha|gray|undefined},...]
       [-mo "META-TAG=VALUE"]* [-q] [-sds]
       [-co "NAME=VALUE"]* [-stats] [-norat] [-noxmp]
       [-oo NAME=VALUE]*
       src_dataset dst_dataset
grdcut [ERROR]: Error calling gdal_translate -projwin -63.6834 44.7334 -63.6 44.65 -of netCDF -co COMPRESS=DEFLATE -co FORMAT=NC4 -co ZLEVEL=3 -a_nodata NaN Canadian Hydrographic Service NONNA bathymetry/NONNAP_9_TIFF/TIFF/NONNAP10_4400N06400W.tiff BB_Bathymetry.ncgrdcut [DEBUG]: gmtlib_garbage_collection: Destroying object: C=0 A=0 ID=1 W=Input F=Image M=File S=Unused P=55f21ca0d2b0 N=Canadian Hydrographic Service NONNA bathymetry/NONNAP_9_TIFF/TIFF/NONNAP10_4400N06400W.tiff

Thanks, we occasionally find these issues. We developers grew up in a time when using spaces in file names or directories was considered the equivalent of purposefully stabbing oneself in the foot.
At any rate, I will submit a PR to fix this issue - the use of gdal_translate from grdcut is relatively new and hence not tested on such filenames!

1 Like

If you are able to build from git source then please try out this pull request that I hope fixes the problem.

Now approved and merged into the master branch.

Thanks! Sorry for silence, was too busy to follow. Anyway I am not qualified enough to build from git sources within a reasonable time.