[gdal-dev] Copy metadata

Klaus Schneider-Zapp klaus.schneider-zapp at pix4d.com
Thu May 18 05:56:09 PDT 2017


Hi all,

I would like to copy Exif and XMP data with GDAL. Minimal example:

namespace std
{
    template <>
    struct default_delete<GDALDataset>
    {
        void operator()(GDALDataset* dataset) const
        {
            GDALClose(static_cast<GDALDatasetH>(dataset));
        }
    };
}

bool copyMetadata(const std::string& inputPath, const std::string& outputPath)
{
    std::unique_ptr<GDALDataset> inputDataset(static_cast<GDALDataset*>(
                              GDALOpenEx(inputPath.c_str(), GDAL_OF_RASTER | 
GDAL_OF_READONLY, nullptr, nullptr, nullptr)));
    std::unique_ptr<GDALDataset> outputDataset(static_cast<GDALDataset*>(
                               GDALOpenEx(outputPath.c_str(), GDAL_OF_RASTER | 
GDAL_OF_UPDATE, nullptr, nullptr, nullptr)));

    if (inputDataset == nullptr || outputDataset == nullptr)
    {
        return false;
    }

    const std::array<const char*, 2> domainList = {{"EXIF", "xml:XMP"}};
    for (const auto& domain : domainList)
    {
        char** metadata = inputDataset->GetMetadata(domain);
        const auto err = outputDataset->SetMetadata(metadata, domain);
        if (err != CE_None && err != CE_Warning)
        {
            return false;
        }
    }
    return true;
}

I can call this function with success (returns true), but the metadata of the 
output image still does not change. What am I doing wrong?

Thanks,
Klaus



More information about the gdal-dev mailing list