From b8f5ab2b0ab3b00557d685c306ce94f923381b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= Date: Wed, 29 May 2019 17:28:40 +0200 Subject: [PATCH] COMP: added retro compatibility for gdal 2 --- .../GdalAdapters/include/otbSpatialReference.h | 7 ++++++- .../Adapters/GdalAdapters/src/otbSpatialReference.cxx | 4 ++-- .../Core/Transform/include/otbGenericMapProjection.hxx | 2 ++ .../Sampling/include/otbImageSampleExtractorFilter.hxx | 10 +++++++++- .../Stereo/include/otbMulti3DMapToDEMFilter.hxx | 4 ++++ 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Modules/Adapters/GdalAdapters/include/otbSpatialReference.h b/Modules/Adapters/GdalAdapters/include/otbSpatialReference.h index 10114f320f..68c659dcfe 100644 --- a/Modules/Adapters/GdalAdapters/include/otbSpatialReference.h +++ b/Modules/Adapters/GdalAdapters/include/otbSpatialReference.h @@ -151,8 +151,13 @@ public: */ unsigned int ToEPSG() const; +#if GDAL_VERSION_NUM >= 3000000 + /** Set the Axis mapping strategy + * proxy to the eponym ogr spatial reference method + * \param strategy Axis mapping stategy + */ void SetAxisMappingStrategy(OSRAxisMappingStrategy strategy); - +#endif /** * Find which UTM zone a given (lat,lon) point falls in. diff --git a/Modules/Adapters/GdalAdapters/src/otbSpatialReference.cxx b/Modules/Adapters/GdalAdapters/src/otbSpatialReference.cxx index 5b2dc7020b..fa7259e850 100644 --- a/Modules/Adapters/GdalAdapters/src/otbSpatialReference.cxx +++ b/Modules/Adapters/GdalAdapters/src/otbSpatialReference.cxx @@ -292,11 +292,11 @@ void SpatialReference::UTMFromGeoPoint(double lon, double lat, unsigned int & zo assert(zone<=60); } - +#if GDAL_VERSION_NUM >= 3000000 void SpatialReference::SetAxisMappingStrategy(OSRAxisMappingStrategy strategy) { m_SR.get()->SetAxisMappingStrategy(strategy); }; - +#endif } diff --git a/Modules/Core/Transform/include/otbGenericMapProjection.hxx b/Modules/Core/Transform/include/otbGenericMapProjection.hxx index 4bb5808c8d..6cb2fd3754 100644 --- a/Modules/Core/Transform/include/otbGenericMapProjection.hxx +++ b/Modules/Core/Transform/include/otbGenericMapProjection.hxx @@ -70,8 +70,10 @@ GenericMapProjection= 3000000 wgs84.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); wktSpatialReference.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); +#endif if(DirectionOfMapping == TransformDirection::INVERSE) { diff --git a/Modules/Learning/Sampling/include/otbImageSampleExtractorFilter.hxx b/Modules/Learning/Sampling/include/otbImageSampleExtractorFilter.hxx index 776be257ed..ead92368f7 100644 --- a/Modules/Learning/Sampling/include/otbImageSampleExtractorFilter.hxx +++ b/Modules/Learning/Sampling/include/otbImageSampleExtractorFilter.hxx @@ -128,8 +128,16 @@ PersistentImageSampleExtractorFilter if(projectionInformationAvailable) { OGRSpatialReference imgSRS; + + #if GDAL_VERSION_NUM >= 3000000 // importFromWkt is const-correct in GDAL 3 const char *projWktCstr = projectionRefWkt.c_str(); - OGRErr err = imgSRS.importFromWkt( projWktCstr ); + OGRErr err = imgSRS.importFromWkt( &projWktCstr ); + #else + const char *projWktCstr = projectionRefWkt.c_str(); + char **projWktPointer = const_cast(&projWktCstr); + OGRErr err = imgSRS.importFromWkt( projWktPointer ); + #endif + if (err == OGRERR_NONE) { // get input layer diff --git a/Modules/Registration/Stereo/include/otbMulti3DMapToDEMFilter.hxx b/Modules/Registration/Stereo/include/otbMulti3DMapToDEMFilter.hxx index 016c3177c6..5f659baf36 100644 --- a/Modules/Registration/Stereo/include/otbMulti3DMapToDEMFilter.hxx +++ b/Modules/Registration/Stereo/include/otbMulti3DMapToDEMFilter.hxx @@ -335,7 +335,11 @@ void Multi3DMapToDEMFilter::GenerateOutpu if (!m_ProjectionRef.empty()) { OGRSpatialReference oSRS; + #if GDAL_VERSION_NUM >= 3000000 // importFromWkt is const-correct in GDAL 3 const char *wkt = m_ProjectionRef.c_str(); + #else + char *wkt = const_cast (m_ProjectionRef.c_str()); + #endif oSRS.importFromWkt(&wkt); m_IsGeographic = oSRS.IsGeographic(); // TODO check if this test is valid for all projection systems } -- GitLab