0

I am working with Sentinel-2 data, which I want to collect for a ROI that unfortunately is covered by two different (neighboring) granules. After downloading the granules, I cut them and convert them to to GeoTiff using

gdalwarp -of GTIff -crop_to_cutline -cutline cutline <10m_input_bands> datasetname_10m.tif

This gives the corresponding 4-band GeoTiffs (which contain only the 10m bands 4,3,2 and 8), including lots of no-data pixels where the ROI is actually located in the neighboring granule.

After that, I want to merge them by

python gdal_merge.py -of GTiff -o mergedImage.tif inputImage1.tif InputImage2.tif

The result, however, seems to be just a copy of inputImage1.tif, i.e. the no-data values remain and no mosaic is created.

What am I missing? Or is there another way to create coherent Sentinel-2 ROI images extracted from neighboring granules? At best, this would be automated for batch processing, i.e. search for products of similar name where only the granule indicator (e.h. UPU, UQU etc.) changes, and then performs the merging automatically.

EDIT: Maybe this was clear already, but to be sure: Since the output of gdalwarp is already corresponding to the ROI, the images are of the same size and follow the same geocoding reference (i.e. they reflect the same spatial subset).

3
  • 3
    What does gdalinfo tell about inputImage1 and inputImage2? Does it find the noData value? If it does not maybe using -n switch could help.
    – user30184
    Sep 20, 2017 at 14:36
  • 1
    Gdalbuildvrt is better than gdal_merge for almost anything.
    – user30184
    Sep 20, 2017 at 14:37
  • The only thing related to noData gdalinfo tells me is SPECIAL_VALUE_NODATA=0 (and SPECIAL_VALUE_SATURATED=65535). EDIT: and specifying -n 0 did the trick...
    – Michael
    Sep 20, 2017 at 14:58

1 Answer 1

2

You need to specify the no data value using -n. As you are clipping the two scenes to the same extent, each one will have no data values where the other has data. If you do not specify the no data value to ignore, it will effectively superimpose one over the other.

Try:

python gdal_merge.py -of GTiff -o mergedImage.tif inputImage1.tif InputImage2.tif -n 0

providing that your no data value is 0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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