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:
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:
Am I right this has something to do with the landscape orientation warning?
How can I set PS_MEDIA and/or PS_PAGE_ORIENTATION in modern mode?
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.
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).
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)
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.
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:
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.
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
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:
Input file size is 2401, 2399
0...10...20...30...40...50...60...70...80...90...100 - done.
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.
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!
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:
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.
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
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.