Skip to content

Commit

Permalink
rerun style script
Browse files Browse the repository at this point in the history
  • Loading branch information
root676 authored and nyalldawson committed Jul 2, 2020
1 parent 084190b commit f72c367
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions src/analysis/processing/qgsalgorithmcellstatistics.cpp
Expand Up @@ -107,11 +107,11 @@ void QgsCellStatisticsAlgorithm::initAlgorithm( const QVariantMap & )
<< QObject::tr( "Variety" );

addParameter( new QgsProcessingParameterEnum( QStringLiteral( "STATISTIC" ), QObject::tr( "Statistic" ), statistics, false, 0, false ) );
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "IGNORE_NODATA" ), QObject::tr( "Ignore NoData values" ), true) );
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "IGNORE_NODATA" ), QObject::tr( "Ignore NoData values" ), true ) );

addParameter( new QgsProcessingParameterRasterLayer( QStringLiteral( "REF_LAYER" ), QObject::tr( "Reference layer" ) ) );

std::unique_ptr< QgsProcessingParameterNumber > output_nodata_parameter = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "OUTPUT_NODATA_VALUE" ), QObject::tr( "Output NoData value" ), QgsProcessingParameterNumber::Double, -9999, true);
std::unique_ptr< QgsProcessingParameterNumber > output_nodata_parameter = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "OUTPUT_NODATA_VALUE" ), QObject::tr( "Output NoData value" ), QgsProcessingParameterNumber::Double, -9999, true );
output_nodata_parameter->setFlags( output_nodata_parameter->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
addParameter( output_nodata_parameter.release() );

Expand All @@ -125,14 +125,14 @@ void QgsCellStatisticsAlgorithm::initAlgorithm( const QVariantMap & )
addOutput( new QgsProcessingOutputNumber( QStringLiteral( "TOTAL_PIXEL_COUNT" ), QObject::tr( "Total pixel count" ) ) );
}

bool QgsCellStatisticsAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * feedback )
bool QgsCellStatisticsAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
QgsRasterLayer *referenceLayer = parameterAsRasterLayer( parameters, QStringLiteral( "REF_LAYER" ), context );
if ( !referenceLayer )
throw QgsProcessingException( invalidRasterError( parameters, QStringLiteral( "REF_LAYER" ) ) );

mIgnoreNoData = parameterAsBool( parameters, QStringLiteral( "IGNORE_NODATA" ), context);
mNoDataValue = parameterAsDouble( parameters, QStringLiteral( "OUTPUT_NODATA_VALUE" ), context);
mIgnoreNoData = parameterAsBool( parameters, QStringLiteral( "IGNORE_NODATA" ), context );
mNoDataValue = parameterAsDouble( parameters, QStringLiteral( "OUTPUT_NODATA_VALUE" ), context );
mCrs = referenceLayer->crs();
mRasterUnitsPerPixelX = referenceLayer->rasterUnitsPerPixelX();
mRasterUnitsPerPixelY = referenceLayer->rasterUnitsPerPixelY();
Expand All @@ -145,7 +145,7 @@ bool QgsCellStatisticsAlgorithm::prepareAlgorithm( const QVariantMap &parameters
rasterLayers.reserve( layers.count() );
for ( QgsMapLayer *l : layers )
{
if(feedback->isCanceled())
if ( feedback->isCanceled() )
break; //in case some slow data sources are loaded

if ( l->type() == QgsMapLayerType::RasterLayer )
Expand Down Expand Up @@ -184,20 +184,20 @@ QVariantMap QgsCellStatisticsAlgorithm::processAlgorithm( const QVariantMap &par
for ( int band : i.bands )
{
Qgis::DataType inputDataType = i.interface->dataType( band );
if( static_cast<int>(mDataType) < static_cast<int>(inputDataType) )
if ( static_cast<int>( mDataType ) < static_cast<int>( inputDataType ) )
mDataType = inputDataType; //if raster data type is more potent, set it as new data type
}
}

//force data types on specific functions if input data types don't match
if( method == QgsRasterAnalysisUtils::Mean || method == QgsRasterAnalysisUtils::StandardDeviation )
if ( method == QgsRasterAnalysisUtils::Mean || method == QgsRasterAnalysisUtils::StandardDeviation )
{
if( static_cast<int>(mDataType) < 6 )
if ( static_cast<int>( mDataType ) < 6 )
mDataType = Qgis::Float32; //force float on mean and stddev if all inputs are integer
}
else if ( method == QgsRasterAnalysisUtils::Count || method == QgsRasterAnalysisUtils::Variety ) //count, variety
{
if( static_cast<int>(mDataType) > 5 ) //if is floating point type
if ( static_cast<int>( mDataType ) > 5 ) //if is floating point type
mDataType = Qgis::Int32; //force integer on variety if all inputs are float or complex
}

Expand Down Expand Up @@ -237,7 +237,7 @@ QVariantMap QgsCellStatisticsAlgorithm::processAlgorithm( const QVariantMap &par
std::vector< std::unique_ptr< QgsRasterBlock > > inputBlocks;
for ( const QgsRasterAnalysisUtils::RasterLogicInput &i : mInputs )
{
if(feedback->isCanceled())
if ( feedback->isCanceled() )
break; //in case some slow data sources are loaded
for ( int band : i.bands )
{
Expand All @@ -263,14 +263,14 @@ QVariantMap QgsCellStatisticsAlgorithm::processAlgorithm( const QVariantMap &par
{
//output cell will always be NoData if NoData occurs in cellValueStack and NoData is not ignored
//this saves unnecessary iterations on the cellValueStack
if( method == QgsRasterAnalysisUtils::Count)
outputBlock->setValue( row, col, cellValueStackSize);
if ( method == QgsRasterAnalysisUtils::Count )
outputBlock->setValue( row, col, cellValueStackSize );
else
{
outputBlock->setValue( row, col, mNoDataValue );
}
}
else if ( !noDataInStack || (noDataInStack && mIgnoreNoData) )
else if ( !noDataInStack || ( noDataInStack && mIgnoreNoData ) )
{
switch ( method )
{
Expand Down
2 changes: 1 addition & 1 deletion tests/src/analysis/testqgsprocessingalgs.cpp
Expand Up @@ -2200,7 +2200,7 @@ void TestQgsProcessingAlgs::cellStatistics()
std::unique_ptr<QgsRasterLayer> outputRaster = qgis::make_unique< QgsRasterLayer >( results.value( QStringLiteral( "OUTPUT" ) ).toString(), "output", "gdal" );
std::unique_ptr< QgsRasterInterface > outputInterface( outputRaster->dataProvider()->clone() );

QCOMPARE( outputInterface->dataType(1), expectedDataType );
QCOMPARE( outputInterface->dataType( 1 ), expectedDataType );
QCOMPARE( outputRaster->width(), expectedRasterLayer->width() );
QCOMPARE( outputRaster->height(), expectedRasterLayer->height() );

Expand Down

0 comments on commit f72c367

Please sign in to comment.