@@ -421,6 +421,66 @@ class TestQgsExpression: public QObject
421
421
422
422
// geometry functions
423
423
QTest::newRow ( " num_points" ) << " num_points(geom_from_wkt('GEOMETRYCOLLECTION(LINESTRING(0 0, 1 0),POINT(6 5))'))" << false << QVariant ( 3 );
424
+ QTest::newRow ( " num_interior_rings not geom" ) << " num_interior_rings('g')" << true << QVariant ();
425
+ QTest::newRow ( " num_interior_rings null" ) << " num_interior_rings(NULL)" << false << QVariant ();
426
+ QTest::newRow ( " num_interior_rings point" ) << " num_interior_rings(geom_from_wkt('POINT(1 2)'))" << false << QVariant ();
427
+ QTest::newRow ( " num_interior_rings polygon" ) << " num_interior_rings(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1))'))" << false << QVariant ( 0 );
428
+ QTest::newRow ( " num_interior_rings polygon with rings" ) << " num_interior_rings(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1),(-0.1 -0.1, 0.4 0, 0.4 0.2, 0 0.2, -0.1 -0.1),(-1 -1, 4 0, 4 2, 0 2, -1 -1))'))" << false << QVariant ( 2 );
429
+ QTest::newRow ( " num_interior_rings line" ) << " num_interior_rings(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)'))" << false << QVariant ();
430
+ QTest::newRow ( " num_interior_rings collection no polygon" ) << " num_interior_rings(geom_from_wkt('GEOMETRYCOLLECTION(POINT(0 1), POINT(0 0), POINT(1 0), POINT(1 1))'))" << false << QVariant ();
431
+ QTest::newRow ( " num_interior_rings collection with polygon" ) << " num_interior_rings(geom_from_wkt('GEOMETRYCOLLECTION(POINT(0 1), POINT(0 0), POINT(1 1), POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1),(-0.1 -0.1, 0.4 0, 0.4 0.2, 0 0.2, -0.1 -0.1),(-1 -1, 4 0, 4 2, 0 2, -1 -1)), POINT(1 0))'))" << false << QVariant ( 2 );
432
+ QTest::newRow ( " num_rings not geom" ) << " num_rings('g')" << true << QVariant ();
433
+ QTest::newRow ( " num_rings null" ) << " num_rings(NULL)" << false << QVariant ();
434
+ QTest::newRow ( " num_rings point" ) << " num_rings(geom_from_wkt('POINT(1 2)'))" << false << QVariant ();
435
+ QTest::newRow ( " num_rings polygon" ) << " num_rings(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1))'))" << false << QVariant ( 1 );
436
+ QTest::newRow ( " num_rings polygon with rings" ) << " num_rings(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1),(-0.1 -0.1, 0.4 0, 0.4 0.2, 0 0.2, -0.1 -0.1),(-1 -1, 4 0, 4 2, 0 2, -1 -1))'))" << false << QVariant ( 3 );
437
+ QTest::newRow ( " num_rings line" ) << " num_rings(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)'))" << false << QVariant ();
438
+ QTest::newRow ( " num_rings collection no polygon" ) << " num_rings(geom_from_wkt('GEOMETRYCOLLECTION(POINT(0 1), POINT(0 0), POINT(1 0), POINT(1 1))'))" << false << QVariant ();
439
+ QTest::newRow ( " num_rings collection with polygon" ) << " num_rings(geom_from_wkt('GEOMETRYCOLLECTION(POINT(0 1), POINT(0 0), POINT(1 1), POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1),(-0.1 -0.1, 0.4 0, 0.4 0.2, 0 0.2, -0.1 -0.1),(-1 -1, 4 0, 4 2, 0 2, -1 -1)), POINT(1 0))'))" << false << QVariant ( 3 );
440
+ QTest::newRow ( " num_rings collection two polygons" ) << " num_rings(geom_from_wkt('GEOMETRYCOLLECTION(POINT(0 1), POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1)), POINT(0 0), POINT(1 1), POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1),(-0.1 -0.1, 0.4 0, 0.4 0.2, 0 0.2, -0.1 -0.1),(-1 -1, 4 0, 4 2, 0 2, -1 -1)), POINT(1 0))'))" << false << QVariant ( 4 );
441
+ QTest::newRow ( " num_geometries not geom" ) << " num_geometries('g')" << true << QVariant ();
442
+ QTest::newRow ( " num_geometries null" ) << " num_geometries(NULL)" << false << QVariant ();
443
+ QTest::newRow ( " num_geometries point" ) << " num_geometries(geom_from_wkt('POINT(1 2)'))" << false << QVariant ( 1 );
444
+ QTest::newRow ( " num_geometries polygon" ) << " num_geometries(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1))'))" << false << QVariant ( 1 );
445
+ QTest::newRow ( " num_geometries line" ) << " num_geometries(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)'))" << false << QVariant ( 1 );
446
+ QTest::newRow ( " num_geometries collection 1" ) << " num_geometries(geom_from_wkt('GEOMETRYCOLLECTION(POINT(0 1), POINT(0 0), POINT(1 0), POINT(1 1))'))" << false << QVariant ( 4 );
447
+ QTest::newRow ( " num_geometries collection 2" ) << " num_geometries(geom_from_wkt('GEOMETRYCOLLECTION(POINT(0 1), POINT(0 0), POINT(1 1), POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1),(-0.1 -0.1, 0.4 0, 0.4 0.2, 0 0.2, -0.1 -0.1),(-1 -1, 4 0, 4 2, 0 2, -1 -1)), POINT(1 0))'))" << false << QVariant ( 5 );
448
+ QTest::newRow ( " num_geometries empty collection" ) << " num_geometries(geom_from_wkt('GEOMETRYCOLLECTION()'))" << false << QVariant ( 0 );
449
+ QTest::newRow ( " nodes_to_points not geom" ) << " nodes_to_points('g')" << true << QVariant ();
450
+ QTest::newRow ( " nodes_to_points null" ) << " nodes_to_points(NULL)" << false << QVariant ();
451
+ QTest::newRow ( " nodes_to_points point" ) << " geom_to_wkt(nodes_to_points(geom_from_wkt('POINT(1 2)')))" << false << QVariant ( QString ( " MultiPoint ((1 2))" ) );
452
+ QTest::newRow ( " nodes_to_points polygon" ) << " geom_to_wkt(nodes_to_points(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1))')))" << false << QVariant ( QString ( " MultiPoint ((-1 -1),(4 0),(4 2),(0 2),(-1 -1))" ) );
453
+ QTest::newRow ( " nodes_to_points polygon with rings" ) << " geom_to_wkt(nodes_to_points(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1),(-0.1 -0.1, 0.4 0, 0.4 0.2, 0 0.2, -0.1 -0.1),(-0.3 -0.9, -0.3 0, 4 -0.1, 0.1 2.1, -0.3 -0.9))')))" << false
454
+ << QVariant ( QString ( " MultiPoint ((-1 -1),(4 0),(4 2),(0 2),(-1 -1),(-0.1 -0.1),(0.4 0),(0.4 0.2),(0 0.2),(-0.1 -0.1),(-0.3 -0.9),(-0.3 0),(4 -0.1),(0.1 2.1),(-0.3 -0.9))" ) );
455
+ QTest::newRow ( " nodes_to_points line" ) << " geom_to_wkt(nodes_to_points(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)')))" << false
456
+ << QVariant ( QString ( " MultiPoint ((0 0),(1 1),(2 2))" ) );
457
+ QTest::newRow ( " nodes_to_points collection 1" ) << " geom_to_wkt(nodes_to_points(geom_from_wkt('GEOMETRYCOLLECTION(POINT(0 1), POINT(0 0), POINT(1 0), POINT(1 1))')))" << false
458
+ << QVariant ( QString ( " MultiPoint ((0 1),(0 0),(1 0),(1 1))" ) );
459
+ QTest::newRow ( " nodes_to_points collection 2" ) << " geom_to_wkt(nodes_to_points(geom_from_wkt('GEOMETRYCOLLECTION(POINTZM(0 1 2 3), POINTZM(0 0 3 4), POINTZM(1 1 5 6), POLYGONZM((-1 -1 7 8, 4 0 1 2, 4 2 7 6, 0 2 1 3, -1 -1 7 8),(-0.1 -0.1 5 4, 0.4 0 9 8, 0.4 0.2 7 10, 0 0.2 0 0, -0.1 -0.1 5 4),(-1 -1 0 0, 4 0 0 1, 4 2 1 2, 0 2 2 3, -1 -1 0 0)), POINTZM(1 0 1 2))')))" << false
460
+ << QVariant ( QString ( " MultiPointZM ((0 1 2 3),(0 0 3 4),(1 1 5 6),(-1 -1 7 8),(4 0 1 2),(4 2 7 6),(0 2 1 3),(-1 -1 7 8),(-0.1 -0.1 5 4),(0.4 0 9 8),(0.4 0.2 7 10),(0 0.2 0 0),(-0.1 -0.1 5 4),(-1 -1 0 0),(4 0 0 1),(4 2 1 2),(0 2 2 3),(-1 -1 0 0),(1 0 1 2))" ) );
461
+ QTest::newRow ( " nodes_to_points empty collection" ) << " geom_to_wkt(nodes_to_points(geom_from_wkt('GEOMETRYCOLLECTION()')))" << false <<
462
+ QVariant ( QString ( " MultiPoint ()" ) );
463
+ QTest::newRow ( " nodes_to_points no close polygon" ) << " geom_to_wkt(nodes_to_points(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1))'),true))" << false << QVariant ( QString ( " MultiPoint ((-1 -1),(4 0),(4 2),(0 2))" ) );
464
+ QTest::newRow ( " nodes_to_points no close polygon with rings" ) << " geom_to_wkt(nodes_to_points(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1),(-0.1 -0.1, 0.4 0, 0.4 0.2, 0 0.2, -0.1 -0.1),(-0.3 -0.9, -0.3 0, 4 -0.1, 0.1 2.1, -0.3 -0.9))'),true))" << false
465
+ << QVariant ( QString ( " MultiPoint ((-1 -1),(4 0),(4 2),(0 2),(-0.1 -0.1),(0.4 0),(0.4 0.2),(0 0.2),(-0.3 -0.9),(-0.3 0),(4 -0.1),(0.1 2.1))" ) );
466
+ QTest::newRow ( " nodes_to_points no close unclosed line" ) << " geom_to_wkt(nodes_to_points(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)'),true))" << false
467
+ << QVariant ( QString ( " MultiPoint ((0 0),(1 1),(2 2))" ) );
468
+ QTest::newRow ( " nodes_to_points no close closed line" ) << " geom_to_wkt(nodes_to_points(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2, 0 0)'),true))" << false
469
+ << QVariant ( QString ( " MultiPoint ((0 0),(1 1),(2 2))" ) );
470
+ QTest::newRow ( " segments_to_lines not geom" ) << " segments_to_lines('g')" << true << QVariant ();
471
+ QTest::newRow ( " segments_to_lines null" ) << " segments_to_lines(NULL)" << false << QVariant ();
472
+ QTest::newRow ( " segments_to_lines point" ) << " geom_to_wkt(segments_to_lines(geom_from_wkt('POINT(1 2)')))" << false << QVariant ( QString ( " MultiLineString ()" ) );
473
+ QTest::newRow ( " segments_to_lines polygon" ) << " geom_to_wkt(segments_to_lines(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1))')))" << false << QVariant ( QString ( " MultiLineString ((-1 -1, 4 0),(4 0, 4 2),(4 2, 0 2),(0 2, -1 -1))" ) );
474
+ QTest::newRow ( " segments_to_lines polygon with rings" ) << " geom_to_wkt(segments_to_lines(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1),(-0.1 -0.1, 0.4 0, 0.4 0.2, 0 0.2, -0.1 -0.1),(-0.3 -0.9, -0.3 0, 4 -0.1, 0.1 2.1, -0.3 -0.9))')))" << false
475
+ << QVariant ( QString ( " MultiLineString ((-1 -1, 4 0),(4 0, 4 2),(4 2, 0 2),(0 2, -1 -1),(-0.1 -0.1, 0.4 0),(0.4 0, 0.4 0.2),(0.4 0.2, 0 0.2),(0 0.2, -0.1 -0.1),(-0.3 -0.9, -0.3 0),(-0.3 0, 4 -0.1),(4 -0.1, 0.1 2.1),(0.1 2.1, -0.3 -0.9))" ) );
476
+ QTest::newRow ( " segments_to_lines line" ) << " geom_to_wkt(segments_to_lines(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)')))" << false
477
+ << QVariant ( QString ( " MultiLineString ((0 0, 1 1),(1 1, 2 2))" ) );
478
+ QTest::newRow ( " segments_to_lines collection 1" ) << " geom_to_wkt(segments_to_lines(geom_from_wkt('GEOMETRYCOLLECTION(POINT(0 1), POINT(0 0), POINT(1 0), POINT(1 1))')))" << false
479
+ << QVariant ( QString ( " MultiLineString ()" ) );
480
+ QTest::newRow ( " segments_to_lines collection 2" ) << " geom_to_wkt(segments_to_lines(geom_from_wkt('GEOMETRYCOLLECTION(POINTZM(0 1 2 3), LINESTRINGZM(0 0 1 2, 1 1 3 4, 2 2 5 6), POINTZM(1 1 5 6), POLYGONZM((-1 -1 7 8, 4 0 1 2, 4 2 7 6, 0 2 1 3, -1 -1 7 8)), POINTZM(1 0 1 2))')))" << false
481
+ << QVariant ( QString ( " MultiLineStringZM ((0 0 1 2, 1 1 3 4),(1 1 3 4, 2 2 5 6),(-1 -1 7 8, 4 0 1 2),(4 0 1 2, 4 2 7 6),(4 2 7 6, 0 2 1 3),(0 2 1 3, -1 -1 7 8))" ) );
482
+ QTest::newRow ( " segments_to_lines empty collection" ) << " geom_to_wkt(segments_to_lines(geom_from_wkt('GEOMETRYCOLLECTION()')))" << false <<
483
+ QVariant ( QString ( " MultiLineString ()" ) );
424
484
QTest::newRow ( " length line" ) << " length(geom_from_wkt('LINESTRING(0 0, 4 0)'))" << false << QVariant ( 4.0 );
425
485
QTest::newRow ( " length polygon" ) << " length(geom_from_wkt('POLYGON((0 0, 4 0, 4 2, 0 2, 0 0))'))" << false << QVariant ();
426
486
QTest::newRow ( " length point" ) << " length(geom_from_wkt('POINT(0 0)'))" << false << QVariant ();
@@ -436,6 +496,26 @@ class TestQgsExpression: public QObject
436
496
QTest::newRow ( " point_n multipoint" ) << " geom_to_wkt(point_n(geom_from_wkt('MULTIPOINT((0 0), (1 1), (2 2))'),2))" << false << QVariant ( " Point (1 1)" );
437
497
QTest::newRow ( " point_n line" ) << " geom_to_wkt(point_n(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)'),3))" << false << QVariant ( " Point (2 2)" );
438
498
QTest::newRow ( " point_n polygon" ) << " geom_to_wkt(point_n(geom_from_wkt('POLYGON((0 0, 4 0, 4 2, 0 2, 0 0))'),3))" << false << QVariant ( " Point (4 2)" );
499
+ QTest::newRow ( " interior_ring_n not geom" ) << " interior_ring_n('g', 1)" << true << QVariant ();
500
+ QTest::newRow ( " interior_ring_n null" ) << " interior_ring_n(NULL, 1)" << false << QVariant ();
501
+ QTest::newRow ( " interior_ring_n point" ) << " interior_ring_n(geom_from_wkt('POINT(1 2)'), 1)" << false << QVariant ();
502
+ QTest::newRow ( " interior_ring_n polygon no rings" ) << " interior_ring_n(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1))'),1)" << false << QVariant ();
503
+ QTest::newRow ( " interior_ring_n polygon with rings" ) << " geom_to_wkt(interior_ring_n(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1),(-0.1 -0.1, 0.4 0, 0.4 0.2, 0 0.2, -0.1 -0.1),(-1 -1, 4 0, 4 2, 0 2, -1 -1))'),1))" << false
504
+ << QVariant ( QString ( " LineString (-0.1 -0.1, 0.4 0, 0.4 0.2, 0 0.2, -0.1 -0.1)" ) );
505
+ QTest::newRow ( " interior_ring_n polygon with rings bad index 1" ) << " interior_ring_n(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1),(-0.1 -0.1, 0.4 0, 0.4 0.2, 0 0.2, -0.1 -0.1),(-1 -1, 4 0, 4 2, 0 2, -1 -1))'),0)" << false
506
+ << QVariant ();
507
+ QTest::newRow ( " interior_ring_n polygon with rings bad index 2" ) << " interior_ring_n(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1),(-0.1 -0.1, 0.4 0, 0.4 0.2, 0 0.2, -0.1 -0.1),(-1 -1, 4 0, 4 2, 0 2, -1 -1))'),3)" << false
508
+ << QVariant ();
509
+ QTest::newRow ( " interior_ring_n line" ) << " interior_ring_n(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)'), 1)" << false << QVariant ();
510
+ QTest::newRow ( " interior_ring_n collection" ) << " interior_ring_n(geom_from_wkt('GEOMETRYCOLLECTION(POINT(0 1), POINT(0 0), POINT(1 0), POINT(1 1))'),1)" << false << QVariant ();
511
+ QTest::newRow ( " geometry_n not geom" ) << " geometry_n('g', 1)" << true << QVariant ();
512
+ QTest::newRow ( " geometry_n null" ) << " geometry_n(NULL, 1)" << false << QVariant ();
513
+ QTest::newRow ( " geometry_n point" ) << " geometry_n(geom_from_wkt('POINT(1 2)'), 1)" << false << QVariant ();
514
+ QTest::newRow ( " geometry_n polygon" ) << " geometry_n(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1))'),1)" << false << QVariant ();
515
+ QTest::newRow ( " geometry_n line" ) << " geometry_n(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)'), 1)" << false << QVariant ();
516
+ QTest::newRow ( " geometry_n collection" ) << " geom_to_wkt(geometry_n(geom_from_wkt('GEOMETRYCOLLECTION(POINT(0 1), POINT(0 0), POINT(1 0), POINT(1 1))'),3))" << false << QVariant ( QString ( " Point (1 0)" ) );
517
+ QTest::newRow ( " geometry_n collection bad index 1" ) << " geometry_n(geom_from_wkt('GEOMETRYCOLLECTION(POINT(0 1), POINT(0 0), POINT(1 0), POINT(1 1))'),0)" << false << QVariant ();
518
+ QTest::newRow ( " geometry_n collection bad index 2" ) << " geometry_n(geom_from_wkt('GEOMETRYCOLLECTION(POINT(0 1), POINT(0 0), POINT(1 0), POINT(1 1))'),5)" << false << QVariant ();
439
519
QTest::newRow ( " start_point point" ) << " geom_to_wkt(start_point(geom_from_wkt('POINT(2 0)')))" << false << QVariant ( " Point (2 0)" );
440
520
QTest::newRow ( " start_point multipoint" ) << " geom_to_wkt(start_point(geom_from_wkt('MULTIPOINT((3 3), (1 1), (2 2))')))" << false << QVariant ( " Point (3 3)" );
441
521
QTest::newRow ( " start_point line" ) << " geom_to_wkt(start_point(geom_from_wkt('LINESTRING(4 1, 1 1, 2 2)')))" << false << QVariant ( " Point (4 1)" );
0 commit comments