From 23ed6e9cd0e8c60b58bd26aaa78d531eb74550eb Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 4 Feb 2021 17:04:18 +1000 Subject: [PATCH] Fix GeometryCollect aggregate detection of geometry result type when running from external python applications --- src/core/qgsaggregatecalculator.cpp | 36 ++++++++++++++++++----------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/core/qgsaggregatecalculator.cpp b/src/core/qgsaggregatecalculator.cpp index 998e0dff261..f1c74e3b708 100644 --- a/src/core/qgsaggregatecalculator.cpp +++ b/src/core/qgsaggregatecalculator.cpp @@ -102,23 +102,31 @@ QVariant QgsAggregateCalculator::calculate( QgsAggregateCalculator::Aggregate ag QVariant::Type resultType = QVariant::Double; if ( attrNum == -1 ) { - // evaluate first feature, check result type - QgsFeatureRequest testRequest( request ); - testRequest.setLimit( 1 ); - QgsFeature f; - QgsFeatureIterator fit = mLayer->getFeatures( testRequest ); - if ( !fit.nextFeature( f ) ) + if ( aggregate == GeometryCollect ) { - //no matching features - if ( ok ) - *ok = true; - return defaultValue( aggregate ); + // in this case we know the result should be a geometry value, so no need to sniff it out... + resultType = QVariant::UserType; } + else + { + // evaluate first feature, check result type + QgsFeatureRequest testRequest( request ); + testRequest.setLimit( 1 ); + QgsFeature f; + QgsFeatureIterator fit = mLayer->getFeatures( testRequest ); + if ( !fit.nextFeature( f ) ) + { + //no matching features + if ( ok ) + *ok = true; + return defaultValue( aggregate ); + } - if ( context ) - context->setFeature( f ); - QVariant v = expression->evaluate( context ); - resultType = v.type(); + if ( context ) + context->setFeature( f ); + QVariant v = expression->evaluate( context ); + resultType = v.type(); + } } else resultType = mLayer->fields().at( attrNum ).type();