如何使用GDAL将色表添加到一个波段的Tiff中?


11

我有1个波段的GeoTIFF文件。带的颜色解释为灰色。我想要一个颜色表,以将其转换Col.tiffCol.jpegCol.png

我尝试通过.vrt在此tiff中放置一个颜色表:

gdal_translate -of VRT  Col.tiff Col.vrt

然后添加.vrt:

<ColorInterp>Palette</ColorInterp>
<ColorTable>
   <Entry c1="0" c2="0" c3="255" c4="240"/>
   <Entry c1="0" c2="0" c3="254" c4="240"/>
   <Entry c1="0" c2="0" c3="253" c4="240"/>
   <Entry c1="0" c2="0" c3="252" c4="240"/>
</ColorTable>

并再次翻译:

gdal_translate Col.vrt Col.tiff

但它回答:

Warning 1: Unable to export color table to GeoTIFF file.  Color tables can only be written to 1 band or 2 bands Byte or UInt16 GeoTIFF files.

我该怎么做?

有关信息,请参见乐队的gdalinfo:

Band 1 Block=55x18 Type=Float64, ColorInterp=Gray
  Description = Something
  Metadata:
    GRIB_COMMENT=Something[p]
    GRIB_ELEMENT=TMP
    GRIB_FORECAST_SECONDS=0 sec
    GRIB_REF_TIME=1401926400 sec UTC
    GRIB_SHORT_NAME=SMTHG
    GRIB_UNIT=[p]
    GRIB_VALID_TIME=1401926400 sec UTC

您的tif有什么最大/最小值?它是Float64,因此该十进制值应如何与调色板的整数值相对应?
2014年

错误表明输出必须为Byte或UInt16类型。也许您应该在gdal_translate命令中添加“ -ot UInt16”。
user30184 2014年

谢谢,它现在可以工作了,我只需要找到漂亮的颜色即可:)
Faquarl 2014年

@AndreJoost我所做的是获取最大/最小值并将它们划分为255个类。然后,对于每个值,我都使用一种颜色。
Faquarl 2014年

最后,我制作了一个Python脚本,用相同的信息制作了一个新的tiff,除了有4个波段(rgba)
Faquarl 2014年

Answers:


5

使用gdal,您可以基于gdal_dem(color_relief)为图像着色

颜色配置文件的语法派生自GRASS r.colors实用程序支持的语法。ESRI HDR颜色表文件(.clr)也与该语法匹配。alpha组件以及制表符和逗号作为分隔符的支持是GDAL特定的扩展

aspect: aspect oriented grey colors
aspectcolr: aspect oriented rainbow colors
bcyr: blue through cyan through yellow to red
bgyr: blue through green through yellow to red
byg: blue through yellow to green
byr: blue through yellow to red
celsius: blue to red for degree Celsius temperature
corine: EU Corine land cover colors
curvature: for terrain curvatures (from v.surf.rst and r.slope.aspect)
differences: differences oriented colors
elevation: maps relative ranges of raster values to elevation color ramp
etopo2: colors for ETOPO2 worldwide bathymetry/topography
evi: enhanced vegetative index colors
gdd: accumulated growing degree days
grey: grey scale
grey.eq: histogram-equalized grey scale
grey.log: histogram logarithmic transformed grey scale
grey1.0: grey scale for raster values between 0.0-1.0
grey255: grey scale for raster values between 0-255
gyr: green through yellow to red
haxby: relative colors for bathymetry or topography
ndvi: Normalized Difference Vegetation Index colors
population: color table covering human population classification breaks
population_dens: color table covering human population density classification breaks
precipitation: precipitation color table (0..2000mm)
precipitation_monthly: precipitation color table (0..1000mm)
rainbow: rainbow color table
ramp: color ramp
random: random color table
rstcurv: terrain curvature (from r.resamp.rst)
rules: create new color table based on user-specified rules read from stdin
ryb: red through yellow to blue
ryg: red through yellow to green
sepia: yellowish-brown through to white
slope: r.slope.aspect-type slope colors for raster values 0-90
srtm: color palette for Shuttle Radar Topography Mission elevation
terrain: global elevation color table covering -11000 to +8850m
wave: color wave

也是在这里看到我的扩展的例子:gis.stackexchange.com/questions/130199/...
安德烈

直接链接到@AndreJ的答案:gis.stackexchange.com/a/132690/49134
汤姆·萨利巴

是的,谢谢,应该将2015年的这些问题标记为重复,但是AndreJ的答案比我的答案还要详细。
radouxju
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.