1

I'm trying to mosaic some georeferenced images using gdalwarp. But if I change the resampling method the result is always the same, why? I need to build a mosaic where the value of each pixel is the average of all overlapped pixels at that point.

For example, my images have a resolution of 0.05m and I want a mosaic with 1m resolution so I try:

gdalwarp -tr 1 1 *.tif merged.tif

and:

gdalwarp -r average *.tif merged_average.tif

but the results are always the same 1m resolution raster. I also tried with min and max resampling methods, but even in this case the results are the same. How can this be possible? Maybe I did something wrong in the code?

  • Do you mean that you have overlapping areas in, let's say image1.tif and image2.tif, and you want that the result is something like pixel_value1+pixel_value2/2? – user30184 Sep 20 at 9:59
  • yes, exactly. I thought to use gdalwarp with average resampling method but the result is not the expected – Giulio Sep 20 at 15:25
  • 1
    Gdalwarp is processing one image at a time. It does respect the selected resampling method for each image when it warps and changes the pixel size. But when it writes new pixels to the overlapping area it just overwrites the old pixels. So the end result is not average of pixels from image 1 and image 2, but just pixels from image 2. Gdalwarp is not the tool for making band compositions. – user30184 Sep 20 at 17:20
  • This has sense! Thank you for your answer. Do you have any idea how to do what i want? – Giulio Sep 21 at 9:30
  • Not really. The is a RFC about adding raster algebra features into GDAL but I do not know what is the situation of that development. And then you can do something similar with derived bands by using a virtual raster gdal.org/drivers/raster/…. But using VRT does not feel simple in your case because I guess that you can have only one or quite many overlapping images for each pixel. – user30184 Sep 21 at 9:52
0

Create the mosaic with gdal_merge (documentation here):

gdal_merge.py -o merged.tif raster1.tif raster2.tif raster3.tif ...  

If the first image (raster1.tif) have a resolution of 0.05m, the mosaic will have a resolution of 0.05m. If not, you can define the pixel size with the -ps parameter.
If there are two or more contributing pixels somewhere, the mosaic will assume the pixel value of the last raster in that place. That is where you can not perform direct algebra from the merge.

Then, resample the merged image with the method you want:

gdalwwarp -tr 1 1 -r average merged.tif merged_average.tif

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.