Commit 66519d0b authored by Guillaume Pasero's avatar Guillaume Pasero

ENH: disable outputfid when no field name is given

parent 9e5de750
......@@ -148,8 +148,12 @@ private:
/** Internal samplers*/
std::vector<SamplerMapType> m_Samplers;
/** Field name to store the FID of the geometry each sample comes from */
/** Field name to store the FID of the geometry each sample comes from.
* When this name is empty, no FID is stored. */
std::string m_OriginFieldName;
/** Flag to enable/disable origin FID in outputs */
bool m_UseOriginField;
};
/**
......
......@@ -31,6 +31,7 @@ PersistentOGRDataToSamplePositionFilter<TInputImage,TMaskImage,TSampler>
{
this->SetNumberOfRequiredOutputs(2);
m_OriginFieldName = std::string("originfid");
m_UseOriginField = true;
}
template<class TInputImage, class TMaskImage, class TSampler>
......@@ -51,7 +52,11 @@ PersistentOGRDataToSamplePositionFilter<TInputImage,TMaskImage,TSampler>
// Add an extra field for the original FID
this->ClearAdditionalFields();
this->CreateAdditionalField(this->GetOriginFieldName(),OFTInteger,12);
m_UseOriginField = (this->GetOriginFieldName().size() > 0);
if (m_UseOriginField)
{
this->CreateAdditionalField(this->GetOriginFieldName(),OFTInteger,12);
}
// compute label mapping
this->ComputeClassPartition();
......@@ -179,7 +184,10 @@ PersistentOGRDataToSamplePositionFilter<TInputImage,TMaskImage,TSampler>
ogr::Layer outputLayer = this->GetInMemoryOutput(threadid,i);
ogr::Feature feat(outputLayer.GetLayerDefn());
feat.SetFrom(feature);
feat[this->GetOriginFieldName()].SetValue(static_cast<int>(feature.GetFID()));
if (m_UseOriginField)
{
feat[this->GetOriginFieldName()].SetValue(static_cast<int>(feature.GetFID()));
}
feat.SetGeometry(&ogrTmpPoint);
outputLayer.CreateFeature(feat);
break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment