Skip to content
Permalink
Browse files

[processing] Also warn on non-matching point and extent CRS

if algorithm cannot handle automatic reprojection

(cherry-picked from 386495b)
  • Loading branch information
nyalldawson committed May 3, 2018
1 parent 61c4cfa commit f5601d585db49e4bed84fa7fd00d3311f9919e33
Showing with 47 additions and 3 deletions.
  1. +29 −3 src/core/processing/qgsprocessingalgorithm.cpp
  2. +18 −0 tests/src/analysis/testqgsprocessing.cpp
@@ -167,7 +167,7 @@ bool QgsProcessingAlgorithm::validateInputCrs( const QVariantMap &parameters, Qg
QgsCoordinateReferenceSystem crs;
Q_FOREACH ( const QgsProcessingParameterDefinition *def, mParameters )
{
if ( def->type() == QStringLiteral( "layer" ) || def->type() == QStringLiteral( "raster" ) )
if ( def->type() == QgsProcessingParameterMapLayer::typeName() || def->type() == QgsProcessingParameterRasterLayer::typeName() )
{
QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( def, parameters, context );
if ( layer )
@@ -183,7 +183,7 @@ bool QgsProcessingAlgorithm::validateInputCrs( const QVariantMap &parameters, Qg
}
}
}
else if ( def->type() == QStringLiteral( "source" ) )
else if ( def->type() == QgsProcessingParameterFeatureSource::typeName() )
{
std::unique_ptr< QgsFeatureSource > source( QgsProcessingParameters::parameterAsSource( def, parameters, context ) );
if ( source )
@@ -199,7 +199,7 @@ bool QgsProcessingAlgorithm::validateInputCrs( const QVariantMap &parameters, Qg
}
}
}
else if ( def->type() == QStringLiteral( "multilayer" ) )
else if ( def->type() == QgsProcessingParameterMultipleLayers::typeName() )
{
QList< QgsMapLayer *> layers = QgsProcessingParameters::parameterAsLayerList( def, parameters, context );
Q_FOREACH ( QgsMapLayer *layer, layers )
@@ -218,6 +218,32 @@ bool QgsProcessingAlgorithm::validateInputCrs( const QVariantMap &parameters, Qg
}
}
}
else if ( def->type() == QgsProcessingParameterExtent::typeName() )
{
QgsCoordinateReferenceSystem extentCrs = QgsProcessingParameters::parameterAsExtentCrs( def, parameters, context );
if ( foundCrs && extentCrs.isValid() && crs != extentCrs )
{
return false;
}
else if ( !foundCrs && extentCrs.isValid() )
{
foundCrs = true;
crs = extentCrs;
}
}
else if ( def->type() == QgsProcessingParameterPoint::typeName() )
{
QgsCoordinateReferenceSystem pointCrs = QgsProcessingParameters::parameterAsPointCrs( def, parameters, context );
if ( foundCrs && pointCrs.isValid() && crs != pointCrs )
{
return false;
}
else if ( !foundCrs && pointCrs.isValid() )
{
foundCrs = true;
crs = pointCrs;
}
}
}
return true;
}
@@ -255,6 +255,24 @@ class DummyAlgorithm : public QgsProcessingAlgorithm
addParameter( new QgsProcessingParameterMultipleLayers( "p5" ) );
parameters.insert( "p5", QVariantList() << layer4326->id() << r1->id() );
QVERIFY( !validateInputCrs( parameters, context ) );

// extent
parameters.clear();
parameters.insert( "p1", QVariant::fromValue( layer3111 ) );
addParameter( new QgsProcessingParameterExtent( "extent" ) );
parameters.insert( "extent", QgsReferencedRectangle( QgsRectangle( 1, 2, 3, 4 ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ) ) );
QVERIFY( !validateInputCrs( parameters, context ) );
parameters.insert( "extent", QgsReferencedRectangle( QgsRectangle( 1, 2, 3, 4 ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3111" ) ) ) );
QVERIFY( validateInputCrs( parameters, context ) );

// point
parameters.clear();
parameters.insert( "p1", QVariant::fromValue( layer3111 ) );
addParameter( new QgsProcessingParameterPoint( "point" ) );
parameters.insert( "point", QgsReferencedPointXY( QgsPointXY( 1, 2 ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ) ) );
QVERIFY( !validateInputCrs( parameters, context ) );
parameters.insert( "point", QgsReferencedPointXY( QgsPointXY( 1, 2 ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3111" ) ) ) );
QVERIFY( validateInputCrs( parameters, context ) );
}

void runAsPythonCommandChecks()

0 comments on commit f5601d5

Please sign in to comment.
You can’t perform that action at this time.