2

I'm looking to modify the original ColorTable, when georeferencing, PNG => gdal_translate + gdalwarp => TIFF.

gdal_translate -of VRT -a_srs EPSG:4326 ' + file_png + ' ' + file_vrt + ' -a_ullr ' + calc_ullr
gdalwarp -s_srs EPSG:4326 -t_srs EPSG:3857 ' + file_vrt + ' ' + file_tiff

If I open the VRT file and do the edit manually, the output TIFF file is correct. The problem is that I have 524288 files ... so I would like to do the modification automatically, via gdal_translate, but I don't quite understand using the parameters of the command ...

• Original VRT & TIFF files

# VRT
  <VRTRasterBand dataType="Byte" band="1">
    <ColorInterp>Palette</ColorInterp>
    <ColorTable>
      <Entry c1="0" c2="0" c3="255" c4="255" />
      <Entry c1="255" c2="255" c3="255" c4="255" />
      <Entry c1="0" c2="0" c3="0" c4="255" />
        [...]
      <Entry c1="0" c2="0" c3="0" c4="255" />
    </ColorTable>
  </VRTRasterBand>

# TIFF
  Band 1 Block=63153x1 Type=Byte, ColorInterp=Palette
  Color Table (RGB with 256 entries)
    0: 0,0,0,255
    1: 255,255,255,255
    2: 0,0,0,255
      [...]
  255: 0,0,0,255

• Modified VRT and TIFF files

# VRT
  <VRTRasterBand dataType="Byte" band="1">
    <ColorInterp>Palette</ColorInterp>
    <ColorTable>
      <Entry c1="0" c2="0" c3="255" c4="255" />
      <Entry c1="0" c2="255" c3="0" c4="255" />
      <Entry c1="255" c2="0" c3="0" c4="255" />
        [...]
      <Entry c1="255" c2="0" c3="0" c4="255" />
    </ColorTable>
  </VRTRasterBand>

# TIFF
  Band 1 Block=63153x1 Type=Byte, ColorInterp=Palette
  Color Table (RGB with 256 entries)
    0: 0,0,255,255
    1: 0,255,0,255
    2: 255,0,0,255
      [...]
  255: 255,0,0,255

With what settings can I get the VRT & TIFF files the way I want?

1

The functional solution is to use sed.

sed -i '/<Entry c1="0" c2="0" c3="0" c4="255" \/>/,/<Entry c1="255" c2="255" c3="255" c4="255" \/>/d; /<ColorTable>/r COLORTABLE.txt' $F_VRT

Or COLORTABLE.txt contains the values I want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.