Skip to content

Commit ba1b34d

Browse files
enricoferm-kuhn
authored andcommitted
geometry overlay functions test suite
1 parent a03e600 commit ba1b34d

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

tests/src/core/testqgsoverlayexpression.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class TestQgsOverlayExpression: public QObject
4646

4747
private:
4848
QgsVectorLayer *mRectanglesLayer = nullptr;
49+
QgsVectorLayer *mPolyLayer = nullptr;
4950

5051
private slots:
5152

@@ -73,7 +74,12 @@ void TestQgsOverlayExpression::initTestCase()
7374
QFileInfo rectanglesFileInfo( rectanglesFileName );
7475
mRectanglesLayer = new QgsVectorLayer( rectanglesFileInfo.filePath(),
7576
QStringLiteral( "rectangles" ), QStringLiteral( "ogr" ) );
77+
QString polygonsFileName = testDataDir + QStringLiteral( "polys_overlapping_with_id.shp" );
78+
QFileInfo polygonsFileInfo( polygonsFileName );
79+
mPolyLayer = new QgsVectorLayer( polygonsFileInfo.filePath(),
80+
QStringLiteral( "polys" ), QStringLiteral( "ogr" ) );
7681
QgsProject::instance()->addMapLayer( mRectanglesLayer );
82+
QgsProject::instance()->addMapLayer( mPolyLayer );
7783
}
7884

7985
void TestQgsOverlayExpression::cleanupTestCase()
@@ -108,8 +114,19 @@ void TestQgsOverlayExpression::testOverlay_data()
108114
QTest::addColumn<QString>( "geometry" );
109115
QTest::addColumn<bool>( "expectedResult" );
110116

111-
QTest::newRow( "intersect" ) << "test_geometry_overlay_intersects('rectangles')" << "POLYGON((-120 30, -105 30, -105 20, -120 20, -120 30))" << true;
112-
QTest::newRow( "intersect no match" ) << "test_geometry_overlay_intersects('rectangles')" << "POLYGON((10 0, 5 0, 5 5, 10 5, 10 0))" << false;
117+
QTest::newRow( "intersects" ) << "geometry_overlay_intersects('rectangles')" << "POLYGON((-120 30, -105 30, -105 20, -120 20, -120 30))" << true;
118+
QTest::newRow( "intersects no match" ) << "geometry_overlay_intersects('rectangles')" << "POLYGON((10 0, 5 0, 5 5, 10 5, 10 0))" << false;
119+
QTest::newRow( "touches" ) << "geometry_overlay_touches('rectangles')" << "POLYGON((-86 54, -95 50, -81 50, -86 54))" << true;
120+
QTest::newRow( "touches no intersects no match" ) << "geometry_overlay_touches('rectangles')" << "POLYGON((-86 54, -95 51, -81 51, -86 54))" << false;
121+
QTest::newRow( "touches intersects no match" ) << "geometry_overlay_touches('rectangles')" << "POLYGON((-86 54, -95 49, -81 49, -86 54))" << false;
122+
QTest::newRow( "within" ) << "geometry_overlay_within('rectangles')" << "POLYGON((-166 15, -166 58, -107 58, -107 15, -166 15))" << true;
123+
QTest::newRow( "within no match" ) << "geometry_overlay_within('rectangles')" << "POLYGON((-156 46, -149 46, -148 37, -156 46))" << false;
124+
QTest::newRow( "contains" ) << "geometry_overlay_contains('rectangles')" << "POINT(-83 47)" << true;
125+
QTest::newRow( "contains no match" ) << "geometry_overlay_contains('rectangles')" << "POINT(-122 43)" << false;
126+
QTest::newRow( "equals" ) << "geometry_overlay_equals('rectangles')" << "MULTIPOLYGON(((-160 50, -145 50, -145 35, -160 35, -160 50)))" << true;
127+
QTest::newRow( "equals no match" ) << "geometry_overlay_equals('rectangles')" << "POLYGON((-156 46, -149 46, -148 37, -156 46))" << false;
128+
QTest::newRow( "disjoint" ) << "geometry_overlay_disjoint('rectangles')" << "LINESTRING(-155 15, -122 55, -84 4)" << true;
129+
QTest::newRow( "disjoint no match" ) << "geometry_overlay_disjoint('rectangles')" << "LINESTRING(-155 15, -122 32, -84 4)" << false;
113130
}
114131

115132

@@ -145,7 +162,14 @@ void TestQgsOverlayExpression::testOverlayExpression_data()
145162
QTest::addColumn<QString>( "geometry" );
146163
QTest::addColumn<QVariantList>( "expectedResult" );
147164

148-
QTest::newRow( "intersect" ) << "geometry_overlay_intersects('rectangles', $geometry)" << "POLYGON((-120 30, -105 30, -105 20, -120 20, -120 30))" << QVariantList { QgsGeometry::fromWkt( "MultiPolygon (((-130 40, -115 40, -115 25, -130 25, -130 40)))" ) };
165+
QTest::newRow( "intersects get geometry" ) << "geometry_overlay_intersects('rectangles', $geometry)" << "POLYGON((-120 30, -105 30, -105 20, -120 20, -120 30))" << QVariantList { QgsGeometry::fromWkt( "MultiPolygon (((-130 40, -115 40, -115 25, -130 25, -130 40)))" ) };
166+
QTest::newRow( "intersects get ids" ) << "geometry_overlay_intersects('rectangles', $id)" << "LINESTRING(-178 52, -133 33, -64 46)" << QVariantList { 1, 2, 3 };
167+
QTest::newRow( "intersects filtered get ids" ) << "geometry_overlay_intersects('rectangles', $id, $id != 2)" << "LINESTRING(-178 52, -133 33, -64 46)" << QVariantList { 1, 3 };
168+
QTest::newRow( "touches get ids" ) << "geometry_overlay_touches('rectangles',$id)" << "POLYGON((-86 54, -95 50, -81 50, -86 54))" << QVariantList { 3 };
169+
QTest::newRow( "equals get ids" ) << "geometry_overlay_equals('rectangles',$id)" << "MULTIPOLYGON(((-160 50, -145 50, -145 35, -160 35, -160 50)))" << QVariantList { 1 };
170+
QTest::newRow( "disjoint get ids" ) << "geometry_overlay_disjoint('rectangles',$id)" << "LINESTRING(-155 15, -122 55, -84 4)" << QVariantList { 1, 2, 3 };
171+
QTest::newRow( "nearest" ) << "geometry_overlay_nearest('rectangles',$id)" << "POINT(-135 38)" << QVariantList { 2 };
172+
QTest::newRow( "nearest filtered" ) << "geometry_overlay_nearest('rectangles',$id,$id != 2)" << "POINT(-135 38)" << QVariantList { 1 };
149173
}
150174
QGSTEST_MAIN( TestQgsOverlayExpression )
151175

0 commit comments

Comments
 (0)