Skip to content

Commit

Permalink
fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
root676 authored and nyalldawson committed Jan 14, 2021
1 parent d254d06 commit 1dda44c
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 98 deletions.
60 changes: 30 additions & 30 deletions src/analysis/processing/qgsalgorithmcellstatistics.cpp
Expand Up @@ -230,19 +230,19 @@ void QgsCellStatisticsAlgorithm::addSpecificAlgorithmParams()
addParameter( new QgsProcessingParameterEnum( QStringLiteral( "STATISTIC" ), QObject::tr( "Statistic" ), statistics, false, 0, false ) );
}

bool QgsCellStatisticsAlgorithm::prepareSpecificAlgorithmParameters(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
bool QgsCellStatisticsAlgorithm::prepareSpecificAlgorithmParameters( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
Q_UNUSED(feedback)
Q_UNUSED( feedback )
//obtain statistic method
mMethod = static_cast<QgsRasterAnalysisUtils::CellValueStatisticMethods>( parameterAsEnum( parameters, QStringLiteral( "STATISTIC" ), context ) );

//force data types on specific functions in the cellstatistics alg if input data types don't match
if (
mMethod == QgsRasterAnalysisUtils::Mean ||
mMethod == QgsRasterAnalysisUtils::StandardDeviation ||
mMethod == QgsRasterAnalysisUtils::Variance ||
(mMethod == QgsRasterAnalysisUtils::Median && (mInputs.size() % 2 == 0) )
)
mMethod == QgsRasterAnalysisUtils::Mean ||
mMethod == QgsRasterAnalysisUtils::StandardDeviation ||
mMethod == QgsRasterAnalysisUtils::Variance ||
( mMethod == QgsRasterAnalysisUtils::Median && ( mInputs.size() % 2 == 0 ) )
)
{
if ( static_cast<int>( mDataType ) < 6 )
mDataType = Qgis::Float32; //force float on mean, stddev and median with equal number of input layers if all inputs are integer
Expand All @@ -255,7 +255,7 @@ bool QgsCellStatisticsAlgorithm::prepareSpecificAlgorithmParameters(const QVaria
return true;
}

void QgsCellStatisticsAlgorithm::processRasterStack(QgsProcessingFeedback *feedback)
void QgsCellStatisticsAlgorithm::processRasterStack( QgsProcessingFeedback *feedback )
{
int maxWidth = QgsRasterIterator::DEFAULT_MAXIMUM_TILE_WIDTH;
int maxHeight = QgsRasterIterator::DEFAULT_MAXIMUM_TILE_HEIGHT;
Expand Down Expand Up @@ -413,25 +413,25 @@ QgsCellStatisticsPercentileAlgorithm *QgsCellStatisticsPercentileAlgorithm::crea

void QgsCellStatisticsPercentileAlgorithm::addSpecificAlgorithmParams()
{
addParameter( new QgsProcessingParameterEnum( QStringLiteral( "METHOD" ), QObject::tr( "Method"), QStringList() << "Nearest rank" << "Inclusive linear interpolation (PERCENTILE.INC)" << "Exclusive linear interpolation (PERCENTILE.EXC)", false, 0, false) );
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "PERCENTILE" ), QObject::tr( "Percentile" ), QgsProcessingParameterNumber::Double, 10, false, 0.0, 1.0) );
addParameter( new QgsProcessingParameterEnum( QStringLiteral( "METHOD" ), QObject::tr( "Method" ), QStringList() << "Nearest rank" << "Inclusive linear interpolation (PERCENTILE.INC)" << "Exclusive linear interpolation (PERCENTILE.EXC)", false, 0, false ) );
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "PERCENTILE" ), QObject::tr( "Percentile" ), QgsProcessingParameterNumber::Double, 10, false, 0.0, 1.0 ) );
}

