From 025e59c3e7736a9e90737ff3653356ed7f284256 Mon Sep 17 00:00:00 2001
From: Manuel Grizonnet <manuel.grizonnet@cnes.fr>
Date: Tue, 13 Feb 2018 11:16:08 +0100
Subject: [PATCH] ENH: check output filename extension before polygon analysis
 to avoid useless computation

---
 .../app/otbPolygonClassStatistics.cxx            | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/Modules/Applications/AppClassification/app/otbPolygonClassStatistics.cxx b/Modules/Applications/AppClassification/app/otbPolygonClassStatistics.cxx
index dc6bc16001..665c0facb5 100644
--- a/Modules/Applications/AppClassification/app/otbPolygonClassStatistics.cxx
+++ b/Modules/Applications/AppClassification/app/otbPolygonClassStatistics.cxx
@@ -155,6 +155,22 @@ private:
           }
         }
       }
+
+     // Check that the extension of the output parameter is XML (mandatory for
+     // StatisticsXMLFileWriter)
+     // Check it here to trigger the error before polygons analysis
+     
+     if ( HasValue("out") )
+       {
+       // Store filename extension
+       // Check that the right extension is given : expected .xml
+       const std::string extension = itksys::SystemTools::GetFilenameLastExtension(this->GetParameterString("out"));
+
+       if (itksys::SystemTools::LowerCase(extension) != ".xml")
+         {
+         otbAppLogFATAL( << extension << " is a wrong extension for parameter \"out\": Expected .xml" );
+         }
+       }
   }
 
   void DoExecute() ITK_OVERRIDE
-- 
GitLab