Skip to content
Snippets Groups Projects
Commit 26a6ca68 authored by Guillaume Pernot's avatar Guillaume Pernot
Browse files

Fixed lost reference of "buffer" in VectorPrediction update mode

parent 8700c3a5
No related branches found
No related tags found
No related merge requests found
...@@ -104,9 +104,11 @@ private: ...@@ -104,9 +104,11 @@ private:
/** Normalize a list sample using the statistic file given */ /** Normalize a list sample using the statistic file given */
typename ListSampleType::Pointer NormalizeListSample(ListSampleType::Pointer input); typename ListSampleType::Pointer NormalizeListSample(ListSampleType::Pointer input);
/** Create the output DataSource, in update mode the input layer is buffered and the input /** Update the output DataSource : the input layer is buffered and the input data source is re opened in update mode. */
* data source is re opened in update mode. */ otb::ogr::DataSource::Pointer UpdateOutputDataSource(otb::ogr::DataSource::Pointer source, otb::ogr::Layer& layer, otb::ogr::DataSource::Pointer buffer);
otb::ogr::DataSource::Pointer CreateOutputDataSource(otb::ogr::DataSource::Pointer source, otb::ogr::Layer& layer, bool updateMode);
/** Create the output DataSource. */
otb::ogr::DataSource::Pointer CreateOutputDataSource(otb::ogr::DataSource::Pointer source, otb::ogr::Layer& layer);
/** Add a prediction field in the output layer if it does not exist. /** Add a prediction field in the output layer if it does not exist.
* If computeConfidenceMap evaluates to true a confidence field will be * If computeConfidenceMap evaluates to true a confidence field will be
......
...@@ -147,41 +147,39 @@ typename VectorPrediction<RegressionMode>::ListSampleType::Pointer VectorPredict ...@@ -147,41 +147,39 @@ typename VectorPrediction<RegressionMode>::ListSampleType::Pointer VectorPredict
template <bool RegressionMode> template <bool RegressionMode>
otb::ogr::DataSource::Pointer VectorPrediction<RegressionMode>::CreateOutputDataSource(otb::ogr::DataSource::Pointer source, otb::ogr::Layer& layer, otb::ogr::DataSource::Pointer VectorPrediction<RegressionMode>::UpdateOutputDataSource(otb::ogr::DataSource::Pointer source, otb::ogr::Layer& layer,
bool updateMode) ogr::DataSource::Pointer buffer)
{ {
ogr::DataSource::Pointer output; ogr::DataSource::Pointer output;
ogr::DataSource::Pointer buffer = ogr::DataSource::New(); // Update mode
if (updateMode) otbAppLogINFO("Update input vector data.");
{ // fill temporary buffer for the transfer
// Update mode otb::ogr::Layer inputLayer = layer;
otbAppLogINFO("Update input vector data."); layer = buffer->CopyLayer(inputLayer, std::string("Buffer"));
// fill temporary buffer for the transfer // close input data source
otb::ogr::Layer inputLayer = layer; source->Clear();
layer = buffer->CopyLayer(inputLayer, std::string("Buffer")); // Re-open input data source in update mode
// close input data source output = otb::ogr::DataSource::New(GetParameterString("in"), otb::ogr::DataSource::Modes::Update_LayerUpdate);
source->Clear(); return output;
// Re-open input data source in update mode }
output = otb::ogr::DataSource::New(GetParameterString("in"), otb::ogr::DataSource::Modes::Update_LayerUpdate);
} template <bool RegressionMode>
else otb::ogr::DataSource::Pointer VectorPrediction<RegressionMode>::CreateOutputDataSource(otb::ogr::DataSource::Pointer source, otb::ogr::Layer& layer)
{
ogr::DataSource::Pointer output;
// Create new OGRDataSource
output = ogr::DataSource::New(GetParameterString("out"), ogr::DataSource::Modes::Overwrite);
otb::ogr::Layer newLayer = output->CreateLayer(GetParameterString("out"), const_cast<OGRSpatialReference*>(layer.GetSpatialRef()), layer.GetGeomType());
// Copy existing fields
OGRFeatureDefn& inLayerDefn = layer.GetLayerDefn();
for (int k = 0; k < inLayerDefn.GetFieldCount(); k++)
{ {
// Create new OGRDataSource OGRFieldDefn fieldDefn(inLayerDefn.GetFieldDefn(k));
output = ogr::DataSource::New(GetParameterString("out"), ogr::DataSource::Modes::Overwrite); newLayer.CreateField(fieldDefn);
otb::ogr::Layer newLayer = output->CreateLayer(GetParameterString("out"), const_cast<OGRSpatialReference*>(layer.GetSpatialRef()), layer.GetGeomType());
// Copy existing fields
OGRFeatureDefn& inLayerDefn = layer.GetLayerDefn();
for (int k = 0; k < inLayerDefn.GetFieldCount(); k++)
{
OGRFieldDefn fieldDefn(inLayerDefn.GetFieldDefn(k));
newLayer.CreateField(fieldDefn);
}
} }
return output; return output;
} }
template <bool RegressionMode> template <bool RegressionMode>
void VectorPrediction<RegressionMode>::AddPredictionField(otb::ogr::Layer& outLayer, otb::ogr::Layer const& layer, bool computeConfidenceMap) void VectorPrediction<RegressionMode>::AddPredictionField(otb::ogr::Layer& outLayer, otb::ogr::Layer const& layer, bool computeConfidenceMap)
{ {
...@@ -306,7 +304,19 @@ void VectorPrediction<RegressionMode>::DoExecute() ...@@ -306,7 +304,19 @@ void VectorPrediction<RegressionMode>::DoExecute()
const bool updateMode = !(IsParameterEnabled("out") && HasValue("out")); const bool updateMode = !(IsParameterEnabled("out") && HasValue("out"));
auto output = CreateOutputDataSource(source, layer, updateMode); ogr::DataSource::Pointer buffer;
otb::ogr::DataSource::Pointer output;
if (updateMode)
{
buffer = ogr::DataSource::New();
output = UpdateOutputDataSource(source, layer, buffer);
}
else
{
output = CreateOutputDataSource(source, layer);
}
otb::ogr::Layer outLayer = output->GetLayer(0); otb::ogr::Layer outLayer = output->GetLayer(0);
OGRErr errStart = outLayer.ogr().StartTransaction(); OGRErr errStart = outLayer.ogr().StartTransaction();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment