0

I want to apply a color to an geotiff image (which contains only elevation and coordinates info) based on the elevation data . How to do that using GDAL in c++.? Is there any example related to this?

SUD2193
  • 139
  • 1
  • 2
  • 7

2 Answers2

2

gdaldem (color-relief) helps me to apply color for geotiff image based on height value.

Eg: gdaldem color-relief <"input"> <"color_relief_text_file"> <"output">

color_relief_text_file => text file (should contain elevation data , R value,G vale,B value) e.g 0 255 255 255 130 250 120 20 150 10 25 60

For more information about gdaldem (color-relief): http://www.gdal.org/gdaldem.html#gdaldem_color_relief

GDALDEMProcessing() is corresponding C++ API function

About GDALDEMProcessing(): http://www.gdal.org/gdal__utils_8h.html#a5d8486d2fd4a7a39bc954eb7f4410053

SUD2193
  • 139
  • 1
  • 2
  • 7
  • Hi SUD, Hi Friends, can anybody give an example of the color_relief_text_file in more detail? Should it be single line or multiple line? Thanks – Santosa Sandy Jan 17 '18 at 09:47
  • Hi Santosa.. I hope this link will help you http://tilemill-project.github.io/tilemill/docs/guides/terrain-data/

    I used multiple line color_relief_text_file. I haven't used single line file. But the order is elevation data, R value,G Value & B Value

    – SUD2193 Jan 18 '18 at 07:34
  • 1
    It should be Multiple line file – SUD2193 Jan 18 '18 at 08:27
1

This C++ repository (https://github.com/khafen74/raster2png) was developed to convert GeoTiffs to colored PNG images using GDAL.

You can create a GDAL color table like so:

colorTable = new GDALColorTable(GPI_RGB);

Then create color entries and make a color ramp.

nTansparency = 0;
GDALColorEntry blk, wht;
blk.c1 = 0, blk.c2 = 0, blk.c3 = 0, blk.c4 = nTransparency;
wht.c1 = 255, wht.c2 = 255, wht.c3 = 255, wht.c4 = nTransparency;

colorTable->CreateColorRamp(1, &blk, 255, &wht);

This file contains code to create a color ramp and apply it to a raster band. (https://github.com/khafen74/raster2png/blob/master/renderer.cpp).

khafen
  • 480
  • 2
  • 11