Skip to content

Fix handling of SAR Metadata (with empty projection)

Luc Hermitte requested to merge lhermitte/otb:Fixes-on-metadata into develop

Summary

Make sure SAR metadata are not improperly discarded.

Rationale

When a projection is set with SetProjectionRef(), it sets MDGeom::ProjectionWKT which in turn prevents SAR metadata to be written into the final file in GDALImageIO::InternalReadImageInformation().

The problem arises when the projection is an empty string. This quickly happens on innocent lines like:

outputPtr->SetProjectionRef(m_SarImagePtr->GetProjectionRef());

(that we could find in DiapOTB otbSARDEMPolygonsAnalysisImageFilter.hxx or related filters like the improved fork in https://gitlab.orfeo-toolbox.org/s1-tiling/normlim_sigma0 or Gamm0 RTC implementation)

Implementation Details

  1. Have SetProjectionRef clear MDGeom::ProjectionWKT metadata on empty string
  2. Test not only Has(MDGeom::ProjectionWKT) in GDALImageIO::InternalReadImageInformation() but also whether the projections are empty
  3. And warn SAR metadata will be discarded if they are detected while there is a projection that supersedes their serialization
Bonus
  • Some warnings are handled:

    • Add OTB_FALLTHROUGH as we can't use C++17 [[fallthrough]] yet.
    • Make otbUnusedMacro depend on the one and only symbol that really decides whether an assertion is expanded or not => NDEBUG and not OTB_DEBUG
  • Remove an undefined behaviour on extracting some SAR std::array metadata (MRE: https://gcc.godbolt.org/z/9s6Gsrz1x)

  • Error messages on missing metadata are improved

    • for instance: instead of an exception that reports an error on map::at, we will correctly signal that GCP are not present in the metadata
    • more context is also provided for many other metadata; and code is simplified thanks to helper functions
  • Some other minor code improvements and optimisations

  • Possibly related to #2266. Further tests are required. EDIT -> no changes

Copyright

The copyright owner is CNES and has signed the ORFEO ToolBox Contributor License Agreement.


Check before merging:

  • All discussions are resolved
  • At least 2 👍 votes from core developers, no 👎 vote.
  • The feature branch is (reasonably) up-to-date with the base branch
  • Dashboard is green
  • Copyright owner has signed the ORFEO ToolBox Contributor License Agreement
  • Optionally, run git diff develop... -U0 --no-color | clang-format-diff.py -p1 -i on latest changes and commit
Edited by Luc Hermitte

Merge request reports