Fix handling of SAR Metadata (with empty projection)
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
- Have
SetProjectionRef
clearMDGeom::ProjectionWKT
metadata on empty string - Test not only
Has(MDGeom::ProjectionWKT)
inGDALImageIO::InternalReadImageInformation()
but also whether the projections are empty - 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 notOTB_DEBUG
- Add
-
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
- for instance: instead of an exception that reports an error on
-
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