Skip to content

Commit

Permalink
Don't set a minimum pixel size for raster creation algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
kannes authored and nyalldawson committed Apr 23, 2023
1 parent 0f22e92 commit e68df56
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/analysis/processing/qgsalgorithmconstantraster.cpp
Expand Up @@ -66,7 +66,7 @@ void QgsConstantRasterAlgorithm::initAlgorithm( const QVariantMap & )
addParameter( new QgsProcessingParameterExtent( QStringLiteral( "EXTENT" ), QObject::tr( "Desired extent" ) ) );
addParameter( new QgsProcessingParameterCrs( QStringLiteral( "TARGET_CRS" ), QObject::tr( "Target CRS" ), QStringLiteral( "ProjectCrs" ) ) );
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "PIXEL_SIZE" ), QObject::tr( "Pixel size" ),
QgsProcessingParameterNumber::Double, 0.00001, false, 0.01 ) );
QgsProcessingParameterNumber::Double, 0.00001, false, 0 ) );
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "NUMBER" ), QObject::tr( "Constant value" ),
QgsProcessingParameterNumber::Double, 1, false ) );

Expand Down Expand Up @@ -95,6 +95,10 @@ QVariantMap QgsConstantRasterAlgorithm::processAlgorithm( const QVariantMap &par
const double value = parameterAsDouble( parameters, QStringLiteral( "NUMBER" ), context );
const int typeId = parameterAsInt( parameters, QStringLiteral( "OUTPUT_TYPE" ), context );

if ( pixelSize <= 0 ) {
throw QgsProcessingException( QObject::tr( "Pixel size must be greater than 0." ) );
}

//implement warning if input float has decimal places but is written to integer raster
double fractpart;
double intpart;
Expand Down
6 changes: 5 additions & 1 deletion src/analysis/processing/qgsalgorithmrandomraster.cpp
Expand Up @@ -41,7 +41,7 @@ void QgsRandomRasterAlgorithmBase::initAlgorithm( const QVariantMap & )
addParameter( new QgsProcessingParameterExtent( QStringLiteral( "EXTENT" ), QObject::tr( "Desired extent" ) ) );
addParameter( new QgsProcessingParameterCrs( QStringLiteral( "TARGET_CRS" ), QObject::tr( "Target CRS" ), QStringLiteral( "ProjectCrs" ) ) );
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "PIXEL_SIZE" ), QObject::tr( "Pixel size" ),
QgsProcessingParameterNumber::Double, 1, false, 0.01 ) );
QgsProcessingParameterNumber::Double, 1, false, 0 ) );

//add specific parameters
addAlgorithmParams();
Expand All @@ -56,6 +56,10 @@ bool QgsRandomRasterAlgorithmBase::prepareAlgorithm( const QVariantMap &paramete
mExtent = parameterAsExtent( parameters, QStringLiteral( "EXTENT" ), context, mCrs );
mPixelSize = parameterAsDouble( parameters, QStringLiteral( "PIXEL_SIZE" ), context );

if ( mPixelSize <= 0 ) {
throw QgsProcessingException( QObject::tr( "Pixel size must be greater than 0." ) );
}

return true;
}

Expand Down

0 comments on commit e68df56

Please sign in to comment.