diff --git a/Modules/Applications/AppClassification/include/otbVectorPrediction.h b/Modules/Applications/AppClassification/include/otbVectorPrediction.h index 7390c407f8ebda6bd9f55fce5cc9b0b6b4e928fa..3e54cb3d0879eb3b40aed1acf3491c0a31794323 100644 --- a/Modules/Applications/AppClassification/include/otbVectorPrediction.h +++ b/Modules/Applications/AppClassification/include/otbVectorPrediction.h @@ -98,8 +98,8 @@ private: /** Method returning whether the confidence map should be computed, depending on the regression mode and input parameters */ bool shouldComputeConfidenceMap() const; - /** Method returning the input list sample from the input DataSource */ - typename ListSampleType::Pointer ReadInputListSample(ogr::DataSource::Pointer source); + /** Method returning the input list sample from the input layer */ + typename ListSampleType::Pointer ReadInputListSample(otb::ogr::Layer const& layer); /** Normalize a list sample using the statistic file given */ typename ListSampleType::Pointer NormalizeListSample(ListSampleType::Pointer input); diff --git a/Modules/Applications/AppClassification/include/otbVectorPrediction.hxx b/Modules/Applications/AppClassification/include/otbVectorPrediction.hxx index 0cc24a8befd8cc0855262c22a0e9ea9e002d1208..3f96d032aef1dc0556db58f2bec923c393ad117c 100644 --- a/Modules/Applications/AppClassification/include/otbVectorPrediction.hxx +++ b/Modules/Applications/AppClassification/include/otbVectorPrediction.hxx @@ -72,24 +72,30 @@ void VectorPrediction<RegressionMode>::DoUpdateParameters() } } -template <bool RegressionMode> -typename VectorPrediction<RegressionMode>::ListSampleType::Pointer VectorPrediction<RegressionMode>::ReadInputListSample(ogr::DataSource::Pointer source) +template <bool RegressionMode> +typename VectorPrediction<RegressionMode>::ListSampleType::Pointer +VectorPrediction<RegressionMode> +::ReadInputListSample(otb::ogr::Layer const& layer) { - auto layer = source->GetLayer(0); typename ListSampleType::Pointer input = ListSampleType::New(); const auto nbFeatures = GetSelectedItems("feat").size(); input->SetMeasurementVectorSize(nbFeatures); - - ogr::Feature feature = layer.ogr().GetNextFeature(); std::vector<int> featureFieldIndex(nbFeatures, -1); + + ogr::Layer::const_iterator it_feat = layer.cbegin(); for (unsigned int i = 0; i < nbFeatures; i++) { - featureFieldIndex[i] = feature.ogr().GetFieldIndex(GetChoiceNames("feat")[GetSelectedItems("feat")[i]].c_str()); - if (featureFieldIndex[i] < 0) - otbAppLogFATAL("The field name for feature " << GetChoiceNames("feat")[GetSelectedItems("feat")[i]].c_str() << " has not been found" << std::endl); + try + { + featureFieldIndex[i] = (*it_feat).GetFieldIndex(GetChoiceNames("feat")[GetSelectedItems("feat")[i]]); + } + catch(...) + { + otbAppLogFATAL("The field name for feature " << GetChoiceNames("feat")[GetSelectedItems("feat")[i]] << " has not been found" << std::endl); + } } - layer.ogr().ResetReading(); + for (auto const& feature : layer) { MeasurementType mv(nbFeatures); @@ -289,7 +295,7 @@ void VectorPrediction<RegressionMode>::DoExecute() ogr::DataSource::Pointer source = ogr::DataSource::New(shapefileName, ogr::DataSource::Modes::Read); auto layer = source->GetLayer(0); - auto input = ReadInputListSample(source); + auto input = ReadInputListSample(layer); ListSampleType::Pointer listSample = NormalizeListSample(input); typename LabelListSampleType::Pointer target;