Skip to content

GDAL Export Format

The GDAL exporter creates text files compatible with GDAL’s gdaldem color-relief command.

PropertyValue
Identifiergdal
Extension.txt
Use caseGDAL raster coloring

The output is a text file with one color entry per line. By default, the output includes a nodata (nv) line but no comments:

nv 0 0 0 0
0.0 68 1 84 255
1.0 68 2 85 255
2.0 68 3 87 255
...
255.0 253 231 37 255

When using verbose mode (-v), comments are included:

# GDAL Color Relief File generated by Palettize
# Colormap name: viridis
# Domain: [0, 255], Scaler: linear
# Interpolation Space for Colormap: oklch
nv 0 0 0 0
0.0 68 1 84 255
...

Each line has the format: value R G B A

Terminal window
# Basic export (includes nv line by default)
palettize create viridis --format gdal --output viridis.txt --domain 0,255
# With verbose comments
palettize create viridis -f gdal -o viridis.txt --domain 0,255 -v
# Custom number of colors
palettize create viridis -f gdal -o viridis.txt --domain 0,255 --steps 256
# Without nodata line
palettize create viridis -f gdal -o viridis.txt --domain 0,255 -O nodata=false
# Custom nodata value
palettize create viridis -f gdal -o viridis.txt --domain 0,255 \
-O nodata_value=-9999 -O "nodata_color=0,0,0,0"
from palettize import create_colormap, get_scaler_by_name, get_exporter
cmap = create_colormap(preset="viridis")
scaler = get_scaler_by_name("linear", domain_min=0, domain_max=255)
exporter = get_exporter("gdal")
output = exporter.export(
colormap=cmap,
scaler=scaler,
domain_min=0,
domain_max=255,
options={"num_colors": 256}
)
# Save to file
with open("viridis.txt", "w") as f:
f.write(output)
OptionTypeDefaultDescription
num_colorsint256Number of color steps to generate
nodatabooltrueInclude nv 0 0 0 0 line by default
nodata_valuefloat | str"nv"NoData value. Use "nv" for GDAL keyword or a numeric value
nodata_colortuple[int,int,int,int](0,0,0,0)RGBA color for NoData
verboseboolfalseInclude comment header lines (set automatically by -v flag)

Once exported, use with gdaldem:

Terminal window
# Generate color-relief image
gdaldem color-relief input.tif viridis.txt output_colored.tif
# With other options
gdaldem color-relief input.tif viridis.txt output.tif \
-of GTiff -co COMPRESS=LZW

By default, the GDAL exporter includes an nv 0 0 0 0 line for transparent nodata handling. GDAL’s nv keyword applies to any nodata value defined in the raster.

Terminal window
# Default behavior includes nv line
palettize create viridis -f gdal -o viridis.txt --domain 0,255
# Disable nodata line
palettize create viridis -f gdal -o viridis.txt --domain 0,255 -O nodata=false
# Specify a numeric NoData value instead of nv
palettize create viridis -f gdal -o viridis.txt --domain 0,255 \
-O nodata_value=-9999 -O "nodata_color=0,0,0,0"

The NoData line appears before the color entries:

nv 0 0 0 0
0.0 68 1 84 255
...