type assertion in OGRFieldWrapper GetValue()
The GetValue<T>()
method of otbOGRFieldWrapper
returns the value of the field by calling the ogr method associated with type T, for example, if T=int, it will call ogr::GetFieldAsInteger
.
There is an assertion that compares the type of the field object from wchich the method is called to the required type (l454 of otbOGRFieldWrapper.hxx):
assert(m_Definition.GetType() == Kind::value && "OGR field type mismatches the type of requested field value");
This means that, if otb is compiled with assertion, GetValue<int>()
can only be called on integer fields, GetValue<string>()
can only be called on string fields and so on.
The GetValue<T>()
method of otbOGRFieldWrapper returns the value of the field by calling the ogr method associated with type T, for example, if T=int, it will call ogr::GetFieldAsInteger.
There is an assertion that compares the type of the field object from wchich the method is called to the required type (l454 of otbOGRFieldWrapper.hxx):
I don't think this is the expected behavior of such a function, as ogr's GetFieldAsXXX can do conversions, for example calling atoi
to convert string to int if GetFieldAsInt is called on a string field.
This method is used for example in the classification vector applications to fetch the fields and values of the input vector data. The input field can be a string (possible fields are defined in the DoExecute of the applications), but the assertion will fail as the class field is an integer.
There are a few tests failing because of this issue if the otb is compiled in debug mode (which does not happen or CI nor Dashboard if I'm correct). If we want to keep this assertion, we should replace GetValue by GetFieldAsXXX in classification applications.