bool QgsCellStatisticsPercentileAlgorithm::prepareSpecificAlgorithmParameters(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
bool QgsCellStatisticsPercentileAlgorithm::prepareSpecificAlgorithmParameters( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
Q_UNUSED(feedback)
mMethod = static_cast< QgsRasterAnalysisUtils::CellValuePercentileMethods >( parameterAsEnum( parameters, QStringLiteral("METHOD"), context) );
Q_UNUSED( feedback )
mMethod = static_cast< QgsRasterAnalysisUtils::CellValuePercentileMethods >( parameterAsEnum( parameters, QStringLiteral( "METHOD" ), context ) );
mPercentile = parameterAsDouble( parameters, QStringLiteral( "PERCENTILE" ), context );

//default percentile output data type to float32 raster if interpolation method is chosen
//otherwise use the most potent data type in the intput raster stack (see prepareAlgorithm() in base class)
if( mMethod != QgsRasterAnalysisUtils::CellValuePercentileMethods::NearestRankPercentile && mDataType < 6)
if ( mMethod != QgsRasterAnalysisUtils::CellValuePercentileMethods::NearestRankPercentile && mDataType < 6 )
mDataType = Qgis::DataType::Float32;

return true;
}

void QgsCellStatisticsPercentileAlgorithm::processRasterStack(QgsProcessingFeedback *feedback)
void QgsCellStatisticsPercentileAlgorithm::processRasterStack( QgsProcessingFeedback *feedback )
{

int maxWidth = QgsRasterIterator::DEFAULT_MAXIMUM_TILE_WIDTH;
Expand Down Expand Up @@ -554,22 +554,22 @@ QgsCellStatisticsPercentRankFromValueAlgorithm *QgsCellStatisticsPercentRankFrom

void QgsCellStatisticsPercentRankFromValueAlgorithm::addSpecificAlgorithmParams()
{
addParameter( new QgsProcessingParameterEnum( QStringLiteral( "METHOD" ), QObject::tr( "Method"), QStringList() << "Inclusive linear interpolation (PERCENTRANK.INC)" << "Exclusive linear interpolation (PERCENTRANK.EXC)", false, 0, false) );
addParameter( new QgsProcessingParameterEnum( QStringLiteral( "METHOD" ), QObject::tr( "Method" ), QStringList() << "Inclusive linear interpolation (PERCENTRANK.INC)" << "Exclusive linear interpolation (PERCENTRANK.EXC)", false, 0, false ) );
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "VALUE" ), QObject::tr( "Value" ), QgsProcessingParameterNumber::Double, 10, false ) );
}

bool QgsCellStatisticsPercentRankFromValueAlgorithm::prepareSpecificAlgorithmParameters(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
bool QgsCellStatisticsPercentRankFromValueAlgorithm::prepareSpecificAlgorithmParameters( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
Q_UNUSED(feedback)
mMethod = static_cast< QgsRasterAnalysisUtils::CellValuePercentRankMethods >( parameterAsEnum( parameters, QStringLiteral("METHOD"), context) );
Q_UNUSED( feedback )
mMethod = static_cast< QgsRasterAnalysisUtils::CellValuePercentRankMethods >( parameterAsEnum( parameters, QStringLiteral( "METHOD" ), context ) );
mValue = parameterAsDouble( parameters, QStringLiteral( "VALUE" ), context );

//output data type always defaults to Float32 because result only ranges between 0 and 1
mDataType = Qgis::DataType::Float32;
return true;
}

void QgsCellStatisticsPercentRankFromValueAlgorithm::processRasterStack(QgsProcessingFeedback *feedback)
void QgsCellStatisticsPercentRankFromValueAlgorithm::processRasterStack( QgsProcessingFeedback *feedback )
{

int maxWidth = QgsRasterIterator::DEFAULT_MAXIMUM_TILE_WIDTH;
Expand Down Expand Up @@ -680,7 +680,7 @@ QString QgsCellStatisticsPercentRankFromRasterAlgorithm::shortHelpString() const
"The output raster's extent and resolution is defined by a reference "
"raster. If the input raster layers that do not match the cell size of the reference raster layer will be "
"resampled using nearest neighbor resampling. NoData values in any of the input layers will result in a NoData cell output if the Ignore NoData parameter is not set. "
"The output raster data type will always be Float32." );
"The output raster data type will always be Float32." );
}

QgsCellStatisticsPercentRankFromRasterAlgorithm *QgsCellStatisticsPercentRankFromRasterAlgorithm::createInstance() const
Expand All @@ -690,15 +690,15 @@ QgsCellStatisticsPercentRankFromRasterAlgorithm *QgsCellStatisticsPercentRankFro

void QgsCellStatisticsPercentRankFromRasterAlgorithm::addSpecificAlgorithmParams()
{
addParameter( new QgsProcessingParameterRasterLayer( QStringLiteral( "INPUT_VALUE_RASTER"), QObject::tr( "Value raster layer") ) );
addParameter( new QgsProcessingParameterBand( QStringLiteral( "VALUE_RASTER_BAND"), QObject::tr( "Value raster band"), 1, QStringLiteral( "VALUE_LAYER" ) ) );
addParameter( new QgsProcessingParameterEnum( QStringLiteral( "METHOD" ), QObject::tr( "Method"), QStringList() << "Inclusive linear interpolation (PERCENTRANK.INC)" << "Exclusive linear interpolation (PERCENTRANK.EXC)", false, 0, false) );
addParameter( new QgsProcessingParameterRasterLayer( QStringLiteral( "INPUT_VALUE_RASTER" ), QObject::tr( "Value raster layer" ) ) );
addParameter( new QgsProcessingParameterBand( QStringLiteral( "VALUE_RASTER_BAND" ), QObject::tr( "Value raster band" ), 1, QStringLiteral( "VALUE_LAYER" ) ) );
addParameter( new QgsProcessingParameterEnum( QStringLiteral( "METHOD" ), QObject::tr( "Method" ), QStringList() << "Inclusive linear interpolation (PERCENTRANK.INC)" << "Exclusive linear interpolation (PERCENTRANK.EXC)", false, 0, false ) );
}

