Request for Changes-11: Gdal 2.0 support
[Request for Changes - 11] Gdal 2.0 support
Status
- Author: Julien Michel
- Submitted on 15.10.2015
- Proposed target release: 5.2
- Adopted : +4 votes
- https://git.orfeo-toolbox.org/otb.git/shortlog/refs/heads/gdal-2.0-support
Summary
This Request for Changes makes Orfeo ToolBox support both gdal 1.x (x >=10) and gdal 2.x.
Rationale
Until now, Gdal 2.0 and higher was not supported in OTB [1]. The main reason is an API change that unifies OGRDatasource and GDALDataset [2].
While in the initial bug report, it was suggested that moving to the C API should resolve the issue, I found no evidence of that (some C API function are also marked as deprecated), and it implies a lot of changes in the code. I therefore did not got this way and tried to keep with the C++ API. Note that there might be other reason to move to the C API in the future, but that is a great deal of work.
Of course, the tricky part of this RFChanges is to get both gdal 1.x and gdal 2.x supported without #ifdef everywhere in the code. I resolved this by hiding all interface changes in functions of an ogr::version_proxy namespace, that is in charge of switching implementation at the back while proposing the same public interface for both versions. I then updated all classes using the deprecated OGR methods to use the ogr::version_proxy functions instead.
[1] https://bugs.orfeo-toolbox.org/view.php?id=937
[2] https://trac.osgeo.org/gdal/wiki/rfc46_gdal_ogr_unification
Implementation details
Classes and files
ThirdParty/GDAL
- There was an error in gdalVersionTest.cxx that prevented 2.0 to be detected as a correct version:
- otb-module-init.cmake has been updated to store the gdal major version in a cmake cache variable :
Core/Common
- otbConfigure.h.in has been updated with the content of the OTB_USE_GDAL_20 cmake variable
Adapters/GDALAdapters
- The ogr::version_proxy namespace was created and contains functions fir the stable interface to use both gdal version
- Two different implementations of those functions are built depending on the gdal version:
- The cmake switch is here:
https://git.orfeo-toolbox.org/otb.git/commitdiff/b68604044cfdeaa63425972632810f14cb1202db#patch2
- OGRDatasetWrapper and OGRLayerWrapper classes have been changed to use the ogr::version_proxy namespace instead of direct calls to gdal API for all calls affected by the API change.
IO/IOGDAL
- OGRVectorDataIO and OGRIOHelper classes have been changed to use the ogr::version_proxy functions instead of direct calls to gdal API for all calls affected by the API change.
IO/TestKernel
- otbTestKernel.cxx has been changed to use the ogr::version_proxy namespace instead of direct calls to gdal API for all calls affected by the API change.
Applications
No code changes in applications.
Tests
No changes in tests, but changes in TestDriver and OGR use might have some impact on the dashboard.
- Dashboard submission for this branch and using gdal 1.10 is on and no has no failing test related to the changes
- A new configuration has to be set to test the same branch with gdal 2.0 as well.
Documentation
- New functions in ogr::version_proxy namespace has been heavily documented.
Additional notes
This bring yet another GDAL/OGR/Proxy/helper class in our code. From an outside perspective, it might be hard to understand what all these classes are for (this is more clear with ogr::version_proxy namespace instead of static class as suggested by Luc).