# Creating a GeoTIFF using \`gmt coast\` fails for some regions

**URL:** <https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633>\
**Category:** Q&A\
**Created:** [December 8, 2024, 4:55pm UTC](https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633 "2024-12-08T16:55:30Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefanfis](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@stefanfis](https://forum.generic-mapping-tools.org/u/stefanfis)\
**Post date:** [December 8, 2024, 4:55pm UTC](https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633/1 "2024-12-08T16:55:30Z")

</div>

I’m creating maps using the `gmt coast` command and want them to export to GeoTIFF files for further processing in other tools like QGIS. Working on lots of country maps, I came across this “bad” region where the created GeoTIFF doesn’t correctly align with e.g. QGIS using the coastline data from Natural Earth. Here’s the code I’m using:

```
BAD_AREA=-5.5/41.9/9.0/51.8+r
gmt begin test_bad ps
gmt coast -R${BAD_AREA} -JM576p -S#a0d2dc
gmt coast -R${BAD_AREA} -JM576p -G#c0a0a0
gmt end
gmt psconvert test_bad.ps -Z -W+g -Tt

```

The strange thing is, using nearly the same region, the GeoTIFF I get fits perfectly:

```
GOOD_AREA=-5.5/41.9/9.0/51.9+r
gmt begin test_good ps
gmt coast -R${GOOD_AREA} -JM576p -S#a0d2dc
gmt coast -R${GOOD_AREA} -JM576p -G#c0a0a0
gmt end
gmt psconvert test_good.ps -Z -W+g -Tt

```

I’ve also tried to explicitly set page size and both possible orientations, but I keep getting these warnings for the “bad” region:

```
coast [WARNING]: Changing to PostScript landscape orientation based on your plot and paper dimensions, but we cannot be 100% sure.
coast [WARNING]: Use PS_MEDIA and/or PS_PAGE_ORIENTATION to specify correct paper dimensions and/or orientation if our guesses are inadequate.

```

**My questions:**

1. Am I right this has something to do with the landscape orientation warning?
2. How can I set PS\_MEDIA and/or PS\_PAGE\_ORIENTATION in modern mode?
3. Is there another way to create GeoTIFF files as a workaround? In my “real” application, I use a lot of `grdimage`, `coast` and `plot` commands.

I’m using _gmt 6.5.0_ on macOS.

Here are the result of the commands from above, added as QGIS layers and with the `ne_10m_coastline` as a red overlay.

* * *

_The bad result:_

 ![test_bad](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/a/a2b9dabd1624e3be87c0051b3a5bdf3d9a354ce6.png)

_The good result:_

 ![test_good](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/2/2cf9444988194e7c968b7c59922c1b2e910ca5e4.png)

---

<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:** [December 8, 2024, 11:12pm UTC](https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633/2 "2024-12-08T23:12:20Z")

</div>

Indeed something fishy is going on in modern mode here.

The solution is to use `eps`

```auto
gmt coast -R-5.5/41.9/9.0/51.8+r -JM576p -G#c0a0a0 -eps lixo

```

or classic mode, but here the `PS_MEDIA` has to be increased. The messages about increasing `PS_MEDIA` in modern mode are also wrong as in that mode either `PS_MEDIA` or `PS_PAGE_ORIENTATION` are not available. (we print on 11 m square paper and crop the whites).

```auto
gmt pscoast -R-5.5/41.9/9.0/51.8+r -JM576p -G#c0a0a0 -P > lixo.ps
pscoast [WARNING]: Your plot (WxH = 20.32 x 20.31 cm) placed at (2.54, 2.54 cm) may exceed your PS_MEDIA (WxH = 20.99 x 29.70 cm)

```

---

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://forum.generic-mapping-tools.org/u/Andreas)\
**Post date:** [December 9, 2024, 6:57am UTC](https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633/3 "2024-12-09T06:57:19Z")

</div>

Why does the 0.1 difference in latitude trigger this?  
And why does making an eps help?

I thought this may be a ‘spherical vs. ellipsoidal’ issue, but obvously not, if making an eps can fix it.

---

<div class="post-metadata">

**Author:** ![stefanfis](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@stefanfis](https://forum.generic-mapping-tools.org/u/stefanfis)\
**Post date:** [December 9, 2024, 11:58am UTC](https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633/4 "2024-12-09T11:58:43Z")

</div>

Thanks so far for trying to help me.

What does `-eps` do? I can’t find anything about it in the docs.

> The solution is to use eps  
> gmt coast -R-5.5/41.9/9.0/51.8+r -JM576p -G#c0a0a0 -eps lixo

Using this option, I get this error:

```
gmt [ERROR]: Cannot run a one-liner modern command within an existing modern mode session

```

Obviously, I’m using it not correctly…

* * *

> Why does the 0.1 difference in latitude trigger this?

It seems that little difference leads to completely different image dimensions. For the “bad” version, `psconvert` says:

```
Input file size is 2400, 2180

```

While on the “good” version, it says:

```
Input file size is 2401, 2426

```

---

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://forum.generic-mapping-tools.org/u/Andreas)\
**Post date:** [December 9, 2024, 3:01pm UTC](https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633/5 "2024-12-09T15:01:26Z")

</div>

Your good vs. bad area differs by 10 degrees in the latitude. I was very confused sometimes when **mapproject** would choose a ‘spherical solution’ since my region was ‘big’, and that was due to a region being larger than ‘10 degrees of central meridian’ when using the UTM projection.

See [Select Ellipsoidal versus Spherical Solution](https://docs.generic-mapping-tools.org/dev/mapproject.html#select-ellipsoidal-versus-spherical-solution) for more.

Probably not related, but thought I’d mention 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:** [December 9, 2024, 4:52pm UTC](https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633/6 "2024-12-09T16:52:40Z")

</div>

> [@Andreas](#):
>
> Why does the 0.1 difference in latitude trigger this?  
> And why does making an eps help?

Ah, those are the debugging questions.

---

<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:** [December 9, 2024, 4:54pm UTC](https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633/7 "2024-12-09T16:54:27Z")

</div>

> [@stefanfis](#):
>
> Using this option, I get this error:
> 
> ```auto
> gmt [ERROR]: Cannot run a one-liner modern command within an existing modern mode session
> 
> ```
> 
> Obviously, I’m using it not correctly…

Unrelated to this problem. It means a previous modern mode command did not finish cleanly and left over stray files. Do a

```auto
gmt clear sessions

```

---

<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:** [December 9, 2024, 4:55pm UTC](https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633/8 "2024-12-09T16:55:35Z")

</div>

> [@stefanfis](#):
>
> What does `-eps` do? I can’t find anything about it in the docs.

It creates the output in eps format. Those things are documented in the `psconvert -T` man page.

---

<div class="post-metadata">

**Author:** ![stefanfis](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@stefanfis](https://forum.generic-mapping-tools.org/u/stefanfis)\
**Post date:** [December 9, 2024, 5:16pm UTC](https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633/9 "2024-12-09T17:16:14Z")

</div>

In the meantime, I made another observation: As a test, I created maps for all countries in South America and in Europe, using some custom bounding boxes from my database as region values. From the 58 maps, 54 maps were correct, but 4 maps were wrong: France, Croatia, Poland and Brazil. Here are the commands I used:

```
gmt coast -R-5.4833080335/41.9448976164/9.0102354535/51.4814569985+r -JM576p -G#c0a0a0
gmt coast -R13.0629568234/42.167624323/19.6006902118/46.7825392115+r -JM576p -G#c0a0a0
gmt coast -R13.1552333516/48.7018341646/24.5652703032/55.161944894+r -JM576p -G#c0a0a0
gmt coast -R-80.0/-35.0/-32.0/8.0+r -JL-56.0/-13.5/-13.5/-13.5/576p -G#c0a0a0

```

These four maps have one thing in common: All four have the same size of 2400x2180 pixels, while none of the other 54 maps has that size.  
The nearest map has been for Belarus with 2400x2164 pixels. This map is correct, though.

---

<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:** [December 9, 2024, 5:29pm UTC](https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633/10 "2024-12-09T17:29:01Z")

</div>

> [@Joaquim](#):
>
> It means a previous modern mode command did not finish cleanly and left over stray files.

The topic starter apparently adds `-eps` to the commands inside his modern mode session. This is not supposed to work. `-eps` is for one-liners like the one @Joaquim showed in his post.

instead you could try something like

```auto
BAD_AREA=-5.5/41.9/9.0/51.8+r
gmt begin test_bad eps
  gmt coast -R${BAD_AREA} -JM576p -S#a0d2dc -G#c0a0a0
gmt end
gmt psconvert test_bad.eps -Z -W+g -Tt

```

(or just a one-liner `gmt coast -R${BAD_AREA} -JM576p -S#a0d2dc -G#c0a0a0 -eps test_bad`)

BTW adding psconvert options to `gmt begin`, like `gmt begin test_bad tiff Z,W+g,-Tt`, does not add GIS header to the tiff, only combination above works `gmt begin test_bad eps`+`gmt psconvert test_bad.eps -Z -W+g -Tt` and it obviously calls `gdal` as the below is on the output, while `gmt begin ...` does not:

```auto
Input file size is 2401, 2399
0...10...20...30...40...50...60...70...80...90...100 - done.

```

---

<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:** [December 9, 2024, 5:35pm UTC](https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633/11 "2024-12-09T17:35:36Z")

</div>

> [@stefanfis](#):
>
> These four maps have one thing in common: All four have the same size of 2400x2180 pixels, while none of the other 54 maps has that size.  
> The nearest map has been for Belarus with 2400x2164 pixels. This map is correct, though.

This is how Mercator projection works when defined with `-JM...` I believe: horizontal map size will be the same with `-JM576p`, while vertical size will not be the same, as the scale (dots per degree latitude) will be different, as defined by the projection.

---

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://forum.generic-mapping-tools.org/u/Andreas)\
**Post date:** [December 9, 2024, 5:37pm UTC](https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633/12 "2024-12-09T17:37:13Z")

</div>

Werent the vertical amount of pixels the same too?

---

<div class="post-metadata">

**Author:** ![stefanfis](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@stefanfis](https://forum.generic-mapping-tools.org/u/stefanfis)\
**Post date:** [December 9, 2024, 5:40pm UTC](https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633/13 "2024-12-09T17:40:16Z")

</div>

> [@mkononets](#):
>
> The topic starter apparently adds `-eps` to the commands inside his modern mode session. This is not supposed to work. `-eps` is for one-liners like the one @Joaquim showed in his post.
> 
> instead you could try something like
> 
> ```auto
> BAD_AREA=-5.5/41.9/9.0/51.8+r
> gmt begin test_bad eps
> gmt coast -R${BAD_AREA} -JM576p -S#a0d2dc -G#c0a0a0
> gmt end
> gmt psconvert test_bad.eps -Z -W+g -Tt
> 
> ```

Yes, that’s been my problem. I completely misunderstood what @Joaquim tried to tell me. Thank you both for your help! With your code, everything works as expected. 🙂

So, when using an EPS file instead of a PS file, the conversion step to create a GeoTIFF works for all my maps. Great!

---

<div class="post-metadata">

**Author:** ![stefanfis](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@stefanfis](https://forum.generic-mapping-tools.org/u/stefanfis)\
**Post date:** [December 9, 2024, 5:54pm UTC](https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633/14 "2024-12-09T17:54:39Z")

</div>

> [@mkononets](#):
>
> > [@stefanfis](#):
> >
> > These four maps have one thing in common: All four have the same size of 2400x2180 pixels, while none of the other 54 maps has that size.  
> > The nearest map has been for Belarus with 2400x2164 pixels. This map is correct, though.
> 
> This is how Mercator projection works when defined with `-JM...` I believe: horizontal map size will be the same with `-JM576p`, while vertical size will not be the same, as the scale (dots per degree latitude) will be different, as defined by the projection.

I’m not surprised that the width of all the maps are identical. I’ve been surprised by the fact that the incorrect maps had the exact same dimensions of 2400x2180 pixels. Especially when looking at the Brazil example where I didn’t even use Mercator, but the Lambert Conformal Conic projection.

I’ve compiled the sizes of the correct maps (that I get when I use EPS) and compared them to the dimensions of the incorrect maps:

```auto
country size with PS size with EPS
------- ------------ -------------
France 2400x2180 2401x2305
Croatia 2400x2180 2401x2369
Poland 2400x2180 2401x2204
Brazil 2400x2180 2401x2245

```

Perhaps this may be helpful when debugging the underlying problem.

---

<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:** [December 9, 2024, 6:01pm UTC](https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633/15 "2024-12-09T18:01:25Z")

</div>

Oh, this does not look right.

---

<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:** [December 10, 2024, 2:14am UTC](https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633/16 "2024-12-10T02:14:13Z")

</div>

Can you please summarize this into an issue? Otherwise risk is that this will be lost.

---

<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:** [December 13, 2024, 3:06pm UTC](https://forum.generic-mapping-tools.org/t/creating-a-geotiff-using-gmt-coast-fails-for-some-regions/5633/17 "2024-12-13T15:06:43Z")

</div>

After all, I don’t think there a “failure for some regions”. The point is that the `ps` indeed requires that we set the paper size when the map overflows A4 in Portrait (which is the case in the failures). If we do

```auto
gmt coast -R-5.5/41.9/9.0/51.8+r -JM576p -G#c0a0a0 -ps lixo --PS_MEDIA=A3

```

there are no warnings and the generated GeoTIFF is correct. It’s the `ps` itself that seems to have wrong BoundingBox that clips it a bit. Oveall, using `ps` in modern mode doesn’t seem to be a very good idea.
