# Grdconvert will not accept -R option

**URL:** <https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609>\
**Category:** Q&A\
**Created:** [July 3, 2020, 1:45pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609 "2020-07-03T13:45:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![markmcdonald](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@markmcdonald](https://forum.generic-mapping-tools.org/u/markmcdonald)\
**Post date:** [July 3, 2020, 1:45pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/1 "2020-07-03T13:45:18Z")

</div>

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 -GsouthNZ.nc

fails with “syntax error -R”

Without the -R option grdconvert produces an nc file,

gmt grdconvert nzbathymetry\_2016\_ascii-grid.asc=ef -GAllNZ.nc

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

gmt grdcut AllNZ.nc -Rd178/-39.5/179.4/-38.8+r -GAllNZS.nc

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.

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [July 3, 2020, 2:50pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/2 "2020-07-03T14:50:46Z")

</div>

It is known that those grids have a problem with the registration (see it [here](https://flint.soest.hawaii.edu/t/grdimage-error-x-max-x-min-must-equal/440)) 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.

---

<div class="post-metadata">

**Author:** ![markmcdonald](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@markmcdonald](https://forum.generic-mapping-tools.org/u/markmcdonald)\
**Post date:** [July 6, 2020, 2:24pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/3 "2020-07-06T14:24:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [July 6, 2020, 2:47pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/4 "2020-07-06T14:47:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![markmcdonald](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@markmcdonald](https://forum.generic-mapping-tools.org/u/markmcdonald)\
**Post date:** [July 6, 2020, 3:04pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/5 "2020-07-06T15:04:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [July 6, 2020, 3:15pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/6 "2020-07-06T15:15:48Z")

</div>

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)

```auto
gmt grd2xyz nzbathymetry_2016_ascii-grid.asc > t.dat

```

---

<div class="post-metadata">

**Author:** ![markmcdonald](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@markmcdonald](https://forum.generic-mapping-tools.org/u/markmcdonald)\
**Post date:** [July 6, 2020, 5:24pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/7 "2020-07-06T17:24:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [July 6, 2020, 5:42pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/8 "2020-07-06T17:42:43Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![markmcdonald](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@markmcdonald](https://forum.generic-mapping-tools.org/u/markmcdonald)\
**Post date:** [July 7, 2020, 3:04pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/9 "2020-07-07T15:04:19Z")

</div>

> [@markmcdonald](#):
>
> EPSG

My ultimate goal is to extract bathymetric profiles for acoustic propagation models. I tried:  
gmt grdproject nzbathymetry\_2016\_ascii-grid.asc -GNZLL.nc -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.

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [July 7, 2020, 3:56pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/10 "2020-07-07T15:56:57Z")

</div>

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

```auto
gmt grdproject nzbathymetry_2016_ascii-grid.asc -GNZLL.nc -J3994 -I -C -F

```

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

---

<div class="post-metadata">

**Author:** ![markmcdonald](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@markmcdonald](https://forum.generic-mapping-tools.org/u/markmcdonald)\
**Post date:** [July 7, 2020, 4:25pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/11 "2020-07-07T16:25:07Z")

</div>

It is closer, but not right yet.  
gmt grdinfo NZLL.nc  
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 [NZLL.nc]  
NZLL.nc: Title: Produced by grdproject  
NZLL.nc: Command: grdproject nzbathymetry\_2016\_ascii-grid.asc -GC:\Users\mark\WhaleAcoust\Hikurangi\map\GMT\NZLL.nc -J+3994 -I -C -F  
NZLL.nc: Remark:  
NZLL.nc: Pixel node registration used [Geographic grid]  
NZLL.nc: Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7  
NZLL.nc: x\_min: 157.000000576 x\_max: 193.001585358 x\_inc: -0.0267413680438 name: longitude n\_columns: 12116  
NZLL.nc: y\_min: -57.4999382033 y\_max: -23.9993740265 y\_inc: 0.00217663336864 name: latitude n\_rows: 15391  
NZLL.nc: z\_min: 0 z\_max: 0 name: z  
NZLL.nc: scale\_factor: 1 add\_offset: 0  
NZLL.nc: format: netCDF-4 chunk\_size: 129,129 shuffle: on deflation\_level: 3  
GEOGCS[“unknown”,  
DATUM[“Unknown based on WGS84 ellipsoid”,  
SPHEROID[“WGS 84”,6378137,298.257223563,  
AUTHORITY[“EPSG”,“7030”]]],  
PRIMEM[“Greenwich”,0,  
AUTHORITY[“EPSG”,“8901”]],  
UNIT[“degree”,0.0174532925199433,  
AUTHORITY[“EPSG”,“9122”]],  
AXIS[“Longitude”,EAST],  
AXIS[“Latitude”,NORTH]]

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [July 7, 2020, 4:45pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/12 "2020-07-07T16:45:02Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![markmcdonald](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@markmcdonald](https://forum.generic-mapping-tools.org/u/markmcdonald)\
**Post date:** [July 7, 2020, 5:01pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/13 "2020-07-07T17:01:25Z")

</div>

[https://niwa.co.nz/our-science/oceans/bathymetry/download-the-data](https://niwa.co.nz/our-science/oceans/bathymetry/download-the-data)  
I am not sure the original has the correct registration. The bathymetry data is also available other places which offer more info on it:

> **[ArcGIS](https://www.arcgis.com/home/item.html?id=a2582b1eb3584237a3b50418f379ca84)**

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [July 7, 2020, 5:36pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/14 "2020-07-07T17:36:38Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![markmcdonald](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@markmcdonald](https://forum.generic-mapping-tools.org/u/markmcdonald)\
**Post date:** [July 7, 2020, 6:26pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/15 "2020-07-07T18:26:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [July 8, 2020, 8:47am UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/16 "2020-07-08T08:47:50Z")

</div>

Try

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

```

---

<div class="post-metadata">

**Author:** ![markmcdonald](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@markmcdonald](https://forum.generic-mapping-tools.org/u/markmcdonald)\
**Post date:** [July 8, 2020, 12:34pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/17 "2020-07-08T12:34:41Z")

</div>

The arcgis site suggests the bounds should be  
West longitude: 161.15  
East longitude: 179.695  
North latitude: -31.329  
South latitude: -49.249  
but  
gmt grdinfo nzbat\_geo.nc  
grdinfo [WARNING]: Guessing of registration in conflict between x and y, using gridline  
nzbat\_geo.nc: Title: GDAL Band Number 1  
nzbat\_geo.nc: Command: Wed Jul 08 06:15:41 2020: GDAL Create(nzbat\_geo.nc, … )  
nzbat\_geo.nc: Remark:  
nzbat\_geo.nc: Gridline node registration used [Geographic grid]  
nzbat\_geo.nc: Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7  
nzbat\_geo.nc: x\_min: 157.001255882 x\_max: 193.00091029 x\_inc: 0.00251061122869 name: longitude n\_columns: 14340  
nzbat\_geo.nc: y\_min: -57.4997149565 y\_max: -24.0006293321 y\_inc: 0.00251061122869 name: latitude n\_rows: 13344  
nzbat\_geo.nc: z\_min: 0 z\_max: 0 name: GDAL Band Number 1  
nzbat\_geo.nc: scale\_factor: 1 add\_offset: 0  
nzbat\_geo.nc: format: classic

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [July 8, 2020, 1:58pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/18 "2020-07-08T13:58:06Z")

</div>

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

 ![image](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/1X/20014a1d269f8ce56bd9662d32ebbe773fcbc574.jpeg)

---

<div class="post-metadata">

**Author:** ![markmcdonald](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@markmcdonald](https://forum.generic-mapping-tools.org/u/markmcdonald)\
**Post date:** [July 8, 2020, 4:47pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/19 "2020-07-08T16:47:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [July 8, 2020, 5:15pm UTC](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609/20 "2020-07-08T17:15:36Z")

</div>

That was just a screen capture of an image using [Mirone](http://joa-quim.pt/mirone). To do it with GMT you would use (classical mode)

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

```

or with the GMT julia (`nzbat_geo.nc` is the name I gave to the converted grid)

```auto
 imshow("nzbat_geo.nc", limits=(177.5, 178.5, -39.5, -38.8), shade=true, coast=true, fmt=:png, show=true)

```

it gives this

 ![GMTjl_tmp](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/1X/a7855bf9405f92642314c8a3b8eaa998837eac4b.png)

[Next page](https://forum.generic-mapping-tools.org/t/grdconvert-will-not-accept-r-option/609.md?page=2)
