Skip to content

Commit

Permalink
Merge pull request #41161 from elpaso/bugfix-gh41109-followup
Browse files Browse the repository at this point in the history
Followup #41109: fix algorithms
  • Loading branch information
elpaso committed Jan 26, 2021
2 parents 2206831 + 6e9389c commit f4c21f5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
Expand Up @@ -18,7 +18,7 @@
<ogr:intval>33</ogr:intval>
<ogr:floatval>44.123456</ogr:floatval>
<ogr:date_count>4</ogr:date_count>
<ogr:date_unique>3</ogr:date_unique>
<ogr:date_unique>4</ogr:date_unique>
<ogr:date_empty>1</ogr:date_empty>
<ogr:date_filled>3</ogr:date_filled>
<ogr:date_min>2005/09/13</ogr:date_min>
Expand Down
Expand Up @@ -1115,7 +1115,7 @@ tests:
rules:
- 'Analyzed field: date_time'
- 'Count: 4'
- 'Unique values: 3'
- 'Unique values: 4'
- 'Minimum value: 2014-11-30T14:30:02'
- 'Maximum value: 2016-11-30T14:29:22'
- 'NULL \(missing\) values: 1'
Expand All @@ -1134,7 +1134,7 @@ tests:
rules:
- 'Analyzed field: date'
- 'Count: 4'
- 'Unique values: 3'
- 'Unique values: 4'
- 'Minimum value: 2014-11-30T00:00:00'
- 'Maximum value: 2016-11-30T00:00:00'
- 'NULL \(missing\) values: 1'
Expand All @@ -1153,7 +1153,7 @@ tests:
rules:
- 'Analyzed field: time'
- 'Count: 4'
- 'Unique values: 3'
- 'Unique values: 4'
- 'Minimum value: 03:29:40'
- 'Maximum value: 15:29:22'
- 'NULL \(missing\) values: 1'
Expand Down
6 changes: 3 additions & 3 deletions src/analysis/processing/qgsalgorithmpointslayerfromtable.cpp
Expand Up @@ -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() ) );
Expand Down
12 changes: 7 additions & 5 deletions src/core/qgsdatetimestatisticalsummary.cpp
Expand Up @@ -58,28 +58,30 @@ void QgsDateTimeStatisticalSummary::calculate( const QVariantList &values )

void QgsDateTimeStatisticalSummary::addValue( const QVariant &value )
{

if ( value.type() == QVariant::DateTime )
{
testDateTime( value.toDateTime() );
testDateTime( value.toDateTime(), value.isNull() );
}
else if ( value.type() == QVariant::Date )
{
QDate date = value.toDate();
testDateTime( date.isValid() ? QDateTime( date, QTime( 0, 0, 0 ) )
: QDateTime() );
: QDateTime(), value.isNull() );
}
else if ( value.type() == QVariant::Time )
{
mIsTimes = true;
QTime time = value.toTime();
testDateTime( time.isValid() ? QDateTime( QDate::fromJulianDay( 0 ), time )
: QDateTime() );
: QDateTime(), value.isNull() );
}
else //not a date
{
mCountMissing++;
mCount++;
}

// QTime?
}

Expand All @@ -89,11 +91,11 @@ void QgsDateTimeStatisticalSummary::finalize()
//if statistics are implemented which require a post-calculation step
}

void QgsDateTimeStatisticalSummary::testDateTime( const QDateTime &dateTime )
void QgsDateTimeStatisticalSummary::testDateTime( const QDateTime &dateTime, bool isNull )
{
mCount++;

if ( !dateTime.isValid() )
if ( !dateTime.isValid() || isNull )
mCountMissing++;

if ( mStatistics & CountDistinct )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsdatetimestatisticalsummary.h
Expand Up @@ -174,7 +174,7 @@ class CORE_EXPORT QgsDateTimeStatisticalSummary
QDateTime mMax;
bool mIsTimes;

void testDateTime( const QDateTime &dateTime );
void testDateTime( const QDateTime &dateTime, bool isNull );
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDateTimeStatisticalSummary::Statistics )
Expand Down

0 comments on commit f4c21f5

Please sign in to comment.