Skip to content

Commit f5601d5

Browse files
committedMay 3, 2018
[processing] Also warn on non-matching point and extent CRS
if algorithm cannot handle automatic reprojection (cherry-picked from 386495b)
1 parent 61c4cfa commit f5601d5

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed
 

‎src/core/processing/qgsprocessingalgorithm.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ bool QgsProcessingAlgorithm::validateInputCrs( const QVariantMap &parameters, Qg
167167
QgsCoordinateReferenceSystem crs;
168168
Q_FOREACH ( const QgsProcessingParameterDefinition *def, mParameters )
169169
{
170-
if ( def->type() == QStringLiteral( "layer" ) || def->type() == QStringLiteral( "raster" ) )
170+
if ( def->type() == QgsProcessingParameterMapLayer::typeName() || def->type() == QgsProcessingParameterRasterLayer::typeName() )
171171
{
172172
QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( def, parameters, context );
173173
if ( layer )
@@ -183,7 +183,7 @@ bool QgsProcessingAlgorithm::validateInputCrs( const QVariantMap &parameters, Qg
183183
}
184184
}
185185
}
186-
else if ( def->type() == QStringLiteral( "source" ) )
186+
else if ( def->type() == QgsProcessingParameterFeatureSource::typeName() )
187187
{
188188
std::unique_ptr< QgsFeatureSource > source( QgsProcessingParameters::parameterAsSource( def, parameters, context ) );
189189
if ( source )
@@ -199,7 +199,7 @@ bool QgsProcessingAlgorithm::validateInputCrs( const QVariantMap &parameters, Qg
199199
}
200200
}
201201
}
202-
else if ( def->type() == QStringLiteral( "multilayer" ) )
202+
else if ( def->type() == QgsProcessingParameterMultipleLayers::typeName() )
203203
{
204204
QList< QgsMapLayer *> layers = QgsProcessingParameters::parameterAsLayerList( def, parameters, context );
205205
Q_FOREACH ( QgsMapLayer *layer, layers )
@@ -218,6 +218,32 @@ bool QgsProcessingAlgorithm::validateInputCrs( const QVariantMap &parameters, Qg
218218
}
219219
}
220220
}
221+
else if ( def->type() == QgsProcessingParameterExtent::typeName() )
222+
{
223+
QgsCoordinateReferenceSystem extentCrs = QgsProcessingParameters::parameterAsExtentCrs( def, parameters, context );
224+
if ( foundCrs && extentCrs.isValid() && crs != extentCrs )
225+
{
226+
return false;
227+
}
228+
else if ( !foundCrs && extentCrs.isValid() )
229+
{
230+
foundCrs = true;
231+
crs = extentCrs;
232+
}
233+
}
234+
else if ( def->type() == QgsProcessingParameterPoint::typeName() )
235+
{
236+
QgsCoordinateReferenceSystem pointCrs = QgsProcessingParameters::parameterAsPointCrs( def, parameters, context );
237+
if ( foundCrs && pointCrs.isValid() && crs != pointCrs )
238+
{
239+
return false;
240+
}
241+
else if ( !foundCrs && pointCrs.isValid() )
242+
{
243+
foundCrs = true;
244+
crs = pointCrs;
245+
}
246+
}
221247
}
222248
return true;
223249
}

‎tests/src/analysis/testqgsprocessing.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,24 @@ class DummyAlgorithm : public QgsProcessingAlgorithm
255255
addParameter( new QgsProcessingParameterMultipleLayers( "p5" ) );
256256
parameters.insert( "p5", QVariantList() << layer4326->id() << r1->id() );
257257
QVERIFY( !validateInputCrs( parameters, context ) );
258+
259+
// extent
260+
parameters.clear();
261+
parameters.insert( "p1", QVariant::fromValue( layer3111 ) );
262+
addParameter( new QgsProcessingParameterExtent( "extent" ) );
263+
parameters.insert( "extent", QgsReferencedRectangle( QgsRectangle( 1, 2, 3, 4 ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ) ) );
264+
QVERIFY( !validateInputCrs( parameters, context ) );
265+
parameters.insert( "extent", QgsReferencedRectangle( QgsRectangle( 1, 2, 3, 4 ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3111" ) ) ) );
266+
QVERIFY( validateInputCrs( parameters, context ) );
267+
268+
// point
269+
parameters.clear();
270+
parameters.insert( "p1", QVariant::fromValue( layer3111 ) );
271+
addParameter( new QgsProcessingParameterPoint( "point" ) );
272+
parameters.insert( "point", QgsReferencedPointXY( QgsPointXY( 1, 2 ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ) ) );
273+
QVERIFY( !validateInputCrs( parameters, context ) );
274+
parameters.insert( "point", QgsReferencedPointXY( QgsPointXY( 1, 2 ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3111" ) ) ) );
275+
QVERIFY( validateInputCrs( parameters, context ) );
258276
}
259277

260278
void runAsPythonCommandChecks()

0 commit comments

Comments
 (0)
Please sign in to comment.