Is there a way to update metadata of an existing geotiff file? I'm particularly interested in setting the nodata value. The following does not appear to work

import rasterio
from pprint import pprint

path = '/path/to/file.tif'

with rasterio.open(path, 'r+') as src:
    src.meta['nodata'] = -32767

3 Answers 3


The previous answers are misleading or wrong. To modify the nodata value of a GeoTIFF with Rasterio, do this

with rasterio.open(tiffname, 'r+') as dataset:
    dataset.nodata = -32767

The project has tests of this usage that you may see also: https://github.com/mapbox/rasterio/blob/master/tests/test_update.py#L59-L64. Note that you may have to close and reopen the file (as done in the test) to see the nodata value take effect in your program.

The meta property of a dataset is a copy of some of its important metadata. Modifying that object has no effect on the dataset.

  • It depends on what really was the question. If it was "Is there a way to update metadata of an existing geotiff file?" like in the question body the gdal_edit answer is not misleading. If one reads only the title that says "with rasterio" and forgets the gdal tag then gdal_edit if off topic and downvote is appropriate.
    – user30184
    Sep 12, 2017 at 19:45

If you want to modify additional meta data values you can use the dataset.update_tags() method provided by rasterio.

Note: do not confuse additional meta data values with the special meta data values like driver, dtype, nodata, width, height, count, crs or transform that are part of dataset.meta

Here is an example (derived from the official documentation):

import rasterio
file_path = "/path/to/my_file.tif"
meta_data_dict = {"my_variable": 'my_value'}
with rasterio.open(file_path, 'r+') as raster:

Additional meta data values are shown in QGIS, if you go to the properties of a layer (right click on layer / properties ...), select Information and check the entries under More information

EDIT: In a few cases QGIS did not show the meta data values under More Information, although they were accessible with rasterio.

enter image description here


I don't know how to do it right with rasterio but the question includes "gdal" tag so it seems that also GDAL based answers are acceptable. In that case this GDAL tool is made for you http://www.gdal.org/gdal_edit.html.


The gdal_edit.py script can be used to edit in place various information of an existing GDAL dataset (projection, geotransform, nodata, metadata).

The script from GDAL trunk can be found at https://trac.osgeo.org/gdal/browser/trunk/gdal/swig/python/scripts/gdal_edit.py.

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.