Quantcast

[gdal-dev] Copy metadata

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[gdal-dev] Copy metadata

Klaus Schneider-Zapp
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

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Copy metadata

Even Rouault-2

Kkaus,

 

> 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?

 

Nothing. By the way, you didn't specify which output format you tried as it can make a difference. But most drivers will ignore metadata domains other than the main one, and even if they do take into account (for example the GeoTIFF driver), they will copy the metadata in a generic form, and do not encode it regarding the EXIF or XMP standards, which is probably what you want.

 

Even

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Loading...