Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
root676 authored and nyalldawson committed Jul 28, 2020
1 parent 83dcd27 commit 2a7dc93
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
24 changes: 12 additions & 12 deletions src/analysis/processing/qgsalgorithmrasterequaltofrequency.cpp
Expand Up @@ -68,8 +68,8 @@ QgsRasterEqualToFrequencyAlgorithm *QgsRasterEqualToFrequencyAlgorithm::createIn

void QgsRasterEqualToFrequencyAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterRasterLayer( QStringLiteral("INPUT_VALUE_RASTER"), QObject::tr("Input value raster") ) );
addParameter( new QgsProcessingParameterBand( QStringLiteral("INPUT_VALUE_RASTER_BAND"), QObject::tr("Value raster band"), 1, QStringLiteral("INPUT_VALUE_RASTER") ) );
addParameter( new QgsProcessingParameterRasterLayer( QStringLiteral( "INPUT_VALUE_RASTER" ), QObject::tr( "Input value raster" ) ) );
addParameter( new QgsProcessingParameterBand( QStringLiteral( "INPUT_VALUE_RASTER_BAND" ), QObject::tr( "Value raster band" ), 1, QStringLiteral( "INPUT_VALUE_RASTER" ) ) );


addParameter( new QgsProcessingParameterMultipleLayers( QStringLiteral( "INPUT_RASTERS" ),
Expand All @@ -83,9 +83,9 @@ void QgsRasterEqualToFrequencyAlgorithm::initAlgorithm( const QVariantMap & )

addParameter( new QgsProcessingParameterRasterDestination( QStringLiteral( "OUTPUT" ),
QObject::tr( "Output layer" ) ) );
addOutput( new QgsProcessingOutputNumber( QStringLiteral( "EQUAL_VALUES_COUNT"), QObject::tr("Count of equal value occurrances") ) );
addOutput( new QgsProcessingOutputNumber( QStringLiteral( "FOUND_LOCATIONS_COUNT" ), QObject::tr("Count of cells with equal value occurrances") ) );
addOutput( new QgsProcessingOutputNumber( QStringLiteral( "MEAN_FREQUENCY_PER_LOCATION" ), QObject::tr("Mean frequency at valid cell locations" ) ) );
addOutput( new QgsProcessingOutputNumber( QStringLiteral( "EQUAL_VALUES_COUNT" ), QObject::tr( "Count of equal value occurrances" ) ) );
addOutput( new QgsProcessingOutputNumber( QStringLiteral( "FOUND_LOCATIONS_COUNT" ), QObject::tr( "Count of cells with equal value occurrances" ) ) );
addOutput( new QgsProcessingOutputNumber( QStringLiteral( "MEAN_FREQUENCY_PER_LOCATION" ), QObject::tr( "Mean frequency at valid cell locations" ) ) );
addOutput( new QgsProcessingOutputString( QStringLiteral( "EXTENT" ), QObject::tr( "Extent" ) ) );
addOutput( new QgsProcessingOutputString( QStringLiteral( "CRS_AUTHID" ), QObject::tr( "CRS authority identifier" ) ) );
addOutput( new QgsProcessingOutputNumber( QStringLiteral( "WIDTH_IN_PIXELS" ), QObject::tr( "Width in pixels" ) ) );
Expand All @@ -99,7 +99,7 @@ bool QgsRasterEqualToFrequencyAlgorithm::prepareAlgorithm( const QVariantMap &pa
if ( !inputValueRaster )
throw QgsProcessingException( invalidRasterError( parameters, QStringLiteral( "INPUT_VALUE_RASTER" ) ) );

mInputValueRasterBand = parameterAsInt( parameters, QStringLiteral( "INPUT_VALUE_RASTER_BAND"), context );
mInputValueRasterBand = parameterAsInt( parameters, QStringLiteral( "INPUT_VALUE_RASTER_BAND" ), context );
mIgnoreNoData = parameterAsBool( parameters, QStringLiteral( "IGNORE_NODATA" ), context );

mInputValueRasterInterface.reset( inputValueRaster->dataProvider()->clone() );
Expand Down Expand Up @@ -194,7 +194,7 @@ QVariantMap QgsRasterEqualToFrequencyAlgorithm::processAlgorithm( const QVariant
}
}

std::unique_ptr< QgsRasterBlock > outputBlock = qgis::make_unique<QgsRasterBlock>( Qgis::Int32, iterCols, iterRows);
std::unique_ptr< QgsRasterBlock > outputBlock = qgis::make_unique<QgsRasterBlock>( Qgis::Int32, iterCols, iterRows );
feedback->setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
for ( int row = 0; row < iterRows; row++ )
{
Expand All @@ -209,7 +209,7 @@ QVariantMap QgsRasterEqualToFrequencyAlgorithm::processAlgorithm( const QVariant
bool valueRasterCellIsNoData = false;
double searchValue = inputBlock->valueAndNoData( row, col, valueRasterCellIsNoData );

if ( (valueRasterCellIsNoData || noDataInStack) && !mIgnoreNoData )
if ( ( valueRasterCellIsNoData || noDataInStack ) && !mIgnoreNoData )
{
//output cell will always be NoData if NoData occurs in valueRaster or cellValueStack and NoData is not ignored
//this saves unnecessary iterations on the cellValueStack
Expand All @@ -218,7 +218,7 @@ QVariantMap QgsRasterEqualToFrequencyAlgorithm::processAlgorithm( const QVariant
}
else
{
int equalCount = static_cast<int>(std::count(cellValues.begin(), cellValues.end(), searchValue));
int equalCount = static_cast<int>( std::count( cellValues.begin(), cellValues.end(), searchValue ) );
outputBlock->setValue( row, col, equalCount );
equalValuesCount += equalCount;
}
Expand All @@ -229,11 +229,11 @@ QVariantMap QgsRasterEqualToFrequencyAlgorithm::processAlgorithm( const QVariant
provider->setEditable( false );

unsigned long long foundLocationsCount = layerSize - noDataLocationsCount;
double meanEqualCountPerValidLocation = static_cast<double>(equalValuesCount) / static_cast<double>(foundLocationsCount * mInputs.size() );
double meanEqualCountPerValidLocation = static_cast<double>( equalValuesCount ) / static_cast<double>( foundLocationsCount * mInputs.size() );

QVariantMap outputs;
outputs.insert( QStringLiteral( "EQUAL_VALUES_COUNT" ), equalValuesCount);
outputs.insert( QStringLiteral( "FOUND_LOCATIONS_COUNT" ), foundLocationsCount);
outputs.insert( QStringLiteral( "EQUAL_VALUES_COUNT" ), equalValuesCount );
outputs.insert( QStringLiteral( "FOUND_LOCATIONS_COUNT" ), foundLocationsCount );
outputs.insert( QStringLiteral( "MEAN_FREQUENCY_PER_LOCATION" ), meanEqualCountPerValidLocation );
outputs.insert( QStringLiteral( "EXTENT" ), mExtent.toString() );
outputs.insert( QStringLiteral( "CRS_AUTHID" ), mCrs.authid() );
Expand Down
6 changes: 3 additions & 3 deletions tests/src/analysis/testqgsprocessingalgs.cpp
Expand Up @@ -2356,8 +2356,8 @@ void TestQgsProcessingAlgs::equalToFrequency()
QVariantMap parameters;

parameters.insert( QStringLiteral( "INPUT_VALUE_RASTER" ), myDataPath + inputValueRaster );
parameters.insert( QStringLiteral( "INPUT_VALUE_RASTER_BAND"), inputValueRasterBand);
parameters.insert( QStringLiteral( "INPUT_RASTERS"), inputDatasetPaths);
parameters.insert( QStringLiteral( "INPUT_VALUE_RASTER_BAND" ), inputValueRasterBand );
parameters.insert( QStringLiteral( "INPUT_RASTERS" ), inputDatasetPaths );
parameters.insert( QStringLiteral( "IGNORE_NODATA" ), ignoreNoData );
parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT );

Expand Down Expand Up @@ -2410,7 +2410,7 @@ void TestQgsProcessingAlgs::equalToFrequency()
QCOMPARE( outputValue, expectedValue );

Qgis::DataType outputDataType = outputRasterBlock->dataType();
QCOMPARE( outputDataType, expectedDataType);
QCOMPARE( outputDataType, expectedDataType );
}
}
}
Expand Down

0 comments on commit 2a7dc93

Please sign in to comment.