I am having a Merging issue with the GDAL python library. I am using gdal_merge.py
link
My issue is when I merge two rasters NoData value of one raster overlaps the other data resulting in not a proper raster image.
For example, in the raster images below (left images) if I merge these 4 images labeled as 1,2,3,4 I should get the merged raster image as the right-sided image.
But, the merged image I am getting looks like this (image below):
(Note: Image labeled 1,2 and 3 are merged properly. It's only when we merged them with image labeled 4, it's not properly merging.)
How do I resolve this issue?
1 Answer 1
If you are not using the -n parameter, nodata values will be included in your mosaic.
GDAL will ignore nodata values if you specify this and will mosaic data without overlapping nodata areas included.
Note (update from OP): np.nan may not work as a nodata value
For example:
gdal_merge.py -n 0 -o output.tif input1.tif input2.tif
You will need to know the nodata value and make sure it is the same in each image
-
Hi @NathanThomas, I am using -n parameter.
import gdal_merge as gm
,gm.main(['', '-o', outPath, '-of', 'GTiff', '-init', 'np.nan', '-n', 'np.nan', '-a_nodata', 'np.nan', 'input1.tif', 'input2.tif', 'input3.tif', 'input4.tif'])
terraCoder– terraCoder2020年09月20日 23:14:33 +00:00Commented Sep 20, 2020 at 23:14 -
Is the nodata value in each image a nan value?GeoMonkey– GeoMonkey2020年09月21日 00:48:15 +00:00Commented Sep 21, 2020 at 0:48
-
Yes, All the images have nodata as nan value.terraCoder– terraCoder2020年09月21日 01:15:54 +00:00Commented Sep 21, 2020 at 1:15
-
This is strange. Can you include more of your code in the question?GeoMonkey– GeoMonkey2020年09月21日 16:52:55 +00:00Commented Sep 21, 2020 at 16:52
-
1Looks like I have found the problem. It was not working properly becasue of NaN values.
gdal_merge.py
doesn't support the NaN values. I have change nodata from NaN (np.nan
) to -9999 and it workds. Thanks for the help.terraCoder– terraCoder2020年09月22日 14:53:11 +00:00Commented Sep 22, 2020 at 14:53
Explore related questions
See similar questions with these tags.