Request for Changes-11: Gdal 2.0 support

From OTBWiki
Revision as of 11:09, 26 October 2015 by Gpasero (Talk | contribs) ([Request for Changes - 11] Gdal 2.0 support)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

[Request for Changes - 11] Gdal 2.0 support

Status

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:

https://git.orfeo-toolbox.org/otb.git/blobdiff/1c53a1316773adf2a416927938cea11e45f17a0e..b68604044cfdeaa63425972632810f14cb1202db:/Modules/ThirdParty/GDAL/gdalVersionTest.cxx

  • otb-module-init.cmake has been updated to store the gdal major version in a cmake cache variable :

https://git.orfeo-toolbox.org/otb.git/blobdiff/1c53a1316773adf2a416927938cea11e45f17a0e..b68604044cfdeaa63425972632810f14cb1202db:/Modules/ThirdParty/GDAL/otb-module-init.cmake

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

https://git.orfeo-toolbox.org/otb.git/blob/d63d324733ea01342c8247b624c8800f2400ac5d:/Modules/Adapters/GdalAdapters/include/otbOGRVersionProxy.h

  • Two different implementations of those functions are built depending on the gdal version:

https://git.orfeo-toolbox.org/otb.git/blob/d63d324733ea01342c8247b624c8800f2400ac5d:/Modules/Adapters/GdalAdapters/src/otbOGRVersionProxy1x.cxx

https://git.orfeo-toolbox.org/otb.git/blob/d63d324733ea01342c8247b624c8800f2400ac5d:/Modules/Adapters/GdalAdapters/src/otbOGRVersionProxy2x.cxx

  • 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.

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).