1

I have two geotiffs related to one location but with different areas covered:

1.

The first geotiff

2.

The second geotiff

How can I intersect their opaque parts into single geotiff like that?

enter image description here

2
  • what are the nodata vaues of 1. and 2.?
    – pLumo
    Commented Jul 19, 2018 at 9:25
  • @RoVo let it be 0
    – Symon
    Commented Jul 19, 2018 at 9:27

1 Answer 1

1

Note: This solution is working for single band image only

If you have multiple bands, you may repeat this for each band adding -A_Band and -B_Band options and then gdal_merge.py -separate the bands.


You should be able to do this:

(We assume NoData Value of your rasters is 0)

gdal_calc.py -A file1.tif -B file2.tif --NoDataValue=0 \
--calc="A*(A>0)+B*logical_and(A==0,B>0)" \
--outfile=outfile.tif

Explanation:

  • A*(A>0): if A is not Nodata, will be A*1, else A*0
  • B*logical_and(A==0,B>0): if A is NoData and B is not Nodata, will be B*1, else B*0.

(This will always prefer A over B).

3
  • I think I need to transform both images to the save window before doing math.
    – Symon
    Commented Jul 19, 2018 at 9:50
  • *to the same window
    – Symon
    Commented Jul 19, 2018 at 9:56
  • I might need to change a bit as this works for single band GeoTiff. I'll update later
    – pLumo
    Commented Jul 19, 2018 at 10:07

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.