I have two geotiffs related to one location but with different areas covered:
1.
2.
How can I intersect their opaque parts into single geotiff like that?
I have two geotiffs related to one location but with different areas covered:
1.
2.
How can I intersect their opaque parts into single geotiff like that?
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).