c++gdalrasterizingogr

gdalbuildvrt and gdal_translate cannot be used to stack multiple rasters


Using these gdal commands to try and stack 2 or more rasters on top of each other outputs raster that only has information of the last layer.

How should commands be changed that the output image would have the rasters stacked so that the previous layers alpha doesn't overwrite all the data before/under it.

gdal_rasterize -burn 255 -burn 255 -burn 0 -burn 255 -l korkeusviiva -init 1 -ts 512 512 -ot byte -te x1 y1 x2 y2 dat.gpkg r1.tiff
gdal_rasterize -burn 255 -burn 0 -burn 255 -burn 255 -l tieviiva -init 1 -ts 512 512 -ot byte -te x1 y1 x2 y2 dat.pkgp r2.tiff
gdalbuildvrt -te x1 y1 x2 y2 merge.vrt r1.tiff r2.tiff
gdal_translate merge.vrt merge.tiff

For example the r1.tiff and t2.tiff are as exptected but the merge.tiff is just r2.tiff but with black on alpha.

This will later be implemented in the code with the C++ API.


Solution

  • Using gdalwarp instead of gdalbuildvrt and gdal_translate was used to produce desired output.

    gdalwarp -srcnodata "0 0 0 0" -dstnodata "0 0 0 0" -co "COMPRESS=DEFLATE" -te x1 y1 x2 y2 -ts 512 512 -ot Byte -multi r1.tif r2.tif merge.tif