# How to generate a lat/long geotiff with grdimage

**URL:** <https://forum.generic-mapping-tools.org/t/how-to-generate-a-lat-long-geotiff-with-grdimage/4780>\
**Category:** Q&A\
**Created:** [April 9, 2024, 12:42am UTC](https://forum.generic-mapping-tools.org/t/how-to-generate-a-lat-long-geotiff-with-grdimage/4780 "2024-04-09T00:42:47Z")\
**Posts on this page:** 11\
**Page:** 2

<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:** [April 9, 2024, 11:59pm UTC](https://forum.generic-mapping-tools.org/t/how-to-generate-a-lat-long-geotiff-with-grdimage/4780/21 "2024-04-09T23:59:12Z")

</div>

> [@Brent](#):
>
> And I just tried your grdimage/psconvert as above - that also worked, on Linux natively. Gave an image that overlays with QGIS.
> 
> If I then run: _gdal\_edit.py -a\_crs EPSG:4326 test.tiff_

No need for the `gdal_edit` step with the `psconvert` way.

Good that it works now. Indeed it’s strange why it failed before. Worked for me on WSL too.

Glad that it works now

---

<div class="post-metadata">

**Author:** ![Brent](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@Brent](https://forum.generic-mapping-tools.org/u/Brent)\
**Post date:** [April 10, 2024, 2:30am UTC](https://forum.generic-mapping-tools.org/t/how-to-generate-a-lat-long-geotiff-with-grdimage/4780/22 "2024-04-10T02:30:06Z")

</div>

If I don’t apply the gdal\_edit step, the geotiff crs is unknown (from gdalinfo), but the coords are correct. After that step, gdalinfo gives the correct crs data, so I prefer to apply that step for a complete solution.

Cheers

---

<div class="post-metadata">

**Author:** ![Brent](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@Brent](https://forum.generic-mapping-tools.org/u/Brent)\
**Post date:** [April 10, 2024, 3:17am UTC](https://forum.generic-mapping-tools.org/t/how-to-generate-a-lat-long-geotiff-with-grdimage/4780/23 "2024-04-10T03:17:37Z")

</div>

And not as rosy as I thought… and I think this identifies the problem (or helps at least)…

I’m using on Linux (as suggested by Joaquim):

_gmt grdimage @earth\_gebco\_05m\_g -P -J4326 \> world.ps_  
_gmt psconvert world.ps 1W+g_  
_# add the edit to set CRS_  
_gdal\_edit.py -a\_crs EPSG:4326 world.tiff_

It works with no errors for resolutions lower than or equal to \_06m\_

This is a single grdfile download. I start getting my errors at higher resolutions than this.

At ~\_05m\_g it downloads multiple grids to achieve the global coverage & I get the errors described above. The problem seems to be in the merging of grids, wherever that occurs.

I get this same error under Linux & Windows.

Could you please try this and see if it still works for you…

Brent

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [April 10, 2024, 11:09am UTC](https://forum.generic-mapping-tools.org/t/how-to-generate-a-lat-long-geotiff-with-grdimage/4780/24 "2024-04-10T11:09:49Z")

</div>

I did exactly like I posted above with `01m` data. Those two examples, one assigning CRS using `gdal_edit.py`, the other using `gmt grdedit`. I’ve got exactly the same results, so not posting anything here. `gdal_edit.py` assigned CRS correctly, `gmt grdedit` quietly failed

`gmt grdimage @earth_gebco_01m_p -n+a -Aworld.tiff -J4326` produces error messages like below which seems like gdal errors (gdal seems to be called by `grdimage` internally to produce the .tiff?). However, the resulting images are totally fine.

```auto
ERROR 10: Pointer 'hTransform' is NULL in 'OCTTransform'.

ERROR 10: Pointer 'hTransform' is NULL in 'OCTTransform'.

ERROR 10: Pointer 'hTransform' is NULL in 'OCTTransform'.

More than 1000 errors or warnings have been reported. No more will be reported from now.

```

---

<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:** [April 10, 2024, 1:12pm UTC](https://forum.generic-mapping-tools.org/t/how-to-generate-a-lat-long-geotiff-with-grdimage/4780/25 "2024-04-10T13:12:04Z")

</div>

Yes, I can confirm the troubles when using tiled grids. This silently fails for me, which normally means a crash

```auto
gmt grdimage @earth_relief_05m -JX14/0 -P > lixo.ps # Fine
psconvert lixo.ps -W+g # Silently fails

```

Most weird because the PS file is ok. Note that here I used the GMT syntax `-JX14/0` because I found another problem. While `-J4326` works but assigns no CRS, using a proj4 string does. _i.,e,_ `-J+proj=lonlat`. But in both cases it produces a square image and not even `-J+proj=lonlat'width=14/0` changes that fact.

Current situation indicates that `grdimage -A + gdal_edit` is your best bet.

---

<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:** [April 10, 2024, 1:59pm UTC](https://forum.generic-mapping-tools.org/t/how-to-generate-a-lat-long-geotiff-with-grdimage/4780/26 "2024-04-10T13:59:36Z")

</div>

Found why `grdimage -W+g` fails for tilled grids. The PostScript lacks the necessary `+proj=...` information. Looks like when using tiles something is failing to add that info.

Note that `-JEPSG` or `-J+proj` are normally not supported in grdimage that most of times creates frames too (that’s where proj fails) but without **-B** that is not the case and it should work … but doesn’t.

However, the GMT syntax works. That is, this works

```auto
gmt grdimage @earth_relief_05m -JX14d/0d -P > lixo.ps
gmt psconvert lixo.ps -W+g

```

but still lacks the CRS info.

---

<div class="post-metadata">

**Author:** ![Brent](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@Brent](https://forum.generic-mapping-tools.org/u/Brent)\
**Post date:** [April 11, 2024, 1:52am UTC](https://forum.generic-mapping-tools.org/t/how-to-generate-a-lat-long-geotiff-with-grdimage/4780/27 "2024-04-11T01:52:54Z")

</div>

Thanks, it has been working for me at lower resolutions, but when I try to run it with a higher resolution image/dataset, the tile download fails part way through the set of tiles. I’m not sure why. I figure I can try to download the entire grd file from the server & use it as a local data source. This might also fix the error I get with grdimage & tiled downloads saving directly as TIFF.

_grdblend [NOTICE]: Remote data courtesy of GMT data server oceania [[http://oceania.generic-mapping-tools.org](http://oceania.generic-mapping-tools.org)]_

_grdblend [NOTICE]: Earth Relief at 3x3 arc seconds tiles provided by SRTMGL3 (land only) [NASA/USGS]._  
_grdblend [NOTICE]: → Download 1x1 degree grid tile (earth\_relief\_03s\_g): S28E142_  
_grdblend [ERROR]: Libcurl Error: Couldn’t resolve host name_  
_grdblend [ERROR]: Unable to obtain remote file @S28E142.earth\_relief\_03s\_g.nc_  
_grdblend [NOTICE]: → Download 1x1 degree grid tile (earth\_relief\_03s\_g): S28E142_  
_grdblend [ERROR]: Libcurl Error: Couldn’t resolve host name_  
_grdblend [ERROR]: Unable to obtain remote file @S28E142.earth\_relief\_03s\_g.nc_  
_grdblend [NOTICE]: → Download 1x1 degree grid tile (earth\_relief\_03s\_g): S28E142_  
_grdblend [ERROR]: Libcurl Error: Couldn’t resolve host name_  
_grdblend [ERROR]: Unable to obtain remote file @S28E142.earth\_relief\_03s\_g.nc_  
_grdblend [ERROR]: File @S28E142.earth\_relief\_03s\_g.nc not found_  
_[Session gmt (0)]: Error returned from GMT API: GMT\_FILE\_NOT\_FOUND (16)_  
_grdimage [ERROR]: ERROR - Unable to produce blended grid from /tmp/=tiled\_126\_PO\_cmYEAC_  
_[Session gmt (0)]: Error returned from GMT API: GMT\_GRID\_READ\_ERROR (18)_  
_[Session gmt (0)]: Error returned from GMT API: GMT\_GRID\_READ\_ERROR (18)_  
_[Session gmt (0)]: Error returned from GMT API: GMT\_GRID\_READ\_ERROR (18)_  
_psconvert [ERROR]: world.ps: GMT PS format detected but file is not finalized. Maybe a -K in excess? No output created._

---

<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:** [April 11, 2024, 10:53am UTC](https://forum.generic-mapping-tools.org/t/how-to-generate-a-lat-long-geotiff-with-grdimage/4780/28 "2024-04-11T10:53:18Z")

</div>

Yes, pre-downloading the tiles and assembling them locally will solve the current `psconvert -W+g` issue. I have a fix for it but needs more work.

Regarding the libcurl errors, don’t know, but you can try a mirror. See `GMT_DATA_SERVER` and [Mirrors — The Generic Mapping Tools](https://www.generic-mapping-tools.org/mirrors/)

---

<div class="post-metadata">

**Author:** ![Brent](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@Brent](https://forum.generic-mapping-tools.org/u/Brent)\
**Post date:** [April 12, 2024, 12:11am UTC](https://forum.generic-mapping-tools.org/t/how-to-generate-a-lat-long-geotiff-with-grdimage/4780/29 "2024-04-12T00:11:40Z")

</div>

Hi Joaqim,

I have rsynch’ed the entire server data content locally, but I can’t find info on how the tiled jp2 files are assembled into a whole grd file or image, can you point me at where some instructions are available?

Thanks…

---

<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:** [April 12, 2024, 12:50am UTC](https://forum.generic-mapping-tools.org/t/how-to-generate-a-lat-long-geotiff-with-grdimage/4780/30 "2024-04-12T00:50:17Z")

</div>

Ah, that’s not how one do it. See `gmtwhich -Gc`. It will convert the the .jp2 into netCDF and store them in the cache dir (~./gmt/cache). `grdcut -R -G...` downloads only the necessary tiles (or use the ones in cache) and assembles a grid. Don’t know right now how to use the .jp2 that you already downloaded. Maybe put them in a html server and making `GMT_DATA_SERVER` point to it.

---

<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:** [April 12, 2024, 4:47pm UTC](https://forum.generic-mapping-tools.org/t/how-to-generate-a-lat-long-geotiff-with-grdimage/4780/31 "2024-04-12T16:47:37Z")

</div>

See [Address issues raised in #8438 and more. by joa-quim · Pull Request #8440 · GenericMappingTools/gmt · GitHub](https://github.com/GenericMappingTools/gmt/pull/8440)

[Previous page](https://forum.generic-mapping-tools.org/t/how-to-generate-a-lat-long-geotiff-with-grdimage/4780.md?page=1)
