diff --git a/CMake/FindOssim.cmake b/CMake/FindOssim.cmake
index bc15b82c0d6d683dc222c612765c1488747ad599..228c3344997369ae15391791c2681f4286c71d59 100644
--- a/CMake/FindOssim.cmake
+++ b/CMake/FindOssim.cmake
@@ -35,14 +35,10 @@ find_path( OSSIM_INCLUDE_DIR
            NAMES ossim/init/ossimInit.h )
 
 # Version checking
+set(OSSIM_VERSION)
 if(EXISTS "${OSSIM_INCLUDE_DIR}/ossim/ossimVersion.h")
   file(READ "${OSSIM_INCLUDE_DIR}/ossim/ossimVersion.h" _ossim_version_h_CONTENTS)
   string(REGEX REPLACE ".*# *define OSSIM_VERSION *\"([0-9.]+)\".*" "\\1" OSSIM_VERSION "${_ossim_version_h_CONTENTS}")
-  string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1" OSSIM_MAJOR_VERSION_NUMBER "${OSSIM_VERSION}")
-  string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\2" OSSIM_MINOR_VERSION_NUMBER "${OSSIM_VERSION}")
-  string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\3" OSSIM_PATCH_VERSION_NUMBER "${OSSIM_VERSION}")
-  math(EXPR OSSIM_VERSION_NUMBER
-    "((${OSSIM_MAJOR_VERSION_NUMBER})*100+${OSSIM_MINOR_VERSION_NUMBER})*100+${OSSIM_PATCH_VERSION_NUMBER}")
   if("${OSSIM_VERSION}" VERSION_LESS "1.8.20")
     message(WARNING "The OSSIM include directory detected by OTB is: '${OSSIM_INCLUDE_DIR}'."
       "This version (${OSSIM_VERSION}) is not fully compatible with OTB."
@@ -67,6 +63,28 @@ else()
   endif()
 endif()
 
+# Hack to detect version 2.2.0, without ossimVersion.h
+if(EXISTS "${OSSIM_INCLUDE_DIR}/ossim/projection/ossimRpcSolver.h")
+  file(STRINGS "${OSSIM_INCLUDE_DIR}/ossim/projection/ossimRpcSolver.h" _ossim_rpc_solv_content)
+  if(_ossim_rpc_solv_content MATCHES "const +ossimRefPtr<ossimRpcModel> +getRpcModel\\(\\)")
+    if((NOT OSSIM_VERSION) OR (OSSIM_VERSION VERSION_LESS "2.2.0"))
+      set(OSSIM_VERSION "2.2.0")
+    endif()
+  endif()
+endif()
+
+if(OSSIM_VERSION)
+  string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1" OSSIM_MAJOR_VERSION_NUMBER "${OSSIM_VERSION}")
+  string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\2" OSSIM_MINOR_VERSION_NUMBER "${OSSIM_VERSION}")
+  string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\3" OSSIM_PATCH_VERSION_NUMBER "${OSSIM_VERSION}")
+  math(EXPR OSSIM_VERSION_NUMBER
+    "((${OSSIM_MAJOR_VERSION_NUMBER})*100+${OSSIM_MINOR_VERSION_NUMBER})*100+${OSSIM_PATCH_VERSION_NUMBER}")
+else()
+  # Unknown version : default to 0
+  set(OSSIM_VERSION_NUMBER 0)
+endif()
+
+# Look for the library
 find_library(OSSIM_LIBRARY
              NAMES ossim)
 
diff --git a/Modules/Adapters/OSSIMAdapters/src/CMakeLists.txt b/Modules/Adapters/OSSIMAdapters/src/CMakeLists.txt
index 20046e7b0d3da9e9a30a306c9e3474cc2f39de09..5bb6d442694c4c355182ad5d7de345d45c8299da 100644
--- a/Modules/Adapters/OSSIMAdapters/src/CMakeLists.txt
+++ b/Modules/Adapters/OSSIMAdapters/src/CMakeLists.txt
@@ -41,7 +41,16 @@ target_link_libraries(OTBOSSIMAdapters
   ${OTBOssim_LIBRARIES}
   ${OTBOssimPlugins_LIBRARIES}
   ${OTBOpenThreads_LIBRARIES}
-
   )
 
 otb_module_target(OTBOSSIMAdapters)
+
+# add the OTB_OSSIM_VERSION definition
+get_target_property(_OTBOSSIMAdapters_COMP_DEF OTBOSSIMAdapters COMPILE_DEFINITIONS)
+if(_OTBOSSIMAdapters_COMP_DEF)
+  set_target_properties(OTBOSSIMAdapters
+    PROPERTIES COMPILE_DEFINITIONS "${_OTBOSSIMAdapters_COMP_DEF};OTB_OSSIM_VERSION=${OTB_OSSIM_VERSION}")
+else()
+  set_target_properties(OTBOSSIMAdapters
+    PROPERTIES COMPILE_DEFINITIONS "OTB_OSSIM_VERSION=${OTB_OSSIM_VERSION}")
+endif()
diff --git a/Modules/Adapters/OSSIMAdapters/src/otbRPCSolverAdapter.cxx b/Modules/Adapters/OSSIMAdapters/src/otbRPCSolverAdapter.cxx
index dce63c8c53306778bebec12a9c257cf5cb75c938..493cd5f8df045be26bc20076c282ab57a8867510 100644
--- a/Modules/Adapters/OSSIMAdapters/src/otbRPCSolverAdapter.cxx
+++ b/Modules/Adapters/OSSIMAdapters/src/otbRPCSolverAdapter.cxx
@@ -112,7 +112,11 @@ RPCSolverAdapter::Solve(const GCPsContainerType& gcpContainer,
   rmsError = rpcSolver->getRmsError();
 
   // Retrieve the output RPC projection
+#if OTB_OSSIM_VERSION < 20200
   ossimRefPtr<ossimRpcProjection> rpcProjection = dynamic_cast<ossimRpcProjection*>(rpcSolver->createRpcProjection()->getProjection());
+#else
+  ossimRefPtr<ossimRpcModel> rpcProjection = rpcSolver->getRpcModel();
+#endif
 
   // Export the sensor model in an ossimKeywordlist
   ossimKeywordlist geom_kwl;
diff --git a/Modules/Filtering/ImageManipulation/include/otbTwoNRIBandsImageToNComplexBandsImage.txx b/Modules/Filtering/ImageManipulation/include/otbTwoNRIBandsImageToNComplexBandsImage.txx
index 48bf5e6c8561ee8baf736077df608c17c770e994..032074b135d18abd267be37b6d4feb4511612036 100644
--- a/Modules/Filtering/ImageManipulation/include/otbTwoNRIBandsImageToNComplexBandsImage.txx
+++ b/Modules/Filtering/ImageManipulation/include/otbTwoNRIBandsImageToNComplexBandsImage.txx
@@ -52,18 +52,17 @@ TwoNRIBandsImageToNComplexBandsImage<TInputImage, TOutputImage>
 ::GenerateOutputInformation(void)
 {
   Superclass::GenerateOutputInformation();
-  
+
   unsigned int nbCompo = this->GetInput()->GetNumberOfComponentsPerPixel();
-  
+
   if ( (nbCompo % 2) != 0 )
-  {
-	itkExceptionMacro("Number of bands of the input images must be an even number");
-  }
+    {
+    itkExceptionMacro("Number of bands of the input images must be an even number");
+    }
   else
-	this->GetOutput()->SetNumberOfComponentsPerPixel(nbCompo/2);
-	
-	std::cout << "GenerateOutputInformation : " << this->GetOutput()->GetNumberOfComponentsPerPixel() << std::endl;
-  
+    {
+    this->GetOutput()->SetNumberOfComponentsPerPixel(nbCompo/2);
+    }
 }
 
 /**
@@ -75,10 +74,10 @@ TwoNRIBandsImageToNComplexBandsImage<TInputImage, TOutputImage>
 ::BeforeThreadedGenerateData(void)
 {
 	unsigned int nbCompo = this->GetInput()->GetNumberOfComponentsPerPixel();
-			
+
 	if ( (nbCompo % 2) != 0 )
 	  itkExceptionMacro("Number of bands of the input images must be an even number");
-		
+
 }
 
 /**
diff --git a/Modules/Learning/Sampling/include/otbPersistentSamplingFilterBase.txx b/Modules/Learning/Sampling/include/otbPersistentSamplingFilterBase.txx
index 35723e178dcc6796b68d2690419f509ba0443cf0..9873afb0fa06444a0e914876360cff5fa6394ace 100644
--- a/Modules/Learning/Sampling/include/otbPersistentSamplingFilterBase.txx
+++ b/Modules/Learning/Sampling/include/otbPersistentSamplingFilterBase.txx
@@ -740,7 +740,11 @@ PersistentSamplingFilterBase<TInputImage,TMaskImage>
     dstFeature.SetFID(featIt->GetFID());
     tmpLayers[counter].CreateFeature( dstFeature );
     cptFeat++;
-    if (cptFeat > nbFeatThread) counter++; cptFeat=0;
+    if (cptFeat > nbFeatThread && (counter + 1) < numberOfThreads)
+      {
+      counter++;
+      cptFeat=0;
+      }
     }
 
   inLayer.SetSpatialFilter(ITK_NULLPTR);
diff --git a/Modules/ThirdParty/Ossim/otb-module-init.cmake b/Modules/ThirdParty/Ossim/otb-module-init.cmake
index 12dd30732410af3a723c8a6cbca56558a7520a9e..e6fbb52c4252ee098e6866127507d504616694ab 100644
--- a/Modules/ThirdParty/Ossim/otb-module-init.cmake
+++ b/Modules/ThirdParty/Ossim/otb-module-init.cmake
@@ -19,3 +19,5 @@
 #
 
 find_package ( Ossim REQUIRED )
+
+set(OTB_OSSIM_VERSION ${OSSIM_VERSION_NUMBER} CACHE INTERNAL "Ossim version detected by OTB" FORCE)
diff --git a/Packaging/Files/otbenv.profile b/Packaging/Files/otbenv.profile
index 191121e411efbe133bd2a458e1fc2e9bd705e684..47f3a7e522341b1dc9308285587ebaa5cef2f898 100644
--- a/Packaging/Files/otbenv.profile
+++ b/Packaging/Files/otbenv.profile
@@ -23,24 +23,9 @@
 # So if you run again from a terminal. you need to run the script again
 # see how this is sourced in monteverdi.sh and mapla.sh
 
-# unset any existing LD_LIBRARY_PATH
-unset LD_LIBRARY_PATH
-
 CMAKE_PREFIX_PATH=OUT_DIR
 export CMAKE_PREFIX_PATH
 
-
-# if OTB_USE_LOCAL_GTK is set to one,
-# we must include ./lib/gtk because gtklibs are installed there. 
-# OTB_USE_LOCAL_GTK is not set by default (use GTK system)
-#This code only affect linux system. for osx OUT_DIR/lib/gtk does not exists
-if [ "$OTB_USE_LOCAL_GTK" = "1" ]; then
-    if [ -d "OUT_DIR/lib/gtk" ]; then
-	LD_LIBRARY_PATH=OUT_DIR/lib/gtk
-	export LD_LIBRARY_PATH
-    fi
-fi
-
 # check and set OTB_APPLICATION_PATH
 if [ -z "$OTB_APPLICATION_PATH" ] || [ "$OTB_APPLICATION_PATH" = "" ]; then
     OTB_APPLICATION_PATH=OUT_DIR/lib/otb/applications