Reported upstream https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb/-/issues/2525
https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb/-/work_items/2549

--- Modules/Core/Adapters/GdalAdapters/src/otbOGRFieldWrapper.cxx.orig	2025-03-24 10:29:03
+++ Modules/Core/Adapters/GdalAdapters/src/otbOGRFieldWrapper.cxx	2025-11-09 19:32:18
@@ -98,7 +98,7 @@
 /*=================================[ Field ]=================================*/
 /*===========================================================================*/
 
-otb::ogr::Field::Field(otb::ogr::Feature& feature, int index) : m_Definition(*feature.ogr().GetFieldDefnRef(index)), m_Feature(feature.sptr()), m_index(index)
+otb::ogr::Field::Field(otb::ogr::Feature& feature, int index) : m_Definition(const_cast <OGRFieldDefn &> (*feature.ogr().GetFieldDefnRef(index))), m_Feature(feature.sptr()), m_index(index)
 {
   CheckInvariants();
 }
 
--- Modules/Core/Adapters/GdalAdapters/src/otbOGRFeatureWrapper.cxx.orig	2025-03-24 10:29:03
+++ Modules/Core/Adapters/GdalAdapters/src/otbOGRFeatureWrapper.cxx	2025-11-09 19:59:03
@@ -132,7 +132,7 @@
 
 otb::ogr::FieldDefn otb::ogr::Feature::UncheckedGetFieldDefn(int index) const
 {
-  return FieldDefn(*m_Feature->GetFieldDefnRef(index));
+  return FieldDefn(const_cast <OGRFieldDefn &> (*m_Feature->GetFieldDefnRef(index)));
 }
 
 otb::ogr::FieldDefn otb::ogr::Feature::UncheckedGetFieldDefn(std::string const& name) const
@@ -174,7 +174,7 @@
 
 OGRFeatureDefn& otb::ogr::Feature::UncheckedGetDefn() const
 {
-  return *m_Feature->GetDefnRef();
+  return const_cast <OGRFeatureDefn &> (*m_Feature->GetDefnRef());
 }
 
 /*===========================================================================*/
--- Modules/Core/IO/IOGDAL/src/otbOGRIOHelper.cxx.orig	2025-03-24 10:29:03
+++ Modules/Core/IO/IOGDAL/src/otbOGRIOHelper.cxx	2025-11-10 09:14:33
@@ -213,7 +213,7 @@
     {
       if (ogr::IsFieldSetAndNotNull(feature, fieldNum))
       {
-        kwl.AddField(feature->GetFieldDefnRef(fieldNum), feature->GetRawFieldRef(fieldNum));
+        kwl.AddField(const_cast <OGRFieldDefn*> (feature->GetFieldDefnRef(fieldNum)), feature->GetRawFieldRef(fieldNum));
       }
     }
 
@@ -895,7 +895,7 @@
 
       ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn());
       //      ogrFeature->SetField("Name", dataNode->GetNodeId());
-      ogrFeature->GetDefnRef()->SetGeomType(wkbMultiPoint);
+      const_cast<OGRFeatureDefn*>(ogrFeature->GetDefnRef())->SetGeomType(wkbMultiPoint);
       ogrFeature->SetGeometry(ogrMultiPoint);
 
       if (ogrCurrentLayer->CreateFeature(ogrFeature) != OGRERR_NONE)
@@ -916,7 +916,7 @@
 
       ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn());
       //      ogrFeature->SetField("Name", dataNode->GetNodeId());
-      ogrFeature->GetDefnRef()->SetGeomType(wkbMultiLineString);
+      const_cast<OGRFeatureDefn*>(ogrFeature->GetDefnRef())->SetGeomType(wkbMultiLineString);
       ogrFeature->SetGeometry(ogrMultiLineString);
 
       if (ogrCurrentLayer->CreateFeature(ogrFeature) != OGRERR_NONE)
@@ -937,12 +937,12 @@
       ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn());
       //      ogrFeature->SetField("Name", dataNode->GetNodeId());
       #if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,9,0)
-        ogrFeature->GetDefnRef()->Unseal(true);
+        const_cast<OGRFeatureDefn*>(ogrFeature->GetDefnRef())->Unseal(true);
       #endif
-      ogrFeature->GetDefnRef()->SetGeomType(wkbMultiPolygon);
+      const_cast<OGRFeatureDefn*>(ogrFeature->GetDefnRef())->SetGeomType(wkbMultiPolygon);
       ogrFeature->SetGeometry(ogrMultiPolygon);
       #if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,9,0)
-        ogrFeature->GetDefnRef()->Seal(true);
+        const_cast<OGRFeatureDefn*>(ogrFeature->GetDefnRef())->Seal(true);
       #endif
       if (ogrCurrentLayer->CreateFeature(ogrFeature) != OGRERR_NONE)
       {
@@ -962,7 +962,7 @@
 
       ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn());
       //      ogrFeature->SetField("Name", dataNode->GetNodeId());
