Grdconvert will not accept -R option

I am trying to extract bathymetric profiles from the New Zealand 250 m grid available at NIWA in ESRI float format, working in a windows 10 terminal.

gmt grdconvert nzbathymetry_2016_ascii-grid.asc=ef -R178/179.4/-39.5/-38.8

fails with “syntax error -R”

Without the -R option grdconvert produces an nc file,

gmt grdconvert nzbathymetry_2016_ascii-grid.asc=ef

but, I still get ‘syntax error’ with the -R option

gmt grdcut -Rd178/-39.5/179.4/-38.8+r

I’ve tried many variations on the syntax, but have not been able to get around this, though nothing appears wrong when looking at the nc file with grdinfo or gdalinfo.

It is known that those grids have a problem with the registration (see it here) maybe it can explain something. But note that this syntax -Rd178/-39.5/179.4/-38.8+r is invalid. -Rd is a global region. An a final thing is that you can access the .asc file directly. No need to convert before cut.

It seems I naively assumed the esri header info would allow GMT to translate the xy grid data to lat lon for me. The NIWA website says the xy grid data use EPSG 3994. Perhaps I need to use the EPSG code in my GMT commands? I see there was a correction to the GDAL libraries four years ago to make these data read correctly.

GMT can read those esri files natively. No need to convert or do anything else. But, as I said and linked, those files have a wrong header info regarding the grid registration.

I think the data in the files you linked are different in that they appear to be natively in lat lon, while my file is just in grid xy offsets on pixel centers with 250 m pixels. I have not figured out how to reference the xy grid to translate it to lat lon it seems.

Those files are .asc esri ascii grids. Isn’t it the same case as yours?

Doesn’t this work (aside from the fact that coordinates might be off by half a cell size)

gmt grd2xyz nzbathymetry_2016_ascii-grid.asc > t.dat

grd2xyz works, producing xoffset, yoffset, depth triples. Now I need to get them into latitude longitude coordinates.

grd2xyz produces x_coord, y_coord, z where x|y_coord are coordinates in the grid’s coordinate system. Are you saying that they are not geographical coordinates and you want them? Then use mapproject or grdproject the esri grid.

My ultimate goal is to extract bathymetric profiles for acoustic propagation models. I tried:
gmt grdproject nzbathymetry_2016_ascii-grid.asc -Jm100 -I -C
which produces a lat lon grid, but it is nowhere near New Zealand. I used 100 as 100 E is listed as the longitude of the central meridian while -41 is listed as the latitude of truescale.

OK, -Jm100 is not good for sure. Lower case are for map scales. Are you sure the asc grid is in Mercator projection? Because to inverse project you must know the data projection … but I remember you mentioned an EPSG, try

gmt grdproject nzbathymetry_2016_ascii-grid.asc -J3994 -I -C -F

don’t remember if the -C -F is needed with EPGSs but it shouldn’t hurt

