[GIS] gdalwarp causes ERROR 6: PNG driver doesn’t support 6 bands in gdal2tiles

bandgdal2tilesgdalbuildvrtgdalwarpgeotiff-tiff

I've a problem with my gdalwarp function.

What I've done:

I built a .vrt file from 6 .tif images:

gdalbuildvrt -overwrite /input/base.vrt /home/tiles/BASE/*.tif

My gdalinfo looks like that:

Driver: VRT/Virtual Raster
Files: temp/vrt/base.vrt
       /home/tiles/BASE/17_BASE_1.tif
       /home/tiles/BASE/17_BASE_2.tif
       /home/tiles/BASE/17_BASE_3.tif
       /home/tiles/BASE/17_BASE_4.tif
       /home/tiles/BASE/17_BASE_5.tif
       /home/tiles/BASE/17_BASE_6.tif
Size is 60007, 40007
Coordinate System is `'
Origin = (468000.000000000000000,5510000.000000000000000)
Pixel Size = (0.100000000000000,-0.100000000000000)
Corner Coordinates:
Upper Left  (  468000.000, 5510000.000) 
Lower Left  (  468000.000, 5505999.300) 
Upper Right (  474000.700, 5510000.000) 
Lower Right (  474000.700, 5505999.300) 
Center      (  471000.350, 5507999.650) 
Band 1 Block=128x128 Type=Byte, ColorInterp=Red
Band 2 Block=128x128 Type=Byte, ColorInterp=Green
Band 3 Block=128x128 Type=Byte, ColorInterp=Blue
Band 4 Block=128x128 Type=Byte, ColorInterp=Undefined

Everything works fine until now.
What I've done next is building one big .tif image from the .vrt file:

gdalwarp -multi -r cubic -s_srs EPSG:25832 -t_srs EPSG:3857 -cutline /shp/17.shp -crop_to_cutline -dstalpha -co compress=LZW /input/base.vrt /output/base.tif

But, now the gdalinfo from the output tif looks like:

Driver: GTiff/GeoTIFF
Files: temp/base.tif
Size is 47849, 25603
Coordinate System is:
PROJCS["WGS 84 / Pseudo-Mercator",
    GEOGCS["WGS 84",
        DATUM["WGS_1984",
            SPHEROID["WGS 84",6378137,298.257223563,
                AUTHORITY["EPSG","7030"]],
            AUTHORITY["EPSG","6326"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.0174532925199433,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4326"]],
    PROJECTION["Mercator_1SP"],
    PARAMETER["central_meridian",0],
    PARAMETER["scale_factor",1],
    PARAMETER["false_easting",0],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["X",EAST],
    AXIS["Y",NORTH],
    EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],
    AUTHORITY["EPSG","3857"]]
Origin = (952949.608269182615913,6400383.903813457116485)
Pixel Size = (0.154577105681076,-0.154574816517696)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  COMPRESSION=LZW
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (  952949.608, 6400383.904) (  8d33'37.77"E, 49d44' 3.40"N)
Lower Left  (  952949.608, 6396426.325) (  8d33'37.77"E, 49d42'40.66"N)
Upper Right (  960345.968, 6400383.904) (  8d37'36.96"E, 49d44' 3.40"N)
Lower Right (  960345.968, 6396426.325) (  8d37'36.96"E, 49d42'40.66"N)
Center      (  956647.788, 6398405.114) (  8d35'37.37"E, 49d43'22.03"N)
Band 1 Block=47849x1 Type=Byte, ColorInterp=Gray
Band 2 Block=47849x1 Type=Byte, ColorInterp=Undefined
Band 3 Block=47849x1 Type=Byte, ColorInterp=Undefined
Band 4 Block=47849x1 Type=Byte, ColorInterp=Undefined
Band 5 Block=47849x1 Type=Byte, ColorInterp=Alpha

And those Bands causes an error in the gdal2tiles function:

ERROR 6: PNG driver doesn't support 6 bands.  Must be 1 (grey),
2 (grey+alpha), 3 (rgb) or 4 (rgba) bands.

Does someone has any idea what happens? Why is the Band 2-4 Undefinied and Band 1 Gray? I think it should like the gdalinfo from the .vrt file (=> RGBA)?

Best Answer

in my case I have same error - I remove parameter '-dstalpha' from gdalwarp command:

gdalwarp -multi -r cubic -s_srs EPSG:25832 -t_srs EPSG:3857 -cutline /shp/17.shp -crop_to_cutline **-dstalpha** -co compress=LZW /input/base.vrt /output/base.tif