Skip to content
Permalink
Browse files

geometry overlay functions test suite

  • Loading branch information
enricofer authored and m-kuhn committed Jul 3, 2020
1 parent a03e600 commit ba1b34d4390d1e0b36766586a83308d8643c53da
Showing with 27 additions and 3 deletions.
  1. +27 −3 tests/src/core/testqgsoverlayexpression.cpp
@@ -46,6 +46,7 @@ class TestQgsOverlayExpression: public QObject

private:
QgsVectorLayer *mRectanglesLayer = nullptr;
QgsVectorLayer *mPolyLayer = nullptr;

private slots:

@@ -73,7 +74,12 @@ void TestQgsOverlayExpression::initTestCase()
QFileInfo rectanglesFileInfo( rectanglesFileName );
mRectanglesLayer = new QgsVectorLayer( rectanglesFileInfo.filePath(),
QStringLiteral( "rectangles" ), QStringLiteral( "ogr" ) );
QString polygonsFileName = testDataDir + QStringLiteral( "polys_overlapping_with_id.shp" );
QFileInfo polygonsFileInfo( polygonsFileName );
mPolyLayer = new QgsVectorLayer( polygonsFileInfo.filePath(),
QStringLiteral( "polys" ), QStringLiteral( "ogr" ) );
QgsProject::instance()->addMapLayer( mRectanglesLayer );
QgsProject::instance()->addMapLayer( mPolyLayer );
}

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

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


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

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)))" ) };
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)))" ) };
QTest::newRow( "intersects get ids" ) << "geometry_overlay_intersects('rectangles', $id)" << "LINESTRING(-178 52, -133 33, -64 46)" << QVariantList { 1, 2, 3 };
QTest::newRow( "intersects filtered get ids" ) << "geometry_overlay_intersects('rectangles', $id, $id != 2)" << "LINESTRING(-178 52, -133 33, -64 46)" << QVariantList { 1, 3 };
QTest::newRow( "touches get ids" ) << "geometry_overlay_touches('rectangles',$id)" << "POLYGON((-86 54, -95 50, -81 50, -86 54))" << QVariantList { 3 };
QTest::newRow( "equals get ids" ) << "geometry_overlay_equals('rectangles',$id)" << "MULTIPOLYGON(((-160 50, -145 50, -145 35, -160 35, -160 50)))" << QVariantList { 1 };
QTest::newRow( "disjoint get ids" ) << "geometry_overlay_disjoint('rectangles',$id)" << "LINESTRING(-155 15, -122 55, -84 4)" << QVariantList { 1, 2, 3 };
QTest::newRow( "nearest" ) << "geometry_overlay_nearest('rectangles',$id)" << "POINT(-135 38)" << QVariantList { 2 };
QTest::newRow( "nearest filtered" ) << "geometry_overlay_nearest('rectangles',$id,$id != 2)" << "POINT(-135 38)" << QVariantList { 1 };
}
QGSTEST_MAIN( TestQgsOverlayExpression )

0 comments on commit ba1b34d

Please sign in to comment.