bool QgsCellStatisticsPercentRankFromRasterAlgorithm::prepareSpecificAlgorithmParameters(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
bool QgsCellStatisticsPercentRankFromRasterAlgorithm::prepareSpecificAlgorithmParameters( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
Q_UNUSED(feedback)
mMethod = static_cast< QgsRasterAnalysisUtils::CellValuePercentRankMethods >( parameterAsEnum( parameters, QStringLiteral("METHOD"), context) );
Q_UNUSED( feedback )
mMethod = static_cast< QgsRasterAnalysisUtils::CellValuePercentRankMethods >( parameterAsEnum( parameters, QStringLiteral( "METHOD" ), context ) );

QgsRasterLayer *inputValueRaster = parameterAsRasterLayer( parameters, QStringLiteral( "INPUT_VALUE_RASTER" ), context );
if ( !inputValueRaster )
Expand All @@ -713,7 +713,7 @@ bool QgsCellStatisticsPercentRankFromRasterAlgorithm::prepareSpecificAlgorithmPa
return true;
}

void QgsCellStatisticsPercentRankFromRasterAlgorithm::processRasterStack(QgsProcessingFeedback *feedback)
void QgsCellStatisticsPercentRankFromRasterAlgorithm::processRasterStack( QgsProcessingFeedback *feedback )
{
int maxWidth = QgsRasterIterator::DEFAULT_MAXIMUM_TILE_WIDTH;
int maxHeight = QgsRasterIterator::DEFAULT_MAXIMUM_TILE_HEIGHT;
Expand All @@ -732,7 +732,7 @@ void QgsCellStatisticsPercentRankFromRasterAlgorithm::processRasterStack(QgsProc
std::unique_ptr< QgsRasterBlock > outputBlock;
while ( outputIter.readNextRasterPart( 1, iterCols, iterRows, outputBlock, iterLeft, iterTop, &blockExtent ) )
{
std::unique_ptr< QgsRasterBlock > valueBlock ( mValueRasterInterface->block( mValueRasterBand, blockExtent, iterCols, iterRows ) );
std::unique_ptr< QgsRasterBlock > valueBlock( mValueRasterInterface->block( mValueRasterBand, blockExtent, iterCols, iterRows ) );

std::vector< std::unique_ptr< QgsRasterBlock > > inputBlocks;
for ( const QgsRasterAnalysisUtils::RasterLogicInput &i : mInputs )
Expand Down Expand Up @@ -764,7 +764,7 @@ void QgsCellStatisticsPercentRankFromRasterAlgorithm::processRasterStack(QgsProc
std::vector<double> cellValues = QgsRasterAnalysisUtils::getCellValuesFromBlockStack( inputBlocks, row, col, noDataInStack );
int cellValueStackSize = cellValues.size();

if ( noDataInStack && !mIgnoreNoData && !percentRankValueIsNoData)
if ( noDataInStack && !mIgnoreNoData && !percentRankValueIsNoData )
{
outputBlock->setValue( row, col, mNoDataValue );
}
Expand Down
56 changes: 28 additions & 28 deletions src/analysis/processing/qgsrasteranalysisutils.cpp
Expand Up @@ -485,77 +485,77 @@ double QgsRasterAnalysisUtils::nearestRankPercentile( std::vector<double> cellVa
std::sort( cellValues.begin(), cellValues.end() );

int i = 0;
if( percentile > 0 )
if ( percentile > 0 )
{
i = static_cast<int>( std::ceil( percentile * static_cast<double>(stackSize) ) - 1 );
i = static_cast<int>( std::ceil( percentile * static_cast<double>( stackSize ) ) - 1 );
}

return cellValues[i];
}

double QgsRasterAnalysisUtils::interpolatedPercentileInc( std::vector<double> cellValues, int stackSize, double percentile )
{
std::sort(cellValues.begin(), cellValues.end() );
double x = ( percentile * (stackSize - 1) );
std::sort( cellValues.begin(), cellValues.end() );
double x = ( percentile * ( stackSize - 1 ) );

int i = static_cast<int>( std::floor( x ) );
double xFraction = std::fmod(x, 1);
double xFraction = std::fmod( x, 1 );

if(stackSize == 1)
if ( stackSize == 1 )
{
return cellValues[0];
}
else if ( stackSize == 2)
else if ( stackSize == 2 )
{
return cellValues[0] + (cellValues[1] - cellValues[0]) * percentile;
return cellValues[0] + ( cellValues[1] - cellValues[0] ) * percentile;
}
else
{
return cellValues[i] + (cellValues[i+1] - cellValues[i]) * xFraction;
return cellValues[i] + ( cellValues[i + 1] - cellValues[i] ) * xFraction;
}
}

double QgsRasterAnalysisUtils::interpolatedPercentileExc( std::vector<double> cellValues, int stackSize, double percentile, double noDataValue )
{
std::sort(cellValues.begin(), cellValues.end() );
double x = ( percentile * (stackSize + 1) );
std::sort( cellValues.begin(), cellValues.end() );
double x = ( percentile * ( stackSize + 1 ) );

int i = static_cast<int>( std::floor( x ) ) - 1;
double xFraction = std::fmod(x, 1);
double lowerExcValue = 1.0 / (static_cast<double>(stackSize) + 1.0);
double upperExcValue = static_cast<double>(stackSize) / (static_cast<double>(stackSize) + 1.0);
double xFraction = std::fmod( x, 1 );
double lowerExcValue = 1.0 / ( static_cast<double>( stackSize ) + 1.0 );
double upperExcValue = static_cast<double>( stackSize ) / ( static_cast<double>( stackSize ) + 1.0 );

if(stackSize < 2 || ( (percentile < lowerExcValue || percentile > upperExcValue)) )
if ( stackSize < 2 || ( ( percentile < lowerExcValue || percentile > upperExcValue ) ) )
{
return noDataValue;
}
else
{
return cellValues[i] + (cellValues[i+1] - cellValues[i]) * xFraction;
return cellValues[i] + ( cellValues[i + 1] - cellValues[i] ) * xFraction;
}
}

double QgsRasterAnalysisUtils::interpolatedPercentRankInc( std::vector<double> cellValues, int stackSize, double value, double noDataValue )
{
std::sort( cellValues.begin(), cellValues.end() );

if( value < cellValues[0] || value > cellValues[stackSize - 1] )
if ( value < cellValues[0] || value > cellValues[stackSize - 1] )
{
return noDataValue;
}
else
{
for(int i = 0; i < stackSize - 1; i++)
for ( int i = 0; i < stackSize - 1; i++ )
{
if(cellValues[i] <= value && cellValues[i+1] >= value)
if ( cellValues[i] <= value && cellValues[i + 1] >= value )
{
double fraction = 0.0;

//make sure that next number in the distribution is not the same to prevent NaN fractions
if( !qgsDoubleNear( cellValues[i], cellValues[i+1] ) )
fraction = ( value - cellValues[i] ) / ( cellValues[i+1] - cellValues[i] );
if ( !qgsDoubleNear( cellValues[i], cellValues[i + 1] ) )
fraction = ( value - cellValues[i] ) / ( cellValues[i + 1] - cellValues[i] );

return ( fraction + i ) / (stackSize - 1);
return ( fraction + i ) / ( stackSize - 1 );
}
}
return noDataValue;
Expand All @@ -566,23 +566,23 @@ double QgsRasterAnalysisUtils::interpolatedPercentRankExc( std::vector<double> c
{
std::sort( cellValues.begin(), cellValues.end() );

if( value < cellValues[0] || value > cellValues[stackSize - 1] )
if ( value < cellValues[0] || value > cellValues[stackSize - 1] )
{
return noDataValue;
}
else
{
for (int i = 0; i < stackSize - 1; i++)
for ( int i = 0; i < stackSize - 1; i++ )
{
if(cellValues[i] <= value && cellValues[i+1] >= value)
if ( cellValues[i] <= value && cellValues[i + 1] >= value )
{
double fraction = 0.0;

//make sure that next number in the distribution is not the same to prevent NaN fractions
if( !qgsDoubleNear(cellValues[i], cellValues[i+1]) )
fraction = (value - cellValues[i]) / (cellValues[i+1] - cellValues[i]);
if ( !qgsDoubleNear( cellValues[i], cellValues[i + 1] ) )
fraction = ( value - cellValues[i] ) / ( cellValues[i + 1] - cellValues[i] );

return ( (i + 1) + fraction) / (stackSize + 1);
return ( ( i + 1 ) + fraction ) / ( stackSize + 1 );
}
}
return noDataValue;
Expand Down

0 comments on commit 1dda44c

Please sign in to comment.