From 1b15a90d6b00f58d24abbce64b39b09cad97f365 Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@orfeo-toolbox.org>
Date: Wed, 21 Oct 2015 16:38:21 +0200
Subject: [PATCH] ENH: Make GetFieldAsInteger work for Integer64 if possible
 (no overflow)

---
 .../src/otbVectorDataKeywordlist.cxx              | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/Modules/Core/VectorDataBase/src/otbVectorDataKeywordlist.cxx b/Modules/Core/VectorDataBase/src/otbVectorDataKeywordlist.cxx
index f9176647d4..446dedbd76 100644
--- a/Modules/Core/VectorDataBase/src/otbVectorDataKeywordlist.cxx
+++ b/Modules/Core/VectorDataBase/src/otbVectorDataKeywordlist.cxx
@@ -165,6 +165,21 @@ VectorDataKeywordlist
           {
           return (int)(m_FieldList[i].second.Integer);
           }
+#ifdef OTB_USE_GDAL_20
+        // Some fields that were OFTInteger with gdal 1.x are now
+        // exposed as OFTInteger64. So as to make the old code still
+        // work with the same data, here we downcast to Integer (if
+        // and only if no overflow occur).
+        if (m_FieldList[i].first->GetType() == OFTInteger64)
+          {
+          if(m_FieldList[i].second.Integer64 > itk::NumericTraits<int>::max())
+            {
+            itkExceptionMacro(<<"value "<<m_FieldList[i].second.Integer64<<" of field "<<m_FieldList[i].first->GetNameRef()<<" can not be safely casted to 32 bits integer");
+            }
+          
+          return static_cast<int>(m_FieldList[i].second.Integer64);
+          }
+#endif    
         if (m_FieldList[i].first->GetType() == OFTReal)
           {
           return (int)(m_FieldList[i].second.Real);
-- 
GitLab