|
20 | 20 | #include "qgstest.h"
|
21 | 21 | #include "qgsvectorlayer.h"
|
22 | 22 |
|
| 23 | +class DummyFeedback : public QgsProcessingFeedback |
| 24 | +{ |
| 25 | + Q_OBJECT |
| 26 | + |
| 27 | + public: |
| 28 | + void reportError( const QString &error, bool fatalError = false ) |
| 29 | + { |
| 30 | + Q_UNUSED( fatalError ); |
| 31 | + mErrors.append( error ); |
| 32 | + }; |
| 33 | + |
| 34 | + QStringList errors() { return mErrors; }; |
| 35 | + void clear() { mErrors.clear(); }; |
| 36 | + |
| 37 | + private: |
| 38 | + QStringList mErrors; |
| 39 | +}; |
| 40 | + |
23 | 41 | class TestQgsProcessingCheckGeometry : public QgsTest
|
24 | 42 | {
|
25 | 43 | Q_OBJECT
|
@@ -79,6 +97,8 @@ class TestQgsProcessingCheckGeometry : public QgsTest
|
79 | 97 | void holeAlg();
|
80 | 98 | void missingVertexAlg();
|
81 | 99 |
|
| 100 | + void duplicatedId(); |
| 101 | + |
82 | 102 | private:
|
83 | 103 | QgsVectorLayer *mLineLayer = nullptr;
|
84 | 104 | QgsVectorLayer *mPolygonLayer = nullptr;
|
@@ -857,5 +877,324 @@ void TestQgsProcessingCheckGeometry::multipartAlg()
|
857 | 877 | QCOMPARE( errorsLayer->featureCount(), expectedErrorCount );
|
858 | 878 | }
|
859 | 879 |
|
| 880 | +void TestQgsProcessingCheckGeometry::duplicatedId() |
| 881 | +{ |
| 882 | + auto polygonLayer = std::make_unique<QgsVectorLayer>( QStringLiteral( "Polygon?crs=epsg:4326&field=pk:int&field=fid:string" ), QStringLiteral( "poly" ), QStringLiteral( "memory" ) ); |
| 883 | + QVERIFY( polygonLayer->isValid() ); |
| 884 | + |
| 885 | + QgsFeature f; |
| 886 | + f.setAttributes( QgsAttributes() << 1 << QLatin1String( "1" ) ); |
| 887 | + f.setGeometry( QgsGeometry::fromWkt( QStringLiteral( "Polygon (0 0, 0 1, 1 1, 1 0, 0 0)" ) ) ); |
| 888 | + polygonLayer->dataProvider()->addFeature( f ); |
| 889 | + f.setAttributes( QgsAttributes() << 2 << QLatin1String( "2" ) ); |
| 890 | + f.setGeometry( QgsGeometry::fromWkt( QStringLiteral( "Polygon (0 0, 0 1, 1 1, 1 0, 0 0)" ) ) ); |
| 891 | + polygonLayer->dataProvider()->addFeature( f ); |
| 892 | + f.setAttributes( QgsAttributes() << 3 << QLatin1String( "1" ) ); |
| 893 | + f.setGeometry( QgsGeometry::fromWkt( QStringLiteral( "Polygon (0 0, 0 1, 1 1, 1 0, 0 0)" ) ) ); |
| 894 | + polygonLayer->dataProvider()->addFeature( f ); |
| 895 | + QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << polygonLayer.get() ); |
| 896 | + |
| 897 | + auto lineLayer = std::make_unique<QgsVectorLayer>( QStringLiteral( "LineString?crs=epsg:4326&field=pk:int&field=fid:string" ), QStringLiteral( "line" ), QStringLiteral( "memory" ) ); |
| 898 | + QVERIFY( lineLayer->isValid() ); |
| 899 | + |
| 900 | + f.setAttributes( QgsAttributes() << 1 << QLatin1String( "1" ) ); |
| 901 | + f.setGeometry( QgsGeometry::fromWkt( QStringLiteral( "LineString (0 0, 10 15)" ) ) ); |
| 902 | + lineLayer->dataProvider()->addFeature( f ); |
| 903 | + f.setAttributes( QgsAttributes() << 2 << QLatin1String( "2" ) ); |
| 904 | + f.setGeometry( QgsGeometry::fromWkt( QStringLiteral( "LineString (4 2, 0 20)" ) ) ); |
| 905 | + lineLayer->dataProvider()->addFeature( f ); |
| 906 | + f.setAttributes( QgsAttributes() << 3 << QLatin1String( "1" ) ); |
| 907 | + f.setGeometry( QgsGeometry::fromWkt( QStringLiteral( "LineString (1 1, 5 3)" ) ) ); |
| 908 | + lineLayer->dataProvider()->addFeature( f ); |
| 909 | + QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << lineLayer.get() ); |
| 910 | + |
| 911 | + auto pointLayer = std::make_unique<QgsVectorLayer>( QStringLiteral( "Point?crs=epsg:4326&field=pk:int&field=fid:string" ), QStringLiteral( "point" ), QStringLiteral( "memory" ) ); |
| 912 | + QVERIFY( pointLayer->isValid() ); |
| 913 | + |
| 914 | + f.setAttributes( QgsAttributes() << 1 << QLatin1String( "1" ) ); |
| 915 | + f.setGeometry( QgsGeometry::fromWkt( QStringLiteral( "Point (1 1)" ) ) ); |
| 916 | + pointLayer->dataProvider()->addFeature( f ); |
| 917 | + f.setAttributes( QgsAttributes() << 2 << QLatin1String( "2" ) ); |
| 918 | + f.setGeometry( QgsGeometry::fromWkt( QStringLiteral( "Point (0.5 0.5)" ) ) ); |
| 919 | + pointLayer->dataProvider()->addFeature( f ); |
| 920 | + f.setAttributes( QgsAttributes() << 3 << QLatin1String( "1" ) ); |
| 921 | + f.setGeometry( QgsGeometry::fromWkt( QStringLiteral( "Point (1 1)" ) ) ); |
| 922 | + pointLayer->dataProvider()->addFeature( f ); |
| 923 | + QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << pointLayer.get() ); |
| 924 | + |
| 925 | + std::unique_ptr<QgsProcessingAlgorithm> alg( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometryangle" ) ) ); |
| 926 | + QVERIFY( alg != nullptr ); |
| 927 | + QVariantMap parameters; |
| 928 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( polygonLayer->id() ) ); |
| 929 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), QStringLiteral( "fid" ) ); |
| 930 | + parameters.insert( QStringLiteral( "MIN_ANGLE" ), 15 ); |
| 931 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 932 | + bool ok = false; |
| 933 | + DummyFeedback feedback; |
| 934 | + const std::unique_ptr<QgsProcessingContext> context = std::make_unique<QgsProcessingContext>(); |
| 935 | + context->setProject( QgsProject::instance() ); |
| 936 | + QVariantMap results; |
| 937 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 938 | + QVERIFY( !ok ); |
| 939 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 940 | + feedback.clear(); |
| 941 | + |
| 942 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometryarea" ) ) ); |
| 943 | + QVERIFY( alg != nullptr ); |
| 944 | + parameters.clear(); |
| 945 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( polygonLayer->id() ) ); |
| 946 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "fid" ); |
| 947 | + parameters.insert( QStringLiteral( "AREATHRESHOLD" ), 0.04 ); |
| 948 | + parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 949 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 950 | + ok = false; |
| 951 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 952 | + QVERIFY( !ok ); |
| 953 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 954 | + feedback.clear(); |
| 955 | + |
| 956 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometryhole" ) ) ); |
| 957 | + QVERIFY( alg != nullptr ); |
| 958 | + parameters.clear(); |
| 959 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( polygonLayer->id() ) ); |
| 960 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "fid" ); |
| 961 | + parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 962 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 963 | + ok = false; |
| 964 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 965 | + QVERIFY( !ok ); |
| 966 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 967 | + feedback.clear(); |
| 968 | + |
| 969 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometrymissingvertex" ) ) ); |
| 970 | + QVERIFY( alg != nullptr ); |
| 971 | + parameters.clear(); |
| 972 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( polygonLayer->id() ) ); |
| 973 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "fid" ); |
| 974 | + parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 975 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 976 | + ok = false; |
| 977 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 978 | + QVERIFY( !ok ); |
| 979 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 980 | + feedback.clear(); |
| 981 | + |
| 982 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometrycontained" ) ) ); |
| 983 | + QVERIFY( alg != nullptr ); |
| 984 | + parameters.clear(); |
| 985 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( polygonLayer->id() ) ); |
| 986 | + parameters.insert( QStringLiteral( "POLYGONS" ), QList<QVariant>() << QVariant::fromValue( polygonLayer->id() ) ); |
| 987 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), QStringLiteral( "fid" ) ); |
| 988 | + parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 989 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 990 | + ok = false; |
| 991 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 992 | + QVERIFY( !ok ); |
| 993 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 994 | + feedback.clear(); |
| 995 | + |
| 996 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometrydegeneratepolygon" ) ) ); |
| 997 | + QVERIFY( alg != nullptr ); |
| 998 | + parameters.clear(); |
| 999 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( polygonLayer->id() ) ); |
| 1000 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "fid" ); |
| 1001 | + parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1002 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1003 | + ok = false; |
| 1004 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 1005 | + QVERIFY( !ok ); |
| 1006 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 1007 | + feedback.clear(); |
| 1008 | + |
| 1009 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometrysegmentlength" ) ) ); |
| 1010 | + QVERIFY( alg != nullptr ); |
| 1011 | + parameters.clear(); |
| 1012 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( polygonLayer->id() ) ); |
| 1013 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "fid" ); |
| 1014 | + parameters.insert( QStringLiteral( "MIN_SEGMENT_LENGTH" ), 0.03 ); |
| 1015 | + parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1016 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1017 | + ok = false; |
| 1018 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 1019 | + QVERIFY( !ok ); |
| 1020 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 1021 | + feedback.clear(); |
| 1022 | + |
| 1023 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometryselfintersection" ) ) ); |
| 1024 | + QVERIFY( alg != nullptr ); |
| 1025 | + parameters.clear(); |
| 1026 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( polygonLayer->id() ) ); |
| 1027 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "fid" ); |
| 1028 | + parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1029 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1030 | + ok = false; |
| 1031 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 1032 | + QVERIFY( !ok ); |
| 1033 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 1034 | + feedback.clear(); |
| 1035 | + |
| 1036 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometrydangle" ) ) ); |
| 1037 | + QVERIFY( alg != nullptr ); |
| 1038 | + parameters.clear(); |
| 1039 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( lineLayer->id() ) ); |
| 1040 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "fid" ); |
| 1041 | + parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1042 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1043 | + ok = false; |
| 1044 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 1045 | + QVERIFY( !ok ); |
| 1046 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 1047 | + feedback.clear(); |
| 1048 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometryduplicatenodes" ) ) ); |
| 1049 | + QVERIFY( alg != nullptr ); |
| 1050 | + parameters.clear(); |
| 1051 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( polygonLayer->id() ) ); |
| 1052 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "fid" ); |
| 1053 | + parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1054 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1055 | + ok = false; |
| 1056 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 1057 | + QVERIFY( !ok ); |
| 1058 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 1059 | + feedback.clear(); |
| 1060 | + |
| 1061 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometryfollowboundaries" ) ) ); |
| 1062 | + QVERIFY( alg != nullptr ); |
| 1063 | + parameters.clear(); |
| 1064 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( polygonLayer->id() ) ); |
| 1065 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "fid" ); |
| 1066 | + parameters.insert( QStringLiteral( "REF_LAYER" ), QVariant::fromValue( polygonLayer->id() ) ); |
| 1067 | + parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1068 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1069 | + ok = false; |
| 1070 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 1071 | + QVERIFY( !ok ); |
| 1072 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 1073 | + feedback.clear(); |
| 1074 | + |
| 1075 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometryoverlap" ) ) ); |
| 1076 | + QVERIFY( alg != nullptr ); |
| 1077 | + parameters.clear(); |
| 1078 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( polygonLayer->id() ) ); |
| 1079 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "fid" ); |
| 1080 | + parameters.insert( QStringLiteral( "MIN_OVERLAP_AREA" ), 0.01 ); |
| 1081 | + parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1082 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1083 | + ok = false; |
| 1084 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 1085 | + QVERIFY( !ok ); |
| 1086 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 1087 | + feedback.clear(); |
| 1088 | + |
| 1089 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometryselfcontact" ) ) ); |
| 1090 | + QVERIFY( alg != nullptr ); |
| 1091 | + parameters.clear(); |
| 1092 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( polygonLayer->id() ) ); |
| 1093 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "fid" ); |
| 1094 | + parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1095 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1096 | + ok = false; |
| 1097 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 1098 | + QVERIFY( !ok ); |
| 1099 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 1100 | + feedback.clear(); |
| 1101 | + |
| 1102 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometrysliverpolygon" ) ) ); |
| 1103 | + QVERIFY( alg != nullptr ); |
| 1104 | + parameters.clear(); |
| 1105 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( polygonLayer->id() ) ); |
| 1106 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "fid" ); |
| 1107 | + parameters.insert( QStringLiteral( "MAX_AREA" ), 0.04 ); |
| 1108 | + parameters.insert( QStringLiteral( "THRESHOLD" ), 20 ); |
| 1109 | + parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1110 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1111 | + ok = false; |
| 1112 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 1113 | + QVERIFY( !ok ); |
| 1114 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 1115 | + feedback.clear(); |
| 1116 | + |
| 1117 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometrygap" ) ) ); |
| 1118 | + QVERIFY( alg != nullptr ); |
| 1119 | + parameters.clear(); |
| 1120 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( polygonLayer->id() ) ); |
| 1121 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "fid" ); |
| 1122 | + parameters.insert( QStringLiteral( "GAP_THRESHOLD" ), 0.01 ); |
| 1123 | + parameters.insert( QStringLiteral( "NEIGHBORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1124 | + parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1125 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1126 | + ok = false; |
| 1127 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 1128 | + QVERIFY( !ok ); |
| 1129 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 1130 | + feedback.clear(); |
| 1131 | + |
| 1132 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometrypointinpolygon" ) ) ); |
| 1133 | + QVERIFY( alg != nullptr ); |
| 1134 | + parameters.clear(); |
| 1135 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( pointLayer->id() ) ); |
| 1136 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "fid" ); |
| 1137 | + parameters.insert( QStringLiteral( "POLYGONS" ), QVariantList() << QVariant::fromValue( polygonLayer->id() ) ); |
| 1138 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1139 | + ok = false; |
| 1140 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 1141 | + QVERIFY( !ok ); |
| 1142 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 1143 | + feedback.clear(); |
| 1144 | + |
| 1145 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometrypointcoveredbyline" ) ) ); |
| 1146 | + QVERIFY( alg != nullptr ); |
| 1147 | + parameters.clear(); |
| 1148 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( pointLayer->id() ) ); |
| 1149 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "fid" ); |
| 1150 | + parameters.insert( QStringLiteral( "LINES" ), QVariantList() << QVariant::fromValue( lineLayer->id() ) ); |
| 1151 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1152 | + ok = false; |
| 1153 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 1154 | + QVERIFY( !ok ); |
| 1155 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 1156 | + feedback.clear(); |
| 1157 | + |
| 1158 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometrylinelayerintersection" ) ) ); |
| 1159 | + QVERIFY( alg != nullptr ); |
| 1160 | + parameters.clear(); |
| 1161 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( lineLayer->id() ) ); |
| 1162 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "fid" ); |
| 1163 | + parameters.insert( QStringLiteral( "CHECK_LAYER" ), QVariant::fromValue( polygonLayer->id() ) ); |
| 1164 | + parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1165 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1166 | + ok = false; |
| 1167 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 1168 | + QVERIFY( !ok ); |
| 1169 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 1170 | + feedback.clear(); |
| 1171 | + |
| 1172 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometrylineintersection" ) ) ); |
| 1173 | + QVERIFY( alg != nullptr ); |
| 1174 | + parameters.clear(); |
| 1175 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( lineLayer->id() ) ); |
| 1176 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "fid" ); |
| 1177 | + parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1178 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1179 | + ok = false; |
| 1180 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 1181 | + QVERIFY( !ok ); |
| 1182 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 1183 | + feedback.clear(); |
| 1184 | + |
| 1185 | + alg.reset( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometrymultipart" ) ) ); |
| 1186 | + QVERIFY( alg != nullptr ); |
| 1187 | + parameters.clear(); |
| 1188 | + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( polygonLayer->id() ) ); |
| 1189 | + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "fid" ); |
| 1190 | + parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1191 | + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); |
| 1192 | + ok = false; |
| 1193 | + results = alg->run( parameters, *context, &feedback, &ok ); |
| 1194 | + QVERIFY( !ok ); |
| 1195 | + QVERIFY( feedback.errors().contains( QStringLiteral( "Field 'fid' contains non-unique values and can not be used as unique ID." ) ) ); |
| 1196 | + feedback.clear(); |
| 1197 | +} |
| 1198 | + |
860 | 1199 | QGSTEST_MAIN( TestQgsProcessingCheckGeometry )
|
861 | 1200 | #include "testqgsprocessingcheckgeometry.moc"
|
0 commit comments