diff --git a/Modules/Applications/AppClassification/app/otbVectorClassifier.cxx b/Modules/Applications/AppClassification/app/otbVectorClassifier.cxx index 5ccdf67e0c76e382ae273412e399bfcf76b53c60..5e9a245d456c883c2a1d8d5eb3bd7e1e47651ed8 100644 --- a/Modules/Applications/AppClassification/app/otbVectorClassifier.cxx +++ b/Modules/Applications/AppClassification/app/otbVectorClassifier.cxx @@ -100,25 +100,6 @@ VectorClassifier SetOfficialDocLink(); } -template<> -void -VectorClassifier -::CreatePredictionField(OGRFeatureDefn & layerDefn, otb::ogr::Layer & outLayer) -{ - int idx = layerDefn.GetFieldIndex(GetParameterString("cfield").c_str()); - if (idx >= 0) - { - if (layerDefn.GetFieldDefn(idx)->GetType() != OFTInteger) - itkExceptionMacro("Field name "<< GetParameterString("cfield") << " already exists with a different type!"); - } - else - { - OGRFieldDefn predictedField(GetParameterString("cfield").c_str(), OFTInteger); - ogr::FieldDefn predictedFieldDef(predictedField); - outLayer.CreateField(predictedFieldDef); - } -} - } } diff --git a/Modules/Applications/AppClassification/app/otbVectorRegression.cxx b/Modules/Applications/AppClassification/app/otbVectorRegression.cxx index bafb8e07b2827bb7ef492f7d2acb43894694e0a1..8af7bb8b5f431c388ea06d400a3ad36f16e7f9e3 100644 --- a/Modules/Applications/AppClassification/app/otbVectorRegression.cxx +++ b/Modules/Applications/AppClassification/app/otbVectorRegression.cxx @@ -90,25 +90,6 @@ VectorRegression SetOfficialDocLink(); } -template<> -void -VectorRegression -::CreatePredictionField(OGRFeatureDefn & layerDefn, otb::ogr::Layer & outLayer) -{ - int idx = layerDefn.GetFieldIndex(GetParameterString("cfield").c_str()); - if (idx >= 0) - { - if (layerDefn.GetFieldDefn(idx)->GetType() != OFTReal) - itkExceptionMacro("Field name "<< GetParameterString("cfield") << " already exists with a different type!"); - } - else - { - OGRFieldDefn predictedField(GetParameterString("cfield").c_str(), OFTReal); - ogr::FieldDefn predictedFieldDef(predictedField); - outLayer.CreateField(predictedFieldDef); - } -} - } } diff --git a/Modules/Applications/AppClassification/include/otbVectorPrediction.h b/Modules/Applications/AppClassification/include/otbVectorPrediction.h index bb19171b9630cc85f08f3ecff0b325d3b8841c15..14ba7193a308738d143b1148407ff43d6bfa8d2b 100644 --- a/Modules/Applications/AppClassification/include/otbVectorPrediction.h +++ b/Modules/Applications/AppClassification/include/otbVectorPrediction.h @@ -98,10 +98,6 @@ private: void DoUpdateParameters() override; - /** Create the prediction field in the output layer, this template method should be specialized - * to create the right type of field (e.g. OGRInteger or OGRReal) */ - void CreatePredictionField(OGRFeatureDefn & layerDefn, otb::ogr::Layer & outLayer); - void DoExecute() override; ModelPointerType m_Model; diff --git a/Modules/Applications/AppClassification/include/otbVectorPrediction.hxx b/Modules/Applications/AppClassification/include/otbVectorPrediction.hxx index f6edbf2a360f92fa516119f8e7995b614530a4f6..74532f9e8549d3cc87ea7be3695ae92363225c7a 100644 --- a/Modules/Applications/AppClassification/include/otbVectorPrediction.hxx +++ b/Modules/Applications/AppClassification/include/otbVectorPrediction.hxx @@ -229,13 +229,31 @@ VectorPrediction <RegressionMode> OGRFeatureDefn &layerDefn = layer.GetLayerDefn(); // Add the field of prediction in the output layer if field not exist - CreatePredictionField(layerDefn, outLayer); - + + OGRFieldType labelType; + if (RegressionMode==true) + labelType = OFTReal; + else + labelType = OFTInteger; + + int idx = layerDefn.GetFieldIndex(GetParameterString("cfield").c_str()); + if (idx >= 0) + { + if (layerDefn.GetFieldDefn(idx)->GetType() != labelType) + itkExceptionMacro("Field name "<< GetParameterString("cfield") << " already exists with a different type!"); + } + else + { + OGRFieldDefn predictedField(GetParameterString("cfield").c_str(), labelType); + ogr::FieldDefn predictedFieldDef(predictedField); + outLayer.CreateField(predictedFieldDef); + } + // Add confidence field in the output layer std::string confFieldName("confidence"); if (computeConfidenceMap) { - int idx = layerDefn.GetFieldIndex(confFieldName.c_str()); + idx = layerDefn.GetFieldIndex(confFieldName.c_str()); if (idx >= 0) { if (layerDefn.GetFieldDefn(idx)->GetType() != OFTReal)