Re: Using GMT CPT file with gdal raster color
Even Rouault via gdal-dev <[email protected]> Sun, 17 May 2026 23:43:09 +0200
| Newsgroups | gmane.comp.gis.gdal.devel |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format. --===============0798580962648772559== Content-Type: multipart/alternative; boundary="------------Uppz7EjrGRC0WUcA0zZcZE9f" Content-Language: en-US This is a multi-part message in MIME format. --------------Uppz7EjrGRC0WUcA0zZcZE9f Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Sean, thanks for the report. Support for GMT .cpt files dates back to 2010 and hasn't evolved much since. So I assume GMT .cpt format might have changed a bit since then. I've submitted a fix in https://github.com/OSGeo/gdal/pull/14595 to support new files. In the mean time you can manually adjust your .cpt file to please current released GDAL versions by: - replacing slashed with space - and removing the trailing " L" Even Le 17/05/2026 à 22:24, Sean King via gdal-dev a écrit : > Hi folks, > > I'm using GMT version 6.6.0 and GDAL version 3.12.4. I have > several CPT files that I generated in GMT using the makecpt command, > such as: > > */gmt makecpt -T-120/120/10 -I -Crainbow -Z -Fr/* > > which generates the attached file. Then, I am trying to apply that > color palette to a TIFF file using 'gdal raster color'. The > documentation <https://gdal.org/en/stable/programs/gdaldem.html> > states that > > */GMT .cpt palette files are also supported (COLOR_MODEL = RGB only)./* > > however, I continually get the error of > > */ERROR 1: No color association found in test.cpt/* > */ > /* > When I dug into the GDAL source code for the GMT CPT parser here > <https://github.com/OSGeo/gdal/blob/b3f839f2515b023e4a7cf099b7ce1626ccb24eac/gcore/gdalcolortable.cpp#L744>, > it really does not seem to match up with the current implementation of > GMT CPT files, even though the GDAL feature was added in the latest > release. For instance, it uses space, comma, tab, and colon as > delimiters, but no matter what flags I use for my GMT CPT generation, > I get a backslash as the delimiter, as seen in the attached file. > There are other inconsistencies as well. > > Am I missing something? I'm somewhat new to GDAL and GMT, so I'd > appreciate any advice. Also, if this feature really to read GMT CPT > files is not adequate, is there a better way to approach this? I > essentially want to colorize a .grd file using gdal, so that I can > then generate map tiles with it. I have the rest of the pipeline > figured out, but I'm having issues with the color mapping. I wrote my > own converter from GMT CPT to GDAL color file, but it's a bit > buggy/hacky. I'm wondering if there is a more 'official' way to do this. > > Thanks! > Sean > > _______________________________________________ > gdal-dev mailing list > [email protected] > https://lists.osgeo.org/mailman/listinfo/gdal-dev -- Very grumpy about LLMs: FOSS is about increasing public capital, not becoming enslaved to private equity of giga corporations -- http://www.spatialys.com My software is free, but my time generally not. --------------Uppz7EjrGRC0WUcA0zZcZE9f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <p>Sean,</p> <p>thanks for the report. Support for GMT .cpt files dates back to 2010 and hasn't evolved much since. So I assume GMT .cpt format might have changed a bit since then. I've submitted a fix in <a class="moz-txt-link-freetext" href="https://github.com/OSGeo/gdal/pull/14595">https://github.com/OSGeo/gdal/pull/14595</a> to support new files. In the mean time you can manually adjust your .cpt file to please current released GDAL versions by:</p> <p>- replacing slashed with space</p> <p>- and removing the trailing " L"</p> <p>Even</p> <div class="moz-cite-prefix">Le 17/05/2026 à 22:24, Sean King via gdal-dev a écrit :<br> </div> <blockquote type="cite" cite="mid:CAAaFaTknK4dWH8ncGt1DHSrxMVHm=5OAgWoO=vHgM=vm=ng5KQ@mail.gmail.com"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <div dir="ltr">Hi folks, <div><br> </div> <div>I'm using GMT version 6.6.0 and GDAL version 3.12.4. I have several CPT files that I generated in GMT using the makecpt command, such as: </div> <div><br> </div> <div><b><i>gmt makecpt -T-120/120/10 -I -Crainbow -Z -Fr</i></b></div> <div><br> </div> <div>which generates the attached file. Then, I am trying to apply that color palette to a TIFF file using 'gdal raster color'. The <a href="https://gdal.org/en/stable/programs/gdaldem.html" moz-do-not-send="true">documentation</a> states that </div> <div><br> </div> <div><b><i>GMT .cpt palette files are also supported (COLOR_MODEL = RGB only).</i></b></div> <div><br> </div> <div>however, I continually get the error of </div> <div><br> </div> <div><b><i>ERROR 1: No color association found in test.cpt</i></b></div> <div><b><i><br> </i></b></div> <div>When I dug into the GDAL source code for the GMT CPT parser <a href="https://github.com/OSGeo/gdal/blob/b3f839f2515b023e4a7cf099b7ce1626ccb24eac/gcore/gdalcolortable.cpp#L744" moz-do-not-send="true">here</a>, it really does not seem to match up with the current implementation of GMT CPT files, even though the GDAL feature was added in the latest release. For instance, it uses space, comma, tab, and colon as delimiters, but no matter what flags I use for my GMT CPT generation, I get a backslash as the delimiter, as seen in the attached file. There are other inconsistencies as well.</div> <div><br> </div> <div>Am I missing something? I'm somewhat new to GDAL and GMT, so I'd appreciate any advice. Also, if this feature really to read GMT CPT files is not adequate, is there a better way to approach this? I essentially want to colorize a .grd file using gdal, so that I can then generate map tiles with it. I have the rest of the pipeline figured out, but I'm having issues with the color mapping. I wrote my own converter from GMT CPT to GDAL color file, but it's a bit buggy/hacky. I'm wondering if there is a more 'official' way to do this.</div> <div><br> </div> <div>Thanks!</div> <div>Sean</div> </div> <br> <fieldset class="moz-mime-attachment-header"></fieldset> <pre wrap="" class="moz-quote-pre">_______________________________________________ gdal-dev mailing list <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a> <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/gdal-dev">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a> </pre> </blockquote> <pre class="moz-signature" cols="72">-- Very grumpy about LLMs: FOSS is about increasing public capital, not becoming enslaved to private equity of giga corporations -- <a class="moz-txt-link-freetext" href="http://www.spatialys.com">http://www.spatialys.com</a> My software is free, but my time generally not.</pre> </body> </html> --------------Uppz7EjrGRC0WUcA0zZcZE9f-- --===============0798580962648772559== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ gdal-dev mailing list [email protected] https://lists.osgeo.org/mailman/listinfo/gdal-dev --===============0798580962648772559==--