mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-15 00:02:52 -04:00
[processing] Don't crash when hitting transform exceptions
inside transform algorithm
This commit is contained in:
parent
681074bf25
commit
33669ab723
@ -79,7 +79,7 @@ bool QgsTransformAlgorithm::prepareAlgorithm( const QVariantMap ¶meters, Qgs
|
||||
return true;
|
||||
}
|
||||
|
||||
QgsFeatureList QgsTransformAlgorithm::processFeature( const QgsFeature &f, QgsProcessingContext &, QgsProcessingFeedback * )
|
||||
QgsFeatureList QgsTransformAlgorithm::processFeature( const QgsFeature &f, QgsProcessingContext &, QgsProcessingFeedback *feedback )
|
||||
{
|
||||
QgsFeature feature = f;
|
||||
if ( !mCreatedTransform )
|
||||
@ -91,12 +91,21 @@ QgsFeatureList QgsTransformAlgorithm::processFeature( const QgsFeature &f, QgsPr
|
||||
if ( feature.hasGeometry() )
|
||||
{
|
||||
QgsGeometry g = feature.geometry();
|
||||
if ( g.transform( mTransform ) == 0 )
|
||||
try
|
||||
{
|
||||
feature.setGeometry( g );
|
||||
if ( g.transform( mTransform ) == 0 )
|
||||
{
|
||||
feature.setGeometry( g );
|
||||
}
|
||||
else
|
||||
{
|
||||
feature.clearGeometry();
|
||||
}
|
||||
}
|
||||
else
|
||||
catch ( QgsCsException & )
|
||||
{
|
||||
if ( feedback )
|
||||
feedback->reportError( QObject::tr( "Encountered a transform error when reprojecting feature with id %1." ).arg( f.id() ) );
|
||||
feature.clearGeometry();
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "qgsprocessingmodelalgorithm.h"
|
||||
#include "qgsnativealgorithms.h"
|
||||
#include "qgsalgorithmimportphotos.h"
|
||||
#include "qgsalgorithmtransform.h"
|
||||
|
||||
class TestQgsProcessingAlgs: public QObject
|
||||
{
|
||||
@ -39,6 +40,7 @@ class TestQgsProcessingAlgs: public QObject
|
||||
void loadLayerAlg();
|
||||
void parseGeoTags();
|
||||
void featureFilterAlg();
|
||||
void transformAlg();
|
||||
|
||||
private:
|
||||
|
||||
@ -404,6 +406,35 @@ void TestQgsProcessingAlgs::featureFilterAlg()
|
||||
Q_ASSERT( outputParamDef2->flags() & QgsProcessingParameterDefinition::FlagHidden );
|
||||
}
|
||||
|
||||
void TestQgsProcessingAlgs::transformAlg()
|
||||
{
|
||||
std::unique_ptr< QgsProcessingAlgorithm > alg( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:reprojectlayer" ) ) );
|
||||
QVERIFY( alg );
|
||||
|
||||
std::unique_ptr< QgsProcessingContext > context = qgis::make_unique< QgsProcessingContext >();
|
||||
QgsProject p;
|
||||
context->setProject( &p );
|
||||
|
||||
QgsProcessingFeedback feedback;
|
||||
|
||||
QgsVectorLayer *layer = new QgsVectorLayer( QStringLiteral( "Point?crs=EPSG:4326field=col1:integer" ), QStringLiteral( "test" ), QStringLiteral( "memory" ) );
|
||||
QVERIFY( layer->isValid() );
|
||||
QgsFeature f;
|
||||
// add a point with a bad geometry - this should result in a transform exception!
|
||||
f.setGeometry( QgsGeometry::fromPointXY( QgsPointXY( -96215069, 41.673559 ) ) );
|
||||
QVERIFY( layer->dataProvider()->addFeature( f ) );
|
||||
p.addMapLayer( layer );
|
||||
|
||||
QVariantMap parameters;
|
||||
parameters.insert( QStringLiteral( "INPUT" ), QStringLiteral( "test" ) );
|
||||
parameters.insert( QStringLiteral( "OUTPUT" ), QStringLiteral( "memory:" ) );
|
||||
parameters.insert( QStringLiteral( "TARGET_CRS" ), QStringLiteral( "EPSG:2163" ) );
|
||||
bool ok = false;
|
||||
QVariantMap results = alg->run( parameters, *context, &feedback, &ok );
|
||||
Q_UNUSED( results );
|
||||
QVERIFY( ok );
|
||||
}
|
||||
|
||||
|
||||
QGSTEST_MAIN( TestQgsProcessingAlgs )
|
||||
#include "testqgsprocessingalgs.moc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user