OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.67k stars 2.47k forks source link

Enable gdalbuildvrt to retain metadata such as band description #3627

Open maphew opened 3 years ago

maphew commented 3 years ago

Expected behavior and actual behavior.

When using gdalbuildvrt to combine images together the Description element of the bands are not copied over. There is other metadata left behind too.

I expected build vrt to operate the same way as gdal_translate, and copy the description and other metadata.

Steps to reproduce the problem.

From a source image that has band description and other metadata, split each band into a single vrt:

gdal_translate -b 1 rgb.tif b-red.vrt
gdal_translate -b 2 rgb.tif b-grn.vrt
gdal_translate -b 3 rgb.tif b-blu.vrt
gdal_translate -b 1 infrared.tif b-nir.vrt

Stack the 4 bands we want back together:

gdalbuildvrt -separate rgb-nir.vrt b-red.vrt b-grn.vrt b-blu.vrt b-nir.vrt

Interim vrt with meta

final vrt with no meta

Currently I’m hand editing the last stage vrt to put the description back in, but it’s a pain and error prone. At this point I'm personally only interested in retaining the band descriptions but it's easy to imagine scenarios where the other metadata would want to be migrated also.

Attachments:

source-image-rgb.txt - gdalinfo report for the original RGB image interim-image-nir.txt - gdalinfo report for the original near infrared image b-nir.vrt.txt - one of the intermediate VRT bands made by gdal_translate. All metadata intact. rgb-nir.vrt.txt - the result of gdalbuildvrt on the interim files, metadata has been stripped.

Operating system

Windows 10.

GDAL version and provenance

GDAL 3.1.4, released 2020/10/20 (via Qgis)

Also see gdal-dev thread gdalbuildvrt and band descriptions

maphew commented 3 years ago

It should be noted in the docs (for both translate and buildvrt) that copied metadata is not edited, and therefore may no longer be true statements. For example b-red.vrt image of this example now has this note which talks as if all 3 bands are present:

<MDI key="TIFFTAG_IMAGEDESCRIPTION">WorldView-3 Red (0.630 - 0.690) um|WorldView-3 Green (0.510 - 0.580) um|WorldView-3 Blue (0.450 - 0.510) um</MDI>

Gdal can't be expected to check and validate meta statements such as this are still true. It could perhaps add a tag that the meta was copied from source X on such-n-such date.

twest820 commented 9 months ago

+1 for this as I just hit it with some orthoimagery too. As is typical, the band descriptions are consistent across all the tiles I'm using, so no concerns around conflict resolution.

A couple notes:

(The VRT schema's at https://gdal.org/drivers/raster/vrt.html.)