How to create and reproject geotiffs from data and png images

Hallo group. I have completed the tutorials and read through the documentation but my simple needs don't seem to be included in the examples. I am moving from GDAL to GMT and cannot work out the basics of taking a png image and creating a geotiff from data. Then reprojecting to a new geotiff output.

I will eventually be posting a tutorial to the xPlanet forum.

Hi, welcome to GMT(s) (you also should give a look to the wrappers)

I can’t say you started with an easy one, but doable. Since the starting image is a png it knows nothing about coordinates, which is a must when going to GeoTFF. The solution is to use grdimage -Dr -A -R... where you pass the coordinates via the -R option. If those coordinates are geographic, things should go smooth and maybe even -J will let you reproject on the fly (not sure on this one though). If those coordinates are already Cartesian’s (from some projection) then things may become a bit more complicated because the referencing system must somehow be passed to the GeoTIFF file.

the irony is that grdimage -Dr seems calling gdal according to the docs, while the topic starter announced “moving from GDAL to GMT” whatever it means.
This way using gdal_translate may be good enough, capable of assigning any Cartesian crs among other things, e.g. or image processing - convert PNG to GeoTIFF with GDAL - Stack Overflow. Seems quite straightforward esp if no complex georeferencing is required, but I did not try that myself.

Agree that if only a png -> GeoTIFF is wished, gdal_translate or gdalwarp is probably simpler.

Thank you for such a quick reply. I will rewrite my bash according to your notes and let you know how it goes.
The problem I had with gdalwarp was with reprojecting an orthographic geotiff back to plate-carree whenever the map encompassed latitudes above 80 Degrees. The output geotiff always gets truncated at that latitude.
This is my first week with GMT and I couldn’t find the option to output a tiff. It all comes out PDF with no encapsulated images. I feel I must be overlooking the obvious but I’ve gone all squinty eyed searching the docs and tuts. ciao, – Molly

The following produces a tiff map. It can be png etc, see more below. Pdf is produced by default.

gmt begin GMT_tut_5 tiff
	gmt set GMT_THEME cookbook
	gmt coast -Rg -JG280/30/6i -Bag -Dc -A5000 -Gwhite -SDarkTurquoise
gmt end show

see more of the gory details here

That is not a good example. In GMT only grdimage -A and psconvert -W create GeoTIFF files. The above uses Ghostscript to rasterize the PostScript file and produce a regular tif file that knows nothing about spatial coordinates. And although only a convention, .tiff should only be used to indicate that the tif file is a GeoTIFF.

1 Like

I was judging by the question (“It all comes out PDF with no encapsulated images”) and the context (“I have completed the tutorials and read through the documentation…”)

If my idea happened to be wrong then yours might be useful or more specific questions will be asked soon.

no big problem either way.

1 Like

OK, and my reply was still on the context of producing GeoTIFFs.
No problem either too.

Please accept my apologies for such a poorly worded question. I needed both answers you’ve given, Thank you. I have been through the documentation and tutorials but the syntax is quite different to what I’ve been working with. I’m a bit muddled now. I ought to settle my brain down a bit before I dive back in and ask my foolish questions. Ciao, – Molly

There is nothing to apologize for. Driving in the GMT docs is a work. Not because is not good but because it has so many things.

Hallo GMT group. This is one reason I am exploring GMT as an alternative:

These commands demonstrate a possible bug in gdalwarp
Failure to reproject to plate-carree +90 to -90
Unexplained truncation at +/-80

Create a square test png using built-in IM LOGO image.
Convert it to a proper Orthographic Geotiff.
Reproject orthographic to Equirectangular.
Reproject to Azimuthal Equidistant.

Version – Linux 6.5.0-14-generic 22.04.1-Ubuntu
Version – GDAL 3.4.1, released 2021/12/27
Version – ImageMagick (convert) 6.9.11-60
Version – GMT 6.3.0

convert logo: -alpha on -scale 800x600 -set label “ordinary-png” ordinary.png

convert ordinary.png -crop 600x600+100+0 ordinary-square.png

gdal_translate -of Gtiff -a_ullr -1666666 1666666 1666666 -1666666 -a_srs “+proj=ortho +ellps=WGS84 +datum=WGS84 +lat_0=85 +lon_0=-30” ordinary-square.png orthographic-image.tif

gdalwarp -t_srs “+proj=longlat +datum=WGS84 +ellps=WGS84 +units=m” orthographic-image.tif eqc-image.tif

gdalwarp -t_srs “+proj=aeqd +datum=WGS84 +ellps=WGS84 +units=m” eqc-image.tif azimuthal-image.tif

convert azimuthal-image.tif -scale 600x600 azimuthal-image.png


For this question I really suggest that you post it on the GDAL list. GDAL is very robust and is not unlikely that this is an user issue. If you image is small GDAL heuristics to determine the projected limits may lead to that truncation.
And help people by posting an reproducible example. For example I have no idea what is

Create a square test png using built-in IM LOGO image.