Using gdal, where (and how) do I store raster metadata so that it can be viewed in ArcGIS (or similar)?
Gdal datasources and raster band objects have the methods SetMetadata and GetMetadata. These seem to work fine to store the data, and I can get/set the data using Python. However I can't seem to find or view the metadata entries in ArcGIS. An example of what I tried to do is below:
import gdal
import numpy as np
# Some data
fname = 'metadata_test.tif'
data = np.ones([100,100], dtype=int)
lats = np.arange(0, 10, 10.0/100)
lons = np.arange(0, 10, 10.0/100)
# Create data source
driver = gdal.GetDriverByName('GTiff')
ds = driver.Create(fname, len(lons), len(lats), 1, gdal.GDT_Byte)
# Set metadata in datasource
ds.SetMetadata({'description':'test description'})
# Set sample data
out_band = ds.GetRasterBand(1)
out_band.WriteArray(data)
del ds
If you load the test data, you will see that the metadata has indeed been set:
ds = gdal.Open(fname)
ds.GetMetadata()
Out[8]: {'description': 'test description'}
However, I can't find it in ArcGIS.
I also tried the revese process, i.e. creating the metadata entries manually in ArcGIS (by editing the data source item description) and loading up the raster in Python with gdal. However, I can't find the metadata when I try the ds.GetMetadata() command, and in fact am struggling to find it anywhere in the object at all. I thought that the metadata might be stored in the band, however band.GetMetadata yields nothing either.
Best Answer
You should look at the GeoTIFF specification on the GDAL page, which is copied below.
You likely need to use a very-well defined metadata label to ensure inter-comprehension between programs. The metadata tag "description" should be "TIFFTAG_IMAGEDESCRIPTION".
Metadata
GDAL can deal with the following baseline TIFF tags as dataset-level metadata :
The name of the metadata item to use is one of the above names ("TIFFTAG_DOCUMENTNAME", ...).
Other non standard metadata items can be stored in a TIFF file created with the profile GDALGeoTIFF (the default, see below in the Creation issues section). Those metadata items are grouped together into a XML string stored in the non standard TIFFTAG_GDAL_METADATA ASCII tag (code 42112). When BASELINE or GeoTIFF profile are used, those non standard metadata items are stored into a PAM .aux.xml file.