Skip to content
Permalink
Browse files

Followup #41109: fix algorithms

Check for NULL instead of valid (because NULL is valid).

The old behavior was relying on the fact that a NULL attribute was
stored by OGR as an empty string instead of a NULL QVariant of the
corresponding field type, the conversion of the QVariant( QString())
to a numeric field was checked (and it was failing) so everything
worked (at least for non-string types).

(cherry picked from commit d66d66e)
  • Loading branch information
elpaso authored and nyalldawson committed Feb 19, 2021
1 parent 2bf54c1 commit 496b10b1fad888c77b0024faddba4e05eb62af07
@@ -132,14 +132,14 @@ QVariantMap QgsPointsLayerFromTableAlgorithm::processAlgorithm( const QVariantMa
double x = attrs.at( xFieldIndex ).toDouble( &xOk );
double y = attrs.at( yFieldIndex ).toDouble( &yOk );

if ( xOk && yOk )
if ( ! attrs.at( xFieldIndex ).isNull() && ! attrs.at( yFieldIndex ).isNull() && xOk && yOk )
{
QgsPoint point( x, y );

if ( zFieldIndex >= 0 )
if ( zFieldIndex >= 0 && ! attrs.at( zFieldIndex ).isNull() )
point.addZValue( attrs.at( zFieldIndex ).toDouble() );

if ( mFieldIndex >= 0 )
if ( mFieldIndex >= 0 && ! attrs.at( mFieldIndex ).isNull() )
point.addMValue( attrs.at( mFieldIndex ).toDouble() );

f.setGeometry( QgsGeometry( point.clone() ) );
@@ -65,14 +65,14 @@ void QgsDateTimeStatisticalSummary::addValue( const QVariant &value )
else if ( value.type() == QVariant::Date )
{
QDate date = value.toDate();
testDateTime( date.isValid() ? QDateTime( date, QTime( 0, 0, 0 ) )
testDateTime( ! date.isNull() ? QDateTime( date, QTime( 0, 0, 0 ) )
: QDateTime() );
}
else if ( value.type() == QVariant::Time )
{
mIsTimes = true;
QTime time = value.toTime();
testDateTime( time.isValid() ? QDateTime( QDate::fromJulianDay( 0 ), time )
testDateTime( ! time.isNull() ? QDateTime( QDate::fromJulianDay( 0 ), time )
: QDateTime() );
}
else //not a date

0 comments on commit 496b10b

Please sign in to comment.