It is closer, but not right yet.
gmt grdinfo
grdinfo [ERROR]: Grid x increment <= 0.0
grdinfo (gmtlib_read_grd_info): Use grdedit -A on your grid file to make region and increments compatible [] Title: Produced by grdproject Command: grdproject nzbathymetry_2016_ascii-grid.asc -GC:\Users\mark\WhaleAcoust\Hikurangi\map\GMT\ -J+3994 -I -C -F Remark: Pixel node registration used [Geographic grid] Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7 x_min: 157.000000576 x_max: 193.001585358 x_inc: -0.0267413680438 name: longitude n_columns: 12116 y_min: -57.4999382033 y_max: -23.9993740265 y_inc: 0.00217663336864 name: latitude n_rows: 15391 z_min: 0 z_max: 0 name: z scale_factor: 1 add_offset: 0 format: netCDF-4 chunk_size: 129,129 shuffle: on deflation_level: 3
DATUM[“Unknown based on WGS84 ellipsoid”,
SPHEROID[“WGS 84”,6378137,298.257223563,

OK, make me a link with that file.
But have you looked at the registration problem? Are you sure the asc file has the correct registration?

I am not sure the original has the correct registration. The bathymetry data is also available other places which offer more info on it:

Those are very big files, > 560 Mb zipped ascii grids and the download sped for me (that have a 200 Mb network) is quite low ~2 hours.

Please print the grdinfo and gdalinfo outputs of your grid.

and what is the size of your grid?

The size of the grid is 12116 columns and 15391 rows
grdinfo nzbathymetry_2016_ascii-grid.asc
nzbathymetry_2016_ascii-grid.asc: Title:
nzbathymetry_2016_ascii-grid.asc: Command:
nzbathymetry_2016_ascii-grid.asc: Remark:
nzbathymetry_2016_ascii-grid.asc: Pixel node registration used [Cartesian grid]
nzbathymetry_2016_ascii-grid.asc: Grid file format: ei = ESRI Arc/Info ASCII Grid Interchange format (ASCII integer)
nzbathymetry_2016_ascii-grid.asc: x_min: 4795705.6 x_max: 7824705.6 x_inc: 250 name: x n_columns: 12116
nzbathymetry_2016_ascii-grid.asc: y_min: -5915585.8 y_max: -2067835.8 y_inc: 250 name: y n_rows: 15391
nzbathymetry_2016_ascii-grid.asc: z_min: NaN z_max: NaN name: z
nzbathymetry_2016_ascii-grid.asc: scale_factor: 1 add_offset: 0

gdalinfo nzbathymetry_2016_ascii-grid.asc
Driver: AAIGrid/Arc/Info ASCII Grid
Files: nzbathymetry_2016_ascii-grid.asc
Size is 12116, 15391
Origin = (4795705.599999999627471,-2067835.799999999813735)
Pixel Size = (250.000000000000000,-250.000000000000000)
Corner Coordinates:
Upper Left ( 4795705.600,-2067835.800)
Lower Left ( 4795705.600,-5915585.800)
Upper Right ( 7824705.600,-2067835.800)
Lower Right ( 7824705.600,-5915585.800)
Center ( 6310205.600,-3991710.800)
Band 1 Block=12116x1 Type=Float32, ColorInterp=Undefined
NoData Value=-9999


gdalwarp -s_srs EPSG:3994 -t_srs EPSG:4326 --config CENTER_LONG 180 -overwrite nzbathymetry_2016_ascii-grid.asc

The arcgis site suggests the bounds should be
West longitude: 161.15
East longitude: 179.695
North latitude: -31.329
South latitude: -49.249
gmt grdinfo
grdinfo [WARNING]: Guessing of registration in conflict between x and y, using gridline Title: GDAL Band Number 1 Command: Wed Jul 08 06:15:41 2020: GDAL Create(, … ) Remark: Gridline node registration used [Geographic grid] Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7 x_min: 157.001255882 x_max: 193.00091029 x_inc: 0.00251061122869 name: longitude n_columns: 14340 y_min: -57.4997149565 y_max: -24.0006293321 y_inc: 0.00251061122869 name: latitude n_rows: 13344 z_min: 0 z_max: 0 name: GDAL Band Number 1 scale_factor: 1 add_offset: 0 format: classic

The command I gave gives what it seems to be the correct transform. Not sure about the registration conflict. Some GDAL rounding perhaps.

Could you give me the commands you just used to make the figure you posted?

That was just a screen capture of an image using Mirone. To do it with GMT you would use (classical mode)

gmt grdimage gridfile -I+d -J... -R... -K > ...
gmt pscoast -R -J -Da -W0.5 -O >> ...

or with the GMT julia ( is the name I gave to the converted grid)

 imshow("", limits=(177.5, 178.5, -39.5, -38.8), shade=true, coast=true, fmt=:png, show=true)

it gives this