@@ -42,7 +42,7 @@ class TestQgsProcessingAlgs: public QObject
42
42
*/
43
43
std::unique_ptr<QgsProcessingFeatureBasedAlgorithm> featureBasedAlg ( const QString &id );
44
44
45
- QgsFeature runForFeature ( const std::unique_ptr<QgsProcessingFeatureBasedAlgorithm> &alg, QgsFeature feature, const QString &layerType );
45
+ QgsFeature runForFeature ( const std::unique_ptr<QgsProcessingFeatureBasedAlgorithm> &alg, QgsFeature feature, const QString &layerType, QVariantMap parameters = QVariantMap() );
46
46
47
47
private slots:
48
48
void initTestCase ();// will be called before the first testfunction is executed.
@@ -58,9 +58,13 @@ class TestQgsProcessingAlgs: public QObject
58
58
void kmeansCluster ();
59
59
void categorizeByStyle ();
60
60
void extractBinary ();
61
+
61
62
void polygonsToLines_data ();
62
63
void polygonsToLines ();
63
64
65
+ void densifyGeometries_data ();
66
+ void densifyGeometries ();
67
+
64
68
private:
65
69
66
70
QString mPointLayerPath ;
@@ -74,17 +78,16 @@ std::unique_ptr<QgsProcessingFeatureBasedAlgorithm> TestQgsProcessingAlgs::featu
74
78
return std::unique_ptr<QgsProcessingFeatureBasedAlgorithm>( static_cast <QgsProcessingFeatureBasedAlgorithm *>( QgsApplication::processingRegistry ()->createAlgorithmById ( id ) ) );
75
79
}
76
80
77
- QgsFeature TestQgsProcessingAlgs::runForFeature ( const std::unique_ptr< QgsProcessingFeatureBasedAlgorithm > &alg, QgsFeature feature, const QString &layerType )
81
+ QgsFeature TestQgsProcessingAlgs::runForFeature ( const std::unique_ptr< QgsProcessingFeatureBasedAlgorithm > &alg, QgsFeature feature, const QString &layerType, QVariantMap parameters )
78
82
{
83
+ Q_ASSERT ( alg.get () );
79
84
std::unique_ptr< QgsProcessingContext > context = qgis::make_unique< QgsProcessingContext >();
80
85
QgsProject p;
81
86
context->setProject ( &p );
82
87
83
88
QgsProcessingFeedback feedback;
84
89
context->setFeedback ( &feedback );
85
90
86
- QVariantMap parameters;
87
-
88
91
std::unique_ptr<QgsVectorLayer> inputLayer ( qgis::make_unique<QgsVectorLayer>( layerType, QStringLiteral ( " layer" ), QStringLiteral ( " memory" ) ) );
89
92
inputLayer->dataProvider ()->addFeature ( feature );
90
93
@@ -753,5 +756,90 @@ void TestQgsProcessingAlgs::polygonsToLines()
753
756
QVERIFY2 ( result.geometry ().equals ( expectedGeometry ), QStringLiteral ( " Result: %1, Expected: %2" ).arg ( result.geometry ().asWkt (), expectedGeometry.asWkt () ).toUtf8 ().constData () );
754
757
}
755
758
759
+ void TestQgsProcessingAlgs::densifyGeometries_data ()
760
+ {
761
+ QTest::addColumn<QgsGeometry>( " sourceGeometry" );
762
+ QTest::addColumn<QgsGeometry>( " expectedGeometry" );
763
+ QTest::addColumn<double >( " interval" );
764
+ QTest::addColumn<QString>( " geometryType" );
765
+
766
+ QTest::newRow ( " Null geometry" )
767
+ << QgsGeometry ()
768
+ << QgsGeometry ()
769
+ << 0.1
770
+ << " Point" ;
771
+
772
+ QTest::newRow ( " PointZ" )
773
+ << QgsGeometry::fromWkt ( " PointZ( 1 2 3 )" )
774
+ << QgsGeometry::fromWkt ( " PointZ( 1 2 3 )" )
775
+ << 0.1
776
+ << " Point" ;
777
+
778
+ QTest::newRow ( " MultiPoint" )
779
+ << QgsGeometry::fromWkt ( " MULTIPOINT ((155 271), (150 360), (260 360), (271 265), (280 260), (270 370), (154 354), (150 260))" )
780
+ << QgsGeometry::fromWkt ( " MULTIPOINT ((155 271), (150 360), (260 360), (271 265), (280 260), (270 370), (154 354), (150 260))" )
781
+ << 0.1
782
+ << " Point" ;
783
+
784
+ QTest::newRow ( " LineString big distance" )
785
+ << QgsGeometry::fromWkt ( " LineString( 0 0, 10 0, 10 10 )" )
786
+ << QgsGeometry::fromWkt ( " LineString( 0 0, 10 0, 10 10 )" )
787
+ << 100 .
788
+ << " LineString" ;
789
+
790
+ QTest::newRow ( " LineString small distance" )
791
+ << QgsGeometry::fromWkt ( " LineString( 0 0, 10 0, 10 10 )" )
792
+ << QgsGeometry::fromWkt ( " LineString (0 0, 2.5 0, 5 0, 7.5 0, 10 0, 10 2.5, 10 5, 10 7.5, 10 10)" )
793
+ << 3 .
794
+ << " LineString" ;
795
+
796
+ QTest::newRow ( " LineStringZ" )
797
+ << QgsGeometry::fromWkt ( " LineStringZ( 0 0 1, 10 0 2, 10 10 0)" )
798
+ << QgsGeometry::fromWkt ( " LineStringZ (0 0 1, 5 0 1.5, 10 0 2, 10 5 1, 10 10 0)" )
799
+ << 6 .
800
+ << " LineString" ;
801
+
802
+ QTest::newRow ( " LineStringM" )
803
+ << QgsGeometry::fromWkt ( " LineStringM( 0 0 0, 10 0 2, 10 10 0)" )
804
+ << QgsGeometry::fromWkt ( " LineStringM (0 0 0, 2.5 0 0.5, 5 0 1, 7.5 0 1.5, 10 0 2, 10 2.5 1.5, 10 5 1, 10 7.5 0.5, 10 10 0)" )
805
+ << 3 .
806
+ << " LineString" ;
807
+
808
+ QTest::newRow ( " LineStringZM" )
809
+ << QgsGeometry::fromWkt ( " LineStringZM( 0 0 1 10, 10 0 2 8, 10 10 0 4)" )
810
+ << QgsGeometry::fromWkt ( " LineStringZM (0 0 1 10, 5 0 1.5 9, 10 0 2 8, 10 5 1 6, 10 10 0 4)" )
811
+ << 6 .
812
+ << " LineString" ;
813
+
814
+ QTest::newRow ( " Polygon" )
815
+ << QgsGeometry::fromWkt ( " Polygon(( 0 0, 20 0, 20 20, 0 0 ))" )
816
+ << QgsGeometry::fromWkt ( " Polygon ((0 0, 5 0, 10 0, 15 0, 20 0, 20 5, 20 10, 20 15, 20 20, 16 16, 12 12, 7.99999999999999822 7.99999999999999822, 4 4, 0 0))" )
817
+ << 6 .
818
+ << " Polygon" ;
819
+ }
820
+
821
+ void TestQgsProcessingAlgs::densifyGeometries ()
822
+ {
823
+ QFETCH ( QgsGeometry, sourceGeometry );
824
+ QFETCH ( QgsGeometry, expectedGeometry );
825
+ QFETCH ( double , interval );
826
+ QFETCH ( QString, geometryType );
827
+
828
+ std::unique_ptr< QgsProcessingFeatureBasedAlgorithm > alg ( featureBasedAlg ( " native:densifygeometriesgivenaninterval" ) );
829
+
830
+ QVariantMap parameters;
831
+ parameters.insert ( QStringLiteral ( " INTERVAL" ), interval );
832
+
833
+ QgsFeature feature;
834
+ feature.setGeometry ( sourceGeometry );
835
+
836
+ QgsFeature result = runForFeature ( alg, feature, geometryType, parameters );
837
+
838
+ if ( expectedGeometry.isNull () )
839
+ QVERIFY ( result.geometry ().isNull () );
840
+ else
841
+ QVERIFY2 ( result.geometry ().equals ( expectedGeometry ), QStringLiteral ( " Result: %1, Expected: %2" ).arg ( result.geometry ().asWkt (), expectedGeometry.asWkt () ).toUtf8 ().constData () );
842
+ }
843
+
756
844
QGSTEST_MAIN ( TestQgsProcessingAlgs )
757
845
#include " testqgsprocessingalgs.moc"
0 commit comments