Commit 768d1f9c authored by Cédric Traizet's avatar Cédric Traizet
Browse files

Merge branch 'new_improve_qgis_param_w_vectordatalist' into 'develop'

ENH: Improve QGIS field parameter selection

See merge request !846
parents 613bfa77 4c560433
Pipeline #8479 passed with stages
in 4 minutes and 19 seconds
......@@ -16,19 +16,19 @@ for the binary packages of OTB 7.1 and above. In this case QGIS 3.14 or more sho
The table below summarizes which version of OTB can be used with which version of QGIS.
+---------------+-----------------+-----------------+-----------------+
| | QGIS 3.8 - 3.12 | QGIS 3.14 | QGIS 3.16 |
+---------------+-----------------+-----------------+-----------------+
| OTB 6.6.1 | Compatible | Compatible | Compatible |
+---------------+-----------------+-----------------+-----------------+
| OTB 7.0.0 | Compatible | Compatible | Compatible |
+---------------+-----------------+-----------------+-----------------+
| OTB 7.1.0 | Not Compatible | Compatible | Compatible |
+---------------+-----------------+-----------------+-----------------+
| OTB 7.2.0 | Not Compatible | Compatible | Compatible |
+---------------+-----------------+-----------------+-----------------+
| OTB 8.0.0 | Not Compatible | Not Compatible | Compatible |
+---------------+-----------------+-----------------+-----------------+
+---------------+-----------------+-----------------+-----------------+-----------------+
| | QGIS 3.8 - 3.12 | QGIS 3.14 | QGIS 3.16 | QGIS 3.18 |
+---------------+-----------------+-----------------+-----------------+-----------------+
| OTB 6.6.1 | Compatible | Compatible | Compatible | Compatible |
+---------------+-----------------+-----------------+-----------------+-----------------+
| OTB 7.0.0 | Compatible | Compatible | Compatible | Compatible |
+---------------+-----------------+-----------------+-----------------+-----------------+
| OTB 7.1.0 | Not Compatible | Compatible | Compatible | Compatible |
+---------------+-----------------+-----------------+-----------------+-----------------+
| OTB 7.2.0 | Not Compatible | Compatible | Compatible | Compatible |
+---------------+-----------------+-----------------+-----------------+-----------------+
| OTB 8.0.0 | Not Compatible | Not Compatible | Not Compatible | Compatible |
+---------------+-----------------+-----------------+-----------------+-----------------+
Troubleshooting
---------------
......
......@@ -92,15 +92,17 @@ private:
SetParameterDescription("mask", "Validity mask (only pixels corresponding to a mask value greater than 0 will be used for statistics)");
MandatoryOff("mask");
AddParameter(ParameterType_InputFilename, "vec", "Input vectors");
AddParameter(ParameterType_InputVectorData, "vec", "Input vectors");
SetParameterDescription("vec", "Input geometries to analyze");
AddParameter(ParameterType_OutputFilename, "out", "Output XML statistics file");
SetParameterDescription("out", "Output file to store statistics (XML format)");
AddParameter(ParameterType_ListView, "field", "Field Name");
AddParameter(ParameterType_Field, "field", "Field Name");
SetParameterDescription("field", "Name of the field carrying the class name in the input vectors.");
SetListViewSingleSelectionMode("field", true);
SetVectorData("field", "vec");
SetTypeFilter("field", { OFTString, OFTInteger, OFTInteger64 });
AddParameter(ParameterType_Int, "layer", "Layer Index");
SetParameterDescription("layer", "Layer index to read in the input vector file.");
......@@ -131,6 +133,7 @@ private:
ClearChoices("field");
FieldParameter::TypeFilterType typeFilter = GetTypeFilter("field");
for (int iField = 0; iField < feature.ogr().GetFieldCount(); iField++)
{
std::string key, item = feature.ogr().GetFieldDefnRef(iField)->GetNameRef();
......@@ -140,7 +143,7 @@ private:
OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(iField)->GetType();
if (fieldType == OFTString || fieldType == OFTInteger || fieldType == OFTInteger64)
if (typeFilter.empty() || std::find(typeFilter.begin(), typeFilter.end(), fieldType) != std::end(typeFilter))
{
std::string tmpKey = "field." + key.substr(0, end - key.begin());
AddChoice(tmpKey, item);
......
......@@ -70,7 +70,7 @@ private:
AddDocTag(Tags::Learning);
AddParameter(ParameterType_InputFilename, "in", "Input samples");
AddParameter(ParameterType_InputVectorData, "in", "Input samples");
SetParameterDescription("in", "Vector data file containing samples (OGR format)");
AddParameter(ParameterType_OutputFilename, "out", "Output samples");
......@@ -78,9 +78,11 @@ private:
"Output vector data file storing new samples"
"(OGR format).");
AddParameter(ParameterType_ListView, "field", "Field Name");
AddParameter(ParameterType_Field, "field", "Field Name");
SetParameterDescription("field", "Name of the field carrying the class name in the input vectors.");
SetListViewSingleSelectionMode("field", true);
SetVectorData("field", "in");
SetTypeFilter("field", { OFTString, OFTInteger, OFTInteger64 });
AddParameter(ParameterType_Int, "layer", "Layer Index");
SetParameterDescription("layer", "Layer index to read in the input vector file.");
......@@ -99,8 +101,9 @@ private:
"be generated.");
SetDefaultParameterInt("samples", 100);
AddParameter(ParameterType_ListView, "exclude", "Field names for excluded features");
AddParameter(ParameterType_Field, "exclude", "Field names for excluded features");
SetParameterDescription("exclude", "List of field names in the input vector data that will not be generated in the output file.");
SetVectorData("exclude", "in");
AddParameter(ParameterType_Choice, "strategy", "Augmentation strategy");
......@@ -162,6 +165,7 @@ private:
ClearChoices("exclude");
ClearChoices("field");
FieldParameter::TypeFilterType typeFilter = GetTypeFilter("field");
for (int iField = 0; iField < feature.ogr().GetFieldCount(); iField++)
{
std::string key, item = feature.ogr().GetFieldDefnRef(iField)->GetNameRef();
......@@ -171,7 +175,7 @@ private:
OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(iField)->GetType();
if (fieldType == OFTString || fieldType == OFTInteger || fieldType == OFTInteger64)
if (typeFilter.empty() || std::find(typeFilter.begin(), typeFilter.end(), fieldType) != std::end(typeFilter))
{
std::string tmpKey = "field." + key.substr(0, end - key.begin());
AddChoice(tmpKey, item);
......
......@@ -67,7 +67,7 @@ private:
AddParameter(ParameterType_InputImage, "in", "InputImage");
SetParameterDescription("in", "Support image");
AddParameter(ParameterType_InputFilename, "vec", "Input sampling positions");
AddParameter(ParameterType_InputVectorData, "vec", "Input sampling positions");
SetParameterDescription("vec",
"Vector data file containing sampling"
"positions. (OGR format)");
......@@ -96,9 +96,11 @@ private:
AddParameter(ParameterType_StringList, "outfield.list.names", "Output field names");
SetParameterDescription("outfield.list.names", "Full list of output field names.");
AddParameter(ParameterType_ListView, "field", "Field Name");
AddParameter(ParameterType_Field, "field", "Field Name");
SetParameterDescription("field", "Name of the field carrying the class name in the input vectors.");
SetListViewSingleSelectionMode("field", true);
SetVectorData("field", "vec");
SetTypeFilter("field", { OFTString, OFTInteger, OFTInteger64 });
AddParameter(ParameterType_Int, "layer", "Layer Index");
SetParameterDescription("layer", "Layer index to read in the input vector file.");
......@@ -134,6 +136,7 @@ private:
ClearChoices("field");
FieldParameter::TypeFilterType typeFilter = GetTypeFilter("field");
for (int iField = 0; iField < feature.ogr().GetFieldCount(); iField++)
{
std::string key, item = feature.ogr().GetFieldDefnRef(iField)->GetNameRef();
......@@ -143,7 +146,7 @@ private:
OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(iField)->GetType();
if (fieldType == OFTString || fieldType == OFTInteger || fieldType == OFTInteger64)
if (typeFilter.empty() || std::find(typeFilter.begin(), typeFilter.end(), fieldType) != std::end(typeFilter))
{
std::string tmpKey = "field." + key.substr(0, end - key.begin());
AddChoice(tmpKey, item);
......
......@@ -121,7 +121,7 @@ private:
SetParameterDescription("mask", "Validity mask (only pixels corresponding to a mask value greater than 0 will be used for statistics)");
MandatoryOff("mask");
AddParameter(ParameterType_InputFilename, "vec", "Input vectors");
AddParameter(ParameterType_InputVectorData, "vec", "Input vectors");
SetParameterDescription("vec", "Input geometries to analyse");
AddParameter(ParameterType_OutputFilename, "out", "Output vectors");
......@@ -190,9 +190,10 @@ private:
// Default strategy : smallest
SetParameterString("strategy", "smallest");
AddParameter(ParameterType_ListView, "field", "Field Name");
AddParameter(ParameterType_Field, "field", "Field Name");
SetParameterDescription("field", "Name of the field carrying the class name in the input vectors.");
SetListViewSingleSelectionMode("field", true);
SetVectorData("field", "vec");
AddParameter(ParameterType_Int, "layer", "Layer Index");
SetParameterDescription("layer", "Layer index to read in the input vector file.");
......
......@@ -105,6 +105,7 @@ void TrainImagesBase::ShareSamplingParameters()
ShareParameter("sample.vfn", "polystat.field", "Field containing the class integer label for supervision",
"Field containing the class id for supervision. "
"The values in this field shall be cast into integers.");
SetVectorData("sample.vfn", "io.vd");
}
void TrainImagesBase::ConnectSamplingParameters()
......
......@@ -49,8 +49,10 @@ void TrainVectorBase<TInputValue, TOutputValue>::DoInit()
this->MandatoryOff("layer");
this->SetDefaultParameterInt("layer", 0);
this->AddParameter(ParameterType_ListView, "feat", "Field names for training features");
this->AddParameter(ParameterType_Field, "feat", "Field names for training features");
this->SetParameterDescription("feat", "List of field names in the input vector data to be used as features for training.");
this->SetVectorData("feat", "io.vd");
this->SetTypeFilter("feat", { OFTInteger, OFTInteger64, OFTReal });
// Add validation data used to compute confusion matrix or contingency table
this->AddParameter(ParameterType_Group, "valid", "Validation data");
......@@ -68,11 +70,13 @@ void TrainVectorBase<TInputValue, TOutputValue>::DoInit()
this->SetDefaultParameterInt("valid.layer", 0);
// Add class field if we used validation
this->AddParameter(ParameterType_ListView, "cfield", "Field containing the class integer label for supervision");
this->AddParameter(ParameterType_Field, "cfield", "Field containing the class integer label for supervision");
this->SetParameterDescription("cfield",
"Field containing the class id for supervision. "
"The values in this field shall be cast into integers. "
"Only geometries with this field available will be taken into account.");
this->SetVectorData("cfield", "io.vd");
this->SetTypeFilter("cfield", { OFTString, OFTInteger, OFTInteger64, OFTReal });
this->SetListViewSingleSelectionMode("cfield", true);
this->AddParameter(ParameterType_Bool, "v", "Verbose mode");
......@@ -107,6 +111,8 @@ void TrainVectorBase<TInputValue, TOutputValue>::DoUpdateParameters()
this->ClearChoices("feat");
this->ClearChoices("cfield");
FieldParameter::TypeFilterType featTypeFilter = this->GetTypeFilter("feat");
FieldParameter::TypeFilterType cfieldTypeFilter = this->GetTypeFilter("cfield");
for (int iField = 0; iField < feature.ogr().GetFieldCount(); iField++)
{
std::string key, item = feature.ogr().GetFieldDefnRef(iField)->GetNameRef();
......@@ -116,12 +122,12 @@ void TrainVectorBase<TInputValue, TOutputValue>::DoUpdateParameters()
OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(iField)->GetType();
if (fieldType == OFTInteger || fieldType == OFTInteger64 || fieldType == OFTReal)
if (featTypeFilter.empty() || std::find(featTypeFilter.begin(), featTypeFilter.end(), fieldType) != std::end(featTypeFilter))
{
std::string tmpKey = "feat." + key.substr(0, static_cast<unsigned long>(end - key.begin()));
this->AddChoice(tmpKey, item);
}
if (fieldType == OFTString || fieldType == OFTInteger || fieldType == OFTInteger64 || fieldType == OFTReal)
if (cfieldTypeFilter.empty() || std::find(cfieldTypeFilter.begin(), cfieldTypeFilter.end(), fieldType) != std::end(cfieldTypeFilter))
{
std::string tmpKey = "cfield." + key.substr(0, static_cast<unsigned long>(end - key.begin()));
this->AddChoice(tmpKey, item);
......
......@@ -275,7 +275,7 @@ int Read(const std::string& filename, Application::Pointer this_)
std::stringstream(value) >> doubleValue;
this_->SetParameterDouble(key, doubleValue);
}
else if (type == ParameterType_StringList || type == ParameterType_ListView)
else if (type == ParameterType_StringList || type == ParameterType_ListView || type == ParameterType_Field)
{
this_->SetParameterStringList(key, values);
}
......
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