3

I am trying to use gdal.FillNodata in python on a ".tif" raster. The nodata value is set to -3.402823e+38. Here is my code :

import gdal
from gdalconst import *

ET = gdal.Open("ET_sample_reclass.tif", GA_Update) 
ETband = ET.GetRasterBand(1)

result = gdal.FillNodata(targetBand = ETband, maskBand = None, 
                     maxSearchDist = 5, smoothingIterations = 0)

print result # return 0

This code seems to do actually nothing and I don't know how to define an output raster in python. I haven't found any example yet to enlighten me.

3
  • For gdal to write something to disk you need to flush/close the dataset. If you add ET = None at the end of your script this should work. You can see the same behaviour in the source code of the gdal_fillnodata.py script. – Kersten Jun 15 '15 at 16:08
  • Indeed it worked. Thank you. And is there a way to specify a new file as output or overwriting is the only option ? – Delforge Jun 15 '15 at 17:18
  • Of course there is: You can either use the CreateCopy() method to copy a dataset and then write new data into it or create a new dataset from scratch with the Create() method. This is documented in the GDAL API. Not all drivers support the Create() method though, but GeoTiff definitely does. – Kersten Jun 16 '15 at 6:54
2

Since the first comment turned out to be the answer here's the slightly longer version of it:

For gdal to write something to disk you need to flush/close the dataset.

If you add ET = None at the end of your script this should work and will write the new data to disk. You can see the same behaviour in the source code of the gdal_fillnodata.py script.

To create a new dataset, either as a copy of a existing one or from scratch, you can use the Create() and CreateCopy() methods as specified in the GDAL API.

The behaviour of GDAL is not really intuitive so I recommend taking a look at other GDAL Python Gotchas you might run into.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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