-      ogrFeature->GetDefnRef()->SetGeomType(wkbGeometryCollection);
+      const_cast<OGRFeatureDefn*>(ogrFeature->GetDefnRef())->SetGeomType(wkbGeometryCollection);
       ogrFeature->SetGeometry(ogrCollectionGeometry);
 
       if (ogrCurrentLayer->CreateFeature(ogrFeature) != OGRERR_NONE)
@@ -1226,7 +1226,7 @@
       OGRFeature*    ogrFeature;
 
       ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn());
-      ogrFeature->GetDefnRef()->SetGeomType(wkbMultiPoint);
+      const_cast<OGRFeatureDefn*>(ogrFeature->GetDefnRef())->SetGeomType(wkbMultiPoint);
       ogrFeature->SetGeometry(ogrMultiPoint);
 
       if (ogrCurrentLayer->CreateFeature(ogrFeature) != OGRERR_NONE)
@@ -1244,7 +1244,7 @@
       OGRFeature* ogrFeature;
 
       ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn());
-      ogrFeature->GetDefnRef()->SetGeomType(wkbMultiLineString);
+      const_cast<OGRFeatureDefn*>(ogrFeature->GetDefnRef())->SetGeomType(wkbMultiLineString);
       ogrFeature->SetGeometry(ogrMultiLineString);
 
       if (ogrCurrentLayer->CreateFeature(ogrFeature) != OGRERR_NONE)
@@ -1261,7 +1261,7 @@
       OGRFeature*      ogrFeature;
 
       ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn());
-      ogrFeature->GetDefnRef()->SetGeomType(wkbMultiPolygon);
+      const_cast<OGRFeatureDefn*>(ogrFeature->GetDefnRef())->SetGeomType(wkbMultiPolygon);
       ogrFeature->SetGeometry(ogrMultiPolygon);
 
       if (ogrCurrentLayer->CreateFeature(ogrFeature) != OGRERR_NONE)
@@ -1278,7 +1278,7 @@
       OGRFeature* ogrFeature;
 
       ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn());
-      ogrFeature->GetDefnRef()->SetGeomType(wkbGeometryCollection);
+      const_cast<OGRFeatureDefn*>(ogrFeature->GetDefnRef())->SetGeomType(wkbGeometryCollection);
       ogrFeature->SetGeometry(ogrCollectionGeometry);
 
       if (ogrCurrentLayer->CreateFeature(ogrFeature) != OGRERR_NONE)
--- Modules/Core/IO/IOGDAL/src/otbOGRVectorDataIO.cxx.orig	2025-03-24 10:29:03
+++ Modules/Core/IO/IOGDAL/src/otbOGRVectorDataIO.cxx	2025-11-10 09:24:13
@@ -102,7 +102,7 @@
   DataTreePointerType tree = data->GetDataTree();
   DataNodePointerType root = tree->GetRoot()->Get();
 
-  OGRSpatialReference* oSRS = nullptr;
+  const OGRSpatialReference* oSRS = nullptr;
   // We take the assumption that the spatial reference is common to all layers
   oSRS = m_DataSource->GetLayer(0)->GetSpatialRef();
 
--- Modules/Core/IO/TestKernel/src/otbTestHelper.cxx.orig	2025-03-24 10:29:03
+++ Modules/Core/IO/TestKernel/src/otbTestHelper.cxx	2025-11-10 09:26:36
@@ -2002,7 +2002,7 @@
   {
     for (int iField = 0; iField < feature->GetFieldCount(); iField++)
     {
-      OGRFieldDefn* poFDefn = feature->GetDefnRef()->GetFieldDefn(iField);
+      OGRFieldDefn* poFDefn = const_cast<OGRFieldDefn*>(feature->GetDefnRef()->GetFieldDefn(iField));
 
       fprintf(fpOut, "  %s (%s) = ", poFDefn->GetNameRef(), OGRFieldDefn::GetFieldTypeName(poFDefn->GetType()));
 

--- Modules/ThirdParty/GDAL/gdalCreateTest.cxx.orig	2025-03-24 10:29:03
+++ Modules/ThirdParty/GDAL/gdalCreateTest.cxx	2026-06-01 22:53:52
@@ -41,7 +41,7 @@
   return EXIT_FAILURE;
   }
 
-  papszMetadata = GDALGetMetadata( hDriver, NULL );
+  papszMetadata = const_cast<char**>(GDALGetMetadata( hDriver, NULL ));
 
   if( CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATE, FALSE ) )
     printf( "Driver %s supports Create() method.\n", pszFormat );
 
--- Modules/ThirdParty/GDAL/gdalCreateCopyTest.cxx.orig	2025-03-24 10:29:03
+++ Modules/ThirdParty/GDAL/gdalCreateCopyTest.cxx	2026-06-01 22:51:56
@@ -44,7 +44,7 @@
   }
 
   char **papszMetadata;
-  papszMetadata = GDALGetMetadata( hDriver, NULL );
+  papszMetadata = const_cast<char**>(GDALGetMetadata( hDriver, NULL ));
   if( CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATECOPY, FALSE ) )
     printf( "Driver %s supports CreateCopy() method.\n", pszFormat );
 
--- Modules/Core/Metadata/src/otbCosmoImageMetadataInterface.cxx.orig	2025-03-24 10:29:03
+++ Modules/Core/Metadata/src/otbCosmoImageMetadataInterface.cxx	2026-06-01 18:50:21
@@ -50,7 +50,7 @@
   std::vector<std::map<std::string, std::string> > metadataBands;
   GDALDataset * dataset = static_cast<GDALDataset*>(GDALOpen(file.c_str(), GA_ReadOnly));
   // Metadata for dataset
-  char** papszMetadata = dataset->GetMetadata(nullptr);
+  char** papszMetadata = const_cast<char**>(dataset->GetMetadata(nullptr));
   for (int cpt = 0; papszMetadata[cpt] != nullptr; ++cpt)
     {
     std::string key, value;
@@ -67,7 +67,7 @@
     std::map<std::string, std::string> mapCurrentBand;
     GDALRasterBand * Band = dataset->GetRasterBand(iBand + 1);
 
-    papszMetadata = Band->GetMetadata(nullptr);
+    papszMetadata = const_cast<char**>(Band->GetMetadata(nullptr));
     for (int cpt = 0; papszMetadata[cpt] != nullptr; ++cpt)
       {
       std::string key, value;
--- Modules/Core/IO/IOGDAL/src/otbGDALImageIO.cxx.orig	2025-03-24 10:29:03
+++ Modules/Core/IO/IOGDAL/src/otbGDALImageIO.cxx	2026-06-01 19:00:24
@@ -279,7 +279,7 @@
 {
   // Note: we assume that the subdatasets are in order : SUBDATASET_ID_NAME, SUBDATASET_ID_DESC, SUBDATASET_ID+1_NAME, SUBDATASET_ID+1_DESC
   char** papszMetadata;
-  papszMetadata = m_Dataset->GetDataSet()->GetMetadata("SUBDATASETS");
+  papszMetadata = const_cast<char**>(m_Dataset->GetDataSet()->GetMetadata("SUBDATASETS"));
 
   // Have we find some dataSet ?
   // This feature is supported only for hdf4 and hdf5 file (regards to the bug 270)
@@ -437,7 +437,7 @@
     // this happen in the case of a hdf file with SUBDATASETS
     // Note: we assume that the datasets are in order
     char** papszMetadata;
-    papszMetadata = m_Dataset->GetDataSet()->GetMetadata("SUBDATASETS");
+    papszMetadata = const_cast<char**>(m_Dataset->GetDataSet()->GetMetadata("SUBDATASETS"));
     // TODO: we might want to keep the list of names somewhere, at least the number of datasets
     std::vector<std::string> names;
     if (CSLCount(papszMetadata) > 0)
@@ -741,7 +741,7 @@
 
   if (m_NumberOfDimensions == 3)
     m_Spacing[2] = 1;
-  char** papszMetadata = dataset->GetMetadata(nullptr);
+  char** papszMetadata = const_cast<char**>(dataset->GetMetadata(nullptr));
 
   /* -------------------------------------------------------------------- */
   /*      Report general info.                                            */
@@ -930,7 +930,7 @@
   /*      Report metadata.                                                */
   /* -------------------------------------------------------------------- */
 
-  papszMetadata = dataset->GetMetadata(nullptr);
+  papszMetadata = const_cast<char**>(dataset->GetMetadata(nullptr));
   if (CSLCount(papszMetadata) > 0)
   {
     std::string key;
@@ -978,7 +978,7 @@
   /*      Report subdatasets.                                             */
   /* -------------------------------------------------------------------- */
 
-  papszMetadata = dataset->GetMetadata("SUBDATASETS");
+  papszMetadata = const_cast<char**>(dataset->GetMetadata("SUBDATASETS"));
   if (CSLCount(papszMetadata) > 0)
   {
     std::string key;
@@ -1125,7 +1125,7 @@
   ImportMetadata();
 
   // Read AREA_OR_POINT value if present
-  papszMetadata = dataset->GetMetadata(nullptr);
+  papszMetadata = const_cast<char**>(dataset->GetMetadata(nullptr));
   auto areaOrPoint = CSLFetchNameValue(papszMetadata, "AREA_OR_POINT");
   if (areaOrPoint)
     m_Imd.Add(MDStr::AreaOrPoint, areaOrPoint);
