0

Is it possible to overwrite the raster generated using gdal_merge.py? When I ran the command:

% gdal_merge.py -init 255 -o out.tif in1.tif in2.tif

it works fine, but if I ran the same command and out.tif was already previously generated, it overwrites out.tif to a uniform raster (i.e., all values equal to 255).

4
  • What do mean by "to a wrong raster"?
    – user30184
    Feb 24, 2016 at 20:26
  • @user30184 I have updated the question to explain what I mean by wrong raster, thanks!
    – gcamargo
    Feb 24, 2016 at 21:21
  • By reading the documentation gdal.org/gdal_merge.html your command looks right.
    – user30184
    Feb 25, 2016 at 9:57
  • The command is correct, the issue is on the overwriting, or running the command twice.
    – gcamargo
    Feb 25, 2016 at 18:09

1 Answer 1

1

Old question, but for completeness here is an answer. You can't pass in an overwrite flag to gdal_merge.py as you can some other gdal functions. One workaround is to delete the file (if it exists) before you run gdal_merge.py:

import os
try:
    os.remove('path_to_file')
except OSError:
    pass

Your Answer

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

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