Skip to content

Commit

Permalink
Default grid size parameters to not set
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 9, 2022
1 parent a4a0e10 commit 4354dcf
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
10 changes: 6 additions & 4 deletions src/analysis/processing/qgsalgorithmcalculateoverlaps.cpp
Expand Up @@ -53,8 +53,8 @@ void QgsCalculateVectorOverlapsAlgorithm::initAlgorithm( const QVariantMap & )
addParameter( new QgsProcessingParameterMultipleLayers( QStringLiteral( "LAYERS" ), QObject::tr( "Overlay layers" ), QgsProcessing::TypeVectorPolygon ) );
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Overlap" ) ) );

std::unique_ptr< QgsProcessingParameterNumber > gridSize = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "GRIDSIZE" ),
QObject::tr( "Grid size" ), QgsProcessingParameterNumber::Double, QVariant( - 1 ), true );
std::unique_ptr< QgsProcessingParameterNumber > gridSize = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "GRID_SIZE" ),
QObject::tr( "Grid size" ), QgsProcessingParameterNumber::Double, QVariant(), true, 0 );
gridSize->setFlags( gridSize->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
addParameter( gridSize.release() );
}
Expand Down Expand Up @@ -135,9 +135,11 @@ QVariantMap QgsCalculateVectorOverlapsAlgorithm::processAlgorithm( const QVarian
da.setSourceCrs( mCrs, context.transformContext() );
da.setEllipsoid( context.ellipsoid() );

const double gridSize = parameterAsDouble( parameters, QStringLiteral( "GRIDSIZE" ), context );
QgsGeometryParameters geometryParameters;
geometryParameters.setGridSize( gridSize );
if ( parameters.value( QStringLiteral( "GRID_SIZE" ) ).isValid() )
{
geometryParameters.setGridSize( parameterAsDouble( parameters, QStringLiteral( "GRID_SIZE" ), context ) );
}

// loop through input
const double step = mInputCount > 0 ? 100.0 / mInputCount : 0;
Expand Down
13 changes: 9 additions & 4 deletions src/analysis/processing/qgsalgorithmdifference.cpp
Expand Up @@ -83,8 +83,9 @@ void QgsDifferenceAlgorithm::initAlgorithm( const QVariantMap & )
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "OVERLAY" ), QObject::tr( "Overlay layer" ) ) );
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Difference" ) ) );
std::unique_ptr< QgsProcessingParameterNumber > gridSize = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "GRIDSIZE" ),
QObject::tr( "Grid size" ), QgsProcessingParameterNumber::Double, QVariant( - 1 ), true );

std::unique_ptr< QgsProcessingParameterNumber > gridSize = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "GRID_SIZE" ),
QObject::tr( "Grid size" ), QgsProcessingParameterNumber::Double, QVariant(), true, 0 );
gridSize->setFlags( gridSize->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
addParameter( gridSize.release() );
}
Expand Down Expand Up @@ -112,9 +113,13 @@ QVariantMap QgsDifferenceAlgorithm::processAlgorithm( const QVariantMap &paramet

long count = 0;
const long total = sourceA->featureCount();
const double gridSize = parameterAsDouble( parameters, QStringLiteral( "GRIDSIZE" ), context );

QgsGeometryParameters geometryParameters;
geometryParameters.setGridSize( gridSize );
if ( parameters.value( QStringLiteral( "GRID_SIZE" ) ).isValid() )
{
geometryParameters.setGridSize( parameterAsDouble( parameters, QStringLiteral( "GRID_SIZE" ), context ) );
}

QgsOverlayUtils::difference( *sourceA, *sourceB, *sink, context, feedback, count, total, QgsOverlayUtils::OutputA, geometryParameters );

return outputs;
Expand Down
12 changes: 7 additions & 5 deletions src/analysis/processing/qgsalgorithmintersection.cpp
Expand Up @@ -74,11 +74,10 @@ void QgsIntersectionAlgorithm::initAlgorithm( const QVariantMap & )

addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Intersection" ) ) );

std::unique_ptr< QgsProcessingParameterNumber > gridSize = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "GRIDSIZE" ),
QObject::tr( "Grid size" ), QgsProcessingParameterNumber::Double, QVariant( - 1 ), true );
std::unique_ptr< QgsProcessingParameterNumber > gridSize = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "GRID_SIZE" ),
QObject::tr( "Grid size" ), QgsProcessingParameterNumber::Double, QVariant(), true, 0 );
gridSize->setFlags( gridSize->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
addParameter( gridSize.release() );

}


Expand Down Expand Up @@ -116,9 +115,12 @@ QVariantMap QgsIntersectionAlgorithm::processAlgorithm( const QVariantMap &param

long count = 0;
const long total = sourceA->featureCount();
const double gridSize = parameterAsDouble( parameters, QStringLiteral( "GRIDSIZE" ), context );

QgsGeometryParameters geometryParameters;
geometryParameters.setGridSize( gridSize );
if ( parameters.value( QStringLiteral( "GRID_SIZE" ) ).isValid() )
{
geometryParameters.setGridSize( parameterAsDouble( parameters, QStringLiteral( "GRID_SIZE" ), context ) );
}

QgsOverlayUtils::intersection( *sourceA, *sourceB, *sink, context, feedback, count, total, fieldIndicesA, fieldIndicesB, geometryParameters );

Expand Down
10 changes: 6 additions & 4 deletions src/analysis/processing/qgsalgorithmsymmetricaldifference.cpp
Expand Up @@ -67,8 +67,8 @@ void QgsSymmetricalDifferenceAlgorithm::initAlgorithm( const QVariantMap & )

addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Symmetrical difference" ) ) );

std::unique_ptr< QgsProcessingParameterNumber > gridSize = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "GRIDSIZE" ),
QObject::tr( "Grid size" ), QgsProcessingParameterNumber::Double, QVariant( - 1 ), true );
std::unique_ptr< QgsProcessingParameterNumber > gridSize = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "GRID_SIZE" ),
QObject::tr( "Grid size" ), QgsProcessingParameterNumber::Double, QVariant(), true, 0 );
gridSize->setFlags( gridSize->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
addParameter( gridSize.release() );
}
Expand Down Expand Up @@ -103,10 +103,12 @@ QVariantMap QgsSymmetricalDifferenceAlgorithm::processAlgorithm( const QVariantM

long count = 0;
const long total = sourceA->featureCount() + sourceB->featureCount();
const double gridSize = parameterAsDouble( parameters, QStringLiteral( "GRIDSIZE" ), context );

QgsGeometryParameters geometryParameters;
geometryParameters.setGridSize( gridSize );
if ( parameters.value( QStringLiteral( "GRID_SIZE" ) ).isValid() )
{
geometryParameters.setGridSize( parameterAsDouble( parameters, QStringLiteral( "GRID_SIZE" ), context ) );
}

QgsOverlayUtils::difference( *sourceA, *sourceB, *sink, context, feedback, count, total, QgsOverlayUtils::OutputAB, geometryParameters );
if ( feedback->isCanceled() )
Expand Down
10 changes: 6 additions & 4 deletions src/analysis/processing/qgsalgorithmunion.cpp
Expand Up @@ -68,8 +68,8 @@ void QgsUnionAlgorithm::initAlgorithm( const QVariantMap & )

addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Union" ) ) );

std::unique_ptr< QgsProcessingParameterNumber > gridSize = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "GRIDSIZE" ),
QObject::tr( "Grid size" ), QgsProcessingParameterNumber::Double, QVariant( - 1 ), true );
std::unique_ptr< QgsProcessingParameterNumber > gridSize = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "GRID_SIZE" ),
QObject::tr( "Grid size" ), QgsProcessingParameterNumber::Double, QVariant(), true, 0 );
gridSize->setFlags( gridSize->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
addParameter( gridSize.release() );
}
Expand Down Expand Up @@ -109,10 +109,12 @@ QVariantMap QgsUnionAlgorithm::processAlgorithm( const QVariantMap &parameters,

long count = 0;
const long total = sourceA->featureCount() * 2 + sourceB->featureCount();
const double gridSize = parameterAsDouble( parameters, QStringLiteral( "GRIDSIZE" ), context );

QgsGeometryParameters geometryParameters;
geometryParameters.setGridSize( gridSize );
if ( parameters.value( QStringLiteral( "GRID_SIZE" ) ).isValid() )
{
geometryParameters.setGridSize( parameterAsDouble( parameters, QStringLiteral( "GRID_SIZE" ), context ) );
}

QgsOverlayUtils::intersection( *sourceA, *sourceB, *sink, context, feedback, count, total, fieldIndicesA, fieldIndicesB, geometryParameters );
if ( feedback->isCanceled() )
Expand Down

0 comments on commit 4354dcf

Please sign in to comment.