Skip to content

Commit a7ffa9f

Browse files
root676nyalldawson
authored andcommittedNov 26, 2019
fix parameter names and add crs and attempts parameters to advanced parameter group
1 parent 03f0dd6 commit a7ffa9f

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed
 

‎src/analysis/processing/qgsalgorithmrandompointsextent.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,18 @@ QString QgsRandomPointsExtentAlgorithm::groupId() const
4949

5050
void QgsRandomPointsExtentAlgorithm::initAlgorithm( const QVariantMap & )
5151
{
52+
5253
addParameter( new QgsProcessingParameterExtent( QStringLiteral( "EXTENT" ), QObject::tr( "Input extent" ) ) );
53-
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "NUM_POINTS" ), QStringLiteral( "Number of points" ), QgsProcessingParameterNumber::Integer, 1, false, 1 ) );
54-
addParameter( new QgsProcessingParameterCrs( QStringLiteral( "CRS" ), QObject::tr( "Target CRS" ), QStringLiteral( "ProjectCrs" ) ) );
55-
addParameter( new QgsProcessingParameterDistance( QStringLiteral( "MIN_DISTANCE" ), QObject::tr( "Minimum distance between points" ), 0, QStringLiteral( "CRS" ), true, 0 ) );
56-
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "MAX_ATTEMPTS" ), QStringLiteral( "Maximum number of attempts given the minimum distance" ), QgsProcessingParameterNumber::Integer, 200, true, 1 ) );
54+
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "POINTS_NUMBER" ), QObject::tr( "Number of points" ), QgsProcessingParameterNumber::Integer, 1, false, 1 ) );
55+
addParameter( new QgsProcessingParameterDistance( QStringLiteral( "MIN_DISTANCE" ), QObject::tr( "Minimum distance between points" ), 0, QStringLiteral( "TARGET_CRS" ), true, 0 ) );
56+
57+
std::unique_ptr< QgsProcessingParameterCrs > crs_param = qgis::make_unique< QgsProcessingParameterCrs >( QStringLiteral( "TARGET_CRS" ), QObject::tr( "Target CRS" ), QStringLiteral( "ProjectCrs" ), true ) ;
58+
crs_param->setFlags( crs_param->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
59+
addParameter( crs_param.release() );
60+
std::unique_ptr< QgsProcessingParameterNumber > maxAttempts_param = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "MAX_ATTEMPTS" ), QObject::tr( "Maximum number of search attempts given the minimum distance" ), QgsProcessingParameterNumber::Integer, 200, true, 1 );
61+
maxAttempts_param->setFlags( maxAttempts_param->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
62+
addParameter( maxAttempts_param.release() );
63+
5764
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Random points" ), QgsProcessing::TypeVectorPoint ) );
5865
}
5966

@@ -76,9 +83,17 @@ QgsRandomPointsExtentAlgorithm *QgsRandomPointsExtentAlgorithm::createInstance()
7683

7784
bool QgsRandomPointsExtentAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
7885
{
79-
mCrs = parameterAsCrs( parameters, QStringLiteral( "CRS" ), context );
86+
QgsCoordinateReferenceSystem extent_crs = parameterAsExtentCrs( parameters, QStringLiteral( "EXTENT" ), context);
87+
QgsCoordinateReferenceSystem user_crs = parameterAsCrs( parameters, QStringLiteral( "TARGET_CRS" ), context );
88+
89+
//prefer user crs over extent/project crs if defined
90+
if( extent_crs != user_crs )
91+
mCrs = user_crs;
92+
else
93+
mCrs = extent_crs;
94+
8095
mExtent = parameterAsExtent( parameters, QStringLiteral( "EXTENT" ), context, mCrs );
81-
mNumPoints = parameterAsInt( parameters, QStringLiteral( "NUM_POINTS" ), context );
96+
mNumPoints = parameterAsInt( parameters, QStringLiteral( "POINTS_NUMBER" ), context );
8297
mDistance = parameterAsDouble( parameters, QStringLiteral( "MIN_DISTANCE" ), context );
8398
mMaxAttempts = parameterAsInt( parameters, QStringLiteral( "MAX_ATTEMPTS" ), context );
8499

0 commit comments

Comments
 (0)
Please sign in to comment.