Skip to content

Tips and Tutorials \ Adding your own metadata in a satellite image with rasterio

Adding your own metadata in a satellite image with rasterio

Here is a simple way to add custom metadata in an image using rasterio


Tools:
Difficulty:
Type: Tip


Overview

GDAL data model works with a collection of key/value pairs. In this model one can retrieve the metadata along with many other elements (called "tags" in rasterio), with the method your_raster.tags().

Basic metadata are also available with the method .meta. Also, your_raster.profile allows to define a named profile that may be useful in applications (i.e configuring tiling, block size, compression,... )

Usage example

The interesting point here is the ability to add metadata with the update_tags function.

import rasterio

ds = rasterio.open('path_im','r+')  # Need to be open with 'r+' mode or 'w+' mode
ds.update_tags(label_classif=["water,"road","tree"]) 
ds.close
The image is automatically updated without having to re-write the file.

Contacts

    Questions ? Get help on the Forum