From d621b7fb7aa4863496b1e4bcb794c9e32de01bec Mon Sep 17 00:00:00 2001
From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org>
Date: Wed, 20 May 2009 16:09:08 +0800
Subject: [PATCH] BUG: fixes bug on geographic projections

---
 Code/Projections/otbGenericMapProjection.txx  |  3 ++-
 Code/Projections/otbGenericRSTransform.txx    | 26 ++++++++++++++++++-
 .../gdal/ossimOgcWktTranslator.cpp            | 16 ++++++++----
 3 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/Code/Projections/otbGenericMapProjection.txx b/Code/Projections/otbGenericMapProjection.txx
index ecd020cb26..f0d9b8449c 100644
--- a/Code/Projections/otbGenericMapProjection.txx
+++ b/Code/Projections/otbGenericMapProjection.txx
@@ -120,7 +120,8 @@ GenericMapProjection<Transform, TScalarType, NInputDimensions, NOutputDimensions
 
     if (!projectionInformationAvailable)
     {
-      itkExceptionMacro(<<"Impossible to create the projection from string: "<< m_ProjectionRefWkt);
+      std::cout << "WARNING: Impossible to create the projection from string: "<< m_ProjectionRefWkt << std::endl;
+      return false;
     }
 
     m_MapProjection = ossimMapProjectionFactory::instance()->createProjection(kwl);
diff --git a/Code/Projections/otbGenericRSTransform.txx b/Code/Projections/otbGenericRSTransform.txx
index 22098779f7..d4aa51a472 100644
--- a/Code/Projections/otbGenericRSTransform.txx
+++ b/Code/Projections/otbGenericRSTransform.txx
@@ -24,6 +24,9 @@ PURPOSE.  See the above copyright notices for more information.
 // #include "projection/ossimMapProjection.h"
 #include "itkMetaDataObject.h"
 
+//TODO OTB wrapper around the WKT/ossimProjection/isGeographic, etc.
+#include "ogr_spatialref.h"
+
 namespace otb
 {
 
@@ -290,7 +293,28 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
   if (m_InputTransform.IsNull())//default if we didn't manage to instantiate it before
   {
     m_InputTransform = itk::IdentityTransform< double, 2 >::New();
-    firstTransformGiveGeo = false;
+//     firstTransformGiveGeo = false;
+
+    OGRSpatialReferenceH  hSRS = NULL;
+    hSRS = OSRNewSpatialReference(NULL);
+    const char * wktString = m_InputProjectionRef.c_str();
+    if( OSRImportFromWkt( hSRS, (char **) &wktString ) != OGRERR_NONE )
+    {
+      OSRDestroySpatialReference( hSRS );
+      firstTransformGiveGeo = false;
+    }
+
+    else if (static_cast<OGRSpatialReference *>(hSRS)->IsGeographic())
+    {
+      OSRDestroySpatialReference( hSRS );
+      firstTransformGiveGeo = true;
+    }
+    else
+    {
+      OSRDestroySpatialReference( hSRS );
+      firstTransformGiveGeo = false;
+    }
+
     otbMsgDevMacro(<< "Input projection set to identity")
   }
 
diff --git a/Utilities/otbossimplugins/gdal/ossimOgcWktTranslator.cpp b/Utilities/otbossimplugins/gdal/ossimOgcWktTranslator.cpp
index a90dea15d5..917952315e 100644
--- a/Utilities/otbossimplugins/gdal/ossimOgcWktTranslator.cpp
+++ b/Utilities/otbossimplugins/gdal/ossimOgcWktTranslator.cpp
@@ -395,6 +395,12 @@ bool ossimOgcWktTranslator::toOssimKwl( const ossimString& wktString,
       return false;
    }
 
+   if (static_cast<OGRSpatialReference *>(hSRS)->IsGeographic())
+   {
+     OSRDestroySpatialReference( hSRS );
+     return false;
+   }
+
    // Determine if State Plane Coordinate System
    ossimString ossimProj = "";
    const ossimStatePlaneProjectionInfo* spi = NULL;
@@ -448,11 +454,11 @@ bool ossimOgcWktTranslator::toOssimKwl( const ossimString& wktString,
          {
 	    ossimProj = "ossimBngProjection";
          }
-//          else if (ossim_units.contains("degree"))
-//          {
-//             // Assumption...
-//             ossimProj = "ossimEquDistCylProjection";
-//          }
+         else if (ossim_units.contains("degree"))
+         {
+            // Assumption...
+            ossimProj = "ossimEquDistCylProjection";
+         }
       }
    }
 
-- 
GitLab