/
testqgsgeometry.cpp
2492 lines (2237 loc) · 104 KB
/
testqgsgeometry.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
testqgsgeometry.cpp
--------------------------------------
Date : 20 Jan 2008
Copyright : (C) 2008 by Tim Sutton
Email : tim @ linfiniti.com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <QtTest/QtTest>
#include <QObject>
#include <QString>
#include <QStringList>
#include <QApplication>
#include <QFileInfo>
#include <QDir>
#include <QDesktopServices>
#include <QVector>
#include <QPointF>
#include <QImage>
#include <QPainter>
//qgis includes...
#include <qgsapplication.h>
#include <qgsgeometry.h>
#include "qgsgeometryutils.h"
#include <qgspoint.h>
#include "qgspointv2.h"
#include "qgslinestringv2.h"
//qgs unit test utility class
#include "qgsrenderchecker.h"
/** \ingroup UnitTests
* This is a unit test for the different geometry operations on vector features.
*/
class TestQgsGeometry : public QObject
{
Q_OBJECT
public:
TestQgsGeometry();
private slots:
void initTestCase();// will be called before the first testfunction is executed.
void cleanupTestCase();// will be called after the last testfunction was executed.
void init();// will be called before each testfunction is executed.
void cleanup();// will be called after every testfunction.
void copy();
void assignment();
void asVariant(); //test conversion to and from a QVariant
void isEmpty();
void pointV2(); //test QgsPointV2
void lineStringV2(); //test QgsLineStringV2
void utils(); //test QgsGeometryUtils
void fromQgsPoint();
void fromQPoint();
void fromQPolygonF();
void asQPointF();
void asQPolygonF();
void comparePolylines();
void comparePolygons();
// MK, Disabled 14.11.2014
// Too unclear what exactly should be tested and which variations are allowed for the line
#if 0
void simplifyCheck1();
#endif
void intersectionCheck1();
void intersectionCheck2();
void translateCheck1();
void rotateCheck1();
void unionCheck1();
void unionCheck2();
void differenceCheck1();
void differenceCheck2();
void bufferCheck();
void smoothCheck();
void dataStream();
void exportToGeoJSON();
private:
/** A helper method to do a render check to see if the geometry op is as expected */
bool renderCheck( const QString& theTestName, const QString& theComment = "", int mismatchCount = 0 );
/** A helper method to dump to qdebug the geometry of a multipolygon */
void dumpMultiPolygon( QgsMultiPolygon &theMultiPolygon );
/** A helper method to dump to qdebug the geometry of a polygon */
void dumpPolygon( QgsPolygon &thePolygon );
/** A helper method to dump to qdebug the geometry of a polyline */
void dumpPolyline( QgsPolyline &thePolyline );
QString elemToString( const QDomElement& elem ) const;
QgsPoint mPoint1;
QgsPoint mPoint2;
QgsPoint mPoint3;
QgsPoint mPoint4;
QgsPoint mPointA;
QgsPoint mPointB;
QgsPoint mPointC;
QgsPoint mPointD;
QgsPoint mPointW;
QgsPoint mPointX;
QgsPoint mPointY;
QgsPoint mPointZ;
QgsPolyline mPolylineA;
QgsPolyline mPolylineB;
QgsPolyline mPolylineC;
QgsGeometry * mpPolylineGeometryD;
QgsPolygon mPolygonA;
QgsPolygon mPolygonB;
QgsPolygon mPolygonC;
QgsGeometry * mpPolygonGeometryA;
QgsGeometry * mpPolygonGeometryB;
QgsGeometry * mpPolygonGeometryC;
QString mWktLine;
QString mTestDataDir;
QImage mImage;
QPainter * mpPainter;
QPen mPen1;
QPen mPen2;
QString mReport;
};
TestQgsGeometry::TestQgsGeometry()
: mpPolylineGeometryD( NULL )
, mpPolygonGeometryA( NULL )
, mpPolygonGeometryB( NULL )
, mpPolygonGeometryC( NULL )
, mpPainter( NULL )
{
}
void TestQgsGeometry::initTestCase()
{
// Runs once before any tests are run
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::init();
QgsApplication::initQgis();
QgsApplication::showSettings();
mReport += "<h1>Geometry Tests</h1>\n";
mReport += "<p><font color=\"green\">Green = polygonA</font></p>\n";
mReport += "<p><font color=\"red\">Red = polygonB</font></p>\n";
mReport += "<p><font color=\"blue\">Blue = polygonC</font></p>\n";
}
void TestQgsGeometry::cleanupTestCase()
{
// Runs once after all tests are run
QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
{
QTextStream myQTextStream( &myFile );
myQTextStream << mReport;
myFile.close();
//QDesktopServices::openUrl( "file:///" + myReportFile );
}
QgsApplication::exitQgis();
}
void TestQgsGeometry::init()
{
//
// Reset / reinitialise the geometries before each test is run
//
mPoint1 = QgsPoint( 20.0, 20.0 );
mPoint2 = QgsPoint( 80.0, 20.0 );
mPoint3 = QgsPoint( 80.0, 80.0 );
mPoint4 = QgsPoint( 20.0, 80.0 );
mPointA = QgsPoint( 40.0, 40.0 );
mPointB = QgsPoint( 100.0, 40.0 );
mPointC = QgsPoint( 100.0, 100.0 );
mPointD = QgsPoint( 40.0, 100.0 );
mPointW = QgsPoint( 200.0, 200.0 );
mPointX = QgsPoint( 240.0, 200.0 );
mPointY = QgsPoint( 240.0, 240.0 );
mPointZ = QgsPoint( 200.0, 240.0 );
mWktLine = QString( "LINESTRING(117.623198 35.198654, 117.581274 35.198654, 117.078178 35.324427, 116.868555 35.534051, 116.617007 35.869448, 116.491233 35.953297, 116.155836 36.288694, 116.071987 36.372544, 115.443117 36.749865, 114.814247 37.043338, 114.311152 37.169112, 113.388810 37.378735, 113.095337 37.378735, 112.592241 37.378735, 111.753748 37.294886, 111.502201 37.252961, 111.082954 37.127187, 110.747557 37.127187, 110.160612 36.917564, 110.034838 36.833715, 109.741366 36.749865, 109.573667 36.666016, 109.238270 36.498317, 109.070571 36.414468, 108.819023 36.288694, 108.693250 36.246770, 108.483626 36.162920, 107.645134 35.911372, 106.597017 35.869448, 106.051997 35.701749, 105.800449 35.617900, 105.590826 35.575975, 105.297354 35.575975, 104.961956 35.575975, 104.710409 35.534051, 104.458861 35.492126, 103.871916 35.492126, 103.788066 35.492126, 103.326895 35.408277, 102.949574 35.408277, 102.488402 35.450201, 102.069156 35.450201, 101.482211 35.450201, 100.937191 35.659825, 100.308321 35.869448, 100.056773 36.037146, 99.050582 36.079071, 97.667069 35.743674, 97.163973 35.617900, 96.115857 35.534051, 95.612761 35.534051, 94.396947 35.911372, 93.684228 36.288694, 92.929584 36.833715, 92.258790 37.169112, 91.629920 37.504509, 90.414105 37.881831, 90.414105 37.881831, 90.246407 37.923755, 89.491763 37.839906, 89.156366 37.672207, 88.485572 37.504509, 87.814778 37.252961, 87.563230 37.169112, 87.143983 37.043338, 85.970093 36.875639, 85.802395 36.875639, 84.083484 36.959489, 84.041560 37.043338, 82.951519 37.546433, 82.699971 37.630283)" );
mPolygonA.clear();
mPolygonB.clear();
mPolygonC.clear();
mPolylineA.clear();
mPolylineB.clear();
mPolylineC.clear();
mPolylineA << mPoint1 << mPoint2 << mPoint3 << mPoint4 << mPoint1;
mPolygonA << mPolylineA;
//Polygon B intersects Polygon A
mPolylineB << mPointA << mPointB << mPointC << mPointD << mPointA;
mPolygonB << mPolylineB;
// Polygon C should intersect no other polys
mPolylineC << mPointW << mPointX << mPointY << mPointZ << mPointW;
mPolygonC << mPolylineC;
mpPolylineGeometryD = QgsGeometry::fromWkt( mWktLine );
//polygon: first item of the list is outer ring,
// inner rings (if any) start from second item
mpPolygonGeometryA = QgsGeometry::fromPolygon( mPolygonA );
mpPolygonGeometryB = QgsGeometry::fromPolygon( mPolygonB );
mpPolygonGeometryC = QgsGeometry::fromPolygon( mPolygonC );
mImage = QImage( 250, 250, QImage::Format_RGB32 );
mImage.fill( qRgb( 152, 219, 249 ) );
mpPainter = new QPainter( &mImage );
// Draw the test shapes first
mPen1 = QPen();
mPen1.setWidth( 5 );
mPen1.setBrush( Qt::green );
mpPainter->setPen( mPen1 );
dumpPolygon( mPolygonA );
mPen1.setBrush( Qt::red );
mpPainter->setPen( mPen1 );
dumpPolygon( mPolygonB );
mPen1.setBrush( Qt::blue );
mpPainter->setPen( mPen1 );
dumpPolygon( mPolygonC );
mPen2 = QPen();
mPen2.setWidth( 1 );
mPen2.setBrush( Qt::black );
QBrush myBrush( Qt::DiagCrossPattern );
//set the pen to a different color -
//any test outs will be drawn in pen2
mpPainter->setPen( mPen2 );
mpPainter->setBrush( myBrush );
}
void TestQgsGeometry::cleanup()
{
// will be called after every testfunction.
delete mpPolygonGeometryA;
delete mpPolygonGeometryB;
delete mpPolygonGeometryC;
delete mpPolylineGeometryD;
delete mpPainter;
}
void TestQgsGeometry::copy()
{
//create a point geometry
QgsGeometry original( new QgsPointV2( 1.0, 2.0 ) );
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
//implicitly shared copy
QgsGeometry copy( original );
QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
//trigger a detach
copy.setGeometry( new QgsPointV2( 3.0, 4.0 ) );
QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 3.0 );
QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 4.0 );
//make sure original was untouched
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
}
void TestQgsGeometry::assignment()
{
//create a point geometry
QgsGeometry original( new QgsPointV2( 1.0, 2.0 ) );
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
//assign to implicitly shared copy
QgsGeometry copy;
copy = original;
QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
//trigger a detach
copy.setGeometry( new QgsPointV2( 3.0, 4.0 ) );
QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 3.0 );
QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 4.0 );
//make sure original was untouched
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
}
void TestQgsGeometry::asVariant()
{
//create a point geometry
QgsGeometry original( new QgsPointV2( 1.0, 2.0 ) );
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
//convert to and from a QVariant
QVariant var = QVariant::fromValue( original );
QVERIFY( var.isValid() );
QgsGeometry fromVar = qvariant_cast<QgsGeometry>( var );
QCOMPARE( fromVar.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( fromVar.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
//also check copying variant
QVariant var2 = var;
QVERIFY( var2.isValid() );
QgsGeometry fromVar2 = qvariant_cast<QgsGeometry>( var2 );
QCOMPARE( fromVar2.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( fromVar2.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
//modify original and check detachment
original.setGeometry( new QgsPointV2( 3.0, 4.0 ) );
QgsGeometry fromVar3 = qvariant_cast<QgsGeometry>( var );
QCOMPARE( fromVar3.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( fromVar3.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
}
void TestQgsGeometry::isEmpty()
{
QgsGeometry geom;
QVERIFY( geom.isEmpty() );
geom.setGeometry( new QgsPointV2( 1.0, 2.0 ) );
QVERIFY( !geom.isEmpty() );
geom.setGeometry( 0 );
QVERIFY( geom.isEmpty() );
}
void TestQgsGeometry::pointV2()
{
//test QgsPointV2
//test constructors
QgsPointV2 p1( 5.0, 6.0 );
QCOMPARE( p1.x(), 5.0 );
QCOMPARE( p1.y(), 6.0 );
QVERIFY( !p1.isEmpty() );
QVERIFY( !p1.is3D() );
QVERIFY( !p1.isMeasure() );
QCOMPARE( p1.wkbType(), QgsWKBTypes::Point );
QCOMPARE( p1.wktTypeStr(), QString( "Point" ) );
QgsPointV2 p2( QgsPoint( 3.0, 4.0 ) );
QCOMPARE( p2.x(), 3.0 );
QCOMPARE( p2.y(), 4.0 );
QVERIFY( !p2.isEmpty() );
QVERIFY( !p2.is3D() );
QVERIFY( !p2.isMeasure() );
QCOMPARE( p2.wkbType(), QgsWKBTypes::Point );
QgsPointV2 p3( QPointF( 7.0, 9.0 ) );
QCOMPARE( p3.x(), 7.0 );
QCOMPARE( p3.y(), 9.0 );
QVERIFY( !p3.isEmpty() );
QVERIFY( !p3.is3D() );
QVERIFY( !p3.isMeasure() );
QCOMPARE( p3.wkbType(), QgsWKBTypes::Point );
QgsPointV2 p4( QgsWKBTypes::Point, 11.0, 13.0 );
QCOMPARE( p4.x(), 11.0 );
QCOMPARE( p4.y(), 13.0 );
QVERIFY( !p4.isEmpty() );
QVERIFY( !p4.is3D() );
QVERIFY( !p4.isMeasure() );
QCOMPARE( p4.wkbType(), QgsWKBTypes::Point );
QgsPointV2 p5( QgsWKBTypes::PointZ, 11.0, 13.0, 15.0 );
QCOMPARE( p5.x(), 11.0 );
QCOMPARE( p5.y(), 13.0 );
QCOMPARE( p5.z(), 15.0 );
QVERIFY( !p5.isEmpty() );
QVERIFY( p5.is3D() );
QVERIFY( !p5.isMeasure() );
QCOMPARE( p5.wkbType(), QgsWKBTypes::PointZ );
QCOMPARE( p5.wktTypeStr(), QString( "PointZ" ) );
QgsPointV2 p6( QgsWKBTypes::PointM, 11.0, 13.0, 0.0, 17.0 );
QCOMPARE( p6.x(), 11.0 );
QCOMPARE( p6.y(), 13.0 );
QCOMPARE( p6.m(), 17.0 );
QVERIFY( !p6.isEmpty() );
QVERIFY( !p6.is3D() );
QVERIFY( p6.isMeasure() );
QCOMPARE( p6.wkbType(), QgsWKBTypes::PointM );
QCOMPARE( p6.wktTypeStr(), QString( "PointM" ) );
QgsPointV2 p7( QgsWKBTypes::PointZM, 11.0, 13.0, 0.0, 17.0 );
QCOMPARE( p7.x(), 11.0 );
QCOMPARE( p7.y(), 13.0 );
QCOMPARE( p7.m(), 17.0 );
QVERIFY( !p7.isEmpty() );
QVERIFY( p7.is3D() );
QVERIFY( p7.isMeasure() );
QCOMPARE( p7.wkbType(), QgsWKBTypes::PointZM );
QCOMPARE( p7.wktTypeStr(), QString( "PointZM" ) );
QgsPointV2 p8( QgsWKBTypes::Point25D, 21.0, 23.0, 25.0 );
QCOMPARE( p8.x(), 21.0 );
QCOMPARE( p8.y(), 23.0 );
QCOMPARE( p8.z(), 25.0 );
QVERIFY( !p8.isEmpty() );
QVERIFY( p8.is3D() );
QVERIFY( !p8.isMeasure() );
QCOMPARE( p8.wkbType(), QgsWKBTypes::Point25D );
#if 0 //should trigger an assert
//try creating a point with a nonsense WKB type
QgsPointV2 p9( QgsWKBTypes::PolygonZM, 11.0, 13.0, 9.0, 17.0 );
QCOMPARE( p9.wkbType(), QgsWKBTypes::Unknown );
#endif
//test equality operator
QVERIFY( QgsPointV2( QgsWKBTypes::Point, 2 / 3.0, 1 / 3.0 ) == QgsPointV2( QgsWKBTypes::Point, 2 / 3.0, 1 / 3.0 ) );
QVERIFY( !( QgsPointV2( QgsWKBTypes::PointZ, 2 / 3.0, 1 / 3.0 ) == QgsPointV2( QgsWKBTypes::Point, 2 / 3.0, 1 / 3.0 ) ) );
QVERIFY( !( QgsPointV2( QgsWKBTypes::Point, 1 / 3.0, 1 / 3.0 ) == QgsPointV2( QgsWKBTypes::Point, 2 / 3.0, 1 / 3.0 ) ) );
QVERIFY( !( QgsPointV2( QgsWKBTypes::Point, 2 / 3.0, 2 / 3.0 ) == QgsPointV2( QgsWKBTypes::Point, 2 / 3.0, 1 / 3.0 ) ) );
QVERIFY( QgsPointV2( QgsWKBTypes::PointZ, 3.0, 4.0, 1 / 3.0 ) == QgsPointV2( QgsWKBTypes::PointZ, 3.0, 4.0, 1 / 3.0 ) );
QVERIFY( !( QgsPointV2( QgsWKBTypes::PointZ, 3.0, 4.0, 1 / 3.0 ) == QgsPointV2( QgsWKBTypes::PointZM, 3.0, 4.0, 1 / 3.0 ) ) );
QVERIFY( !( QgsPointV2( QgsWKBTypes::PointZ, 3.0, 4.0, 2 / 3.0 ) == QgsPointV2( QgsWKBTypes::PointZ, 3.0, 4.0, 1 / 3.0 ) ) );
QVERIFY( QgsPointV2( QgsWKBTypes::PointM, 3.0, 4.0, 0.0, 1 / 3.0 ) == QgsPointV2( QgsWKBTypes::PointM, 3.0, 4.0, 0.0, 1 / 3.0 ) );
QVERIFY( !( QgsPointV2( QgsWKBTypes::PointM, 3.0, 4.0, 0.0, 1 / 3.0 ) == QgsPointV2( QgsWKBTypes::PointZ, 3.0, 4.0, 0.0, 1 / 3.0 ) ) );
QVERIFY( !( QgsPointV2( QgsWKBTypes::PointM, 3.0, 4.0, 0.0, 1 / 3.0 ) == QgsPointV2( QgsWKBTypes::PointM, 3.0, 4.0, 0.0, 2 / 3.0 ) ) );
QVERIFY( QgsPointV2( QgsWKBTypes::PointZM, 3.0, 4.0, 2 / 3.0, 1 / 3.0 ) == QgsPointV2( QgsWKBTypes::PointZM, 3.0, 4.0, 2 / 3.0, 1 / 3.0 ) );
QVERIFY( QgsPointV2( QgsWKBTypes::Point25D, 3.0, 4.0, 2 / 3.0 ) == QgsPointV2( QgsWKBTypes::Point25D, 3.0, 4.0, 2 / 3.0 ) );
QVERIFY( !( QgsPointV2( QgsWKBTypes::Point25D, 3.0, 4.0, 2 / 3.0 ) == QgsPointV2( QgsWKBTypes::PointZ, 3.0, 4.0, 2 / 3.0 ) ) );
//test inequality operator
QVERIFY( !( QgsPointV2( QgsWKBTypes::Point, 2 / 3.0, 1 / 3.0 ) != QgsPointV2( QgsWKBTypes::Point, 2 / 3.0, 1 / 3.0 ) ) );
QVERIFY( QgsPointV2( QgsWKBTypes::Point, 2 / 3.0, 1 / 3.0 ) != QgsPointV2( QgsWKBTypes::PointZ, 2 / 3.0, 1 / 3.0 ) );
//test setters and getters
//x
QgsPointV2 p10( QgsWKBTypes::PointZM );
p10.setX( 5.0 );
QCOMPARE( p10.x(), 5.0 );
QCOMPARE( p10.rx(), 5.0 );
p10.rx() = 9.0;
QCOMPARE( p10.x(), 9.0 );
//y
p10.setY( 7.0 );
QCOMPARE( p10.y(), 7.0 );
QCOMPARE( p10.ry(), 7.0 );
p10.ry() = 3.0;
QCOMPARE( p10.y(), 3.0 );
//z
p10.setZ( 17.0 );
QCOMPARE( p10.z(), 17.0 );
QCOMPARE( p10.rz(), 17.0 );
p10.rz() = 13.0;
QCOMPARE( p10.z(), 13.0 );
//m
p10.setM( 27.0 );
QCOMPARE( p10.m(), 27.0 );
QCOMPARE( p10.rm(), 27.0 );
p10.rm() = 23.0;
QCOMPARE( p10.m(), 23.0 );
//other checks
QCOMPARE( p10.geometryType(), QString( "Point" ) );
QCOMPARE( p10.dimension(), 0 );
//clone
QScopedPointer< QgsPointV2 >clone( p10.clone() );
QVERIFY( p10 == *clone );
//assignment
QgsPointV2 original( QgsWKBTypes::PointZM, 1.0, 2.0, 3.0, -4.0 );
QgsPointV2 assigned( 6.0, 7.0 );
assigned = original;
QVERIFY( assigned == original );
//clear
QgsPointV2 p11( 5.0, 6.0 );
p11.clear();
QCOMPARE( p11.wkbType(), QgsWKBTypes::Unknown );
QCOMPARE( p11.x(), 0.0 );
QCOMPARE( p11.y(), 0.0 );
//to/from WKB
QgsPointV2 p12( QgsWKBTypes::PointZM, 1.0, 2.0, 3.0, -4.0 );
int size = 0;
unsigned char* wkb = p12.asWkb( size );
QCOMPARE( size, p12.wkbSize() );
QgsPointV2 p13;
p13.fromWkb( wkb );
delete[] wkb;
wkb = 0;
QVERIFY( p13 == p12 );
//bad WKB - check for no crash
p13 = QgsPointV2( 1, 2 );
QVERIFY( !p13.fromWkb( 0 ) );
QCOMPARE( p13.wkbType(), QgsWKBTypes::Unknown );
QgsLineStringV2 line;
p13 = QgsPointV2( 1, 2 );
wkb = line.asWkb( size );
QVERIFY( !p13.fromWkb( wkb ) );
delete[] wkb;
wkb = 0;
QCOMPARE( p13.wkbType(), QgsWKBTypes::Unknown );
//to/from WKT
p13 = QgsPointV2( QgsWKBTypes::PointZM, 1.0, 2.0, 3.0, -4.0 );
QString wkt = p13.asWkt();
QVERIFY( !wkt.isEmpty() );
QgsPointV2 p14;
QVERIFY( p14.fromWkt( wkt ) );
QVERIFY( p14 == p13 );
//bad WKT
QVERIFY( !p14.fromWkt( "Polygon()" ) );
QCOMPARE( p14.wkbType(), QgsWKBTypes::Unknown );
//asGML2
QgsPointV2 exportPoint( 1, 2 );
QgsPointV2 exportPointFloat( 1 / 3.0, 2 / 3.0 );
QDomDocument doc( "gml" );
QString expectedGML2( "<Point xmlns=\"gml\"><coordinates xmlns=\"gml\">1,2</coordinates></Point>" );
QCOMPARE( elemToString( exportPoint.asGML2( doc ) ), expectedGML2 );
QString expectedGML2prec3( "<Point xmlns=\"gml\"><coordinates xmlns=\"gml\">0.333,0.667</coordinates></Point>" );
QCOMPARE( elemToString( exportPointFloat.asGML2( doc, 3 ) ), expectedGML2prec3 );
//asGML3
QString expectedGML3( "<Point xmlns=\"gml\"><pos xmlns=\"gml\" srsDimension=\"2\">1 2</pos></Point>" );
QCOMPARE( elemToString( exportPoint.asGML3( doc ) ), expectedGML3 );
QString expectedGML3prec3( "<Point xmlns=\"gml\"><pos xmlns=\"gml\" srsDimension=\"2\">0.333 0.667</pos></Point>" );
QCOMPARE( elemToString( exportPointFloat.asGML3( doc, 3 ) ), expectedGML3prec3 );
//asJSON
QString expectedJson( "{\"type\": \"Point\", \"coordinates\": [1, 2]}" );
QCOMPARE( exportPoint.asJSON(), expectedJson );
QString expectedJsonPrec3( "{\"type\": \"Point\", \"coordinates\": [0.333, 0.667]}" );
QCOMPARE( exportPointFloat.asJSON( 3 ), expectedJsonPrec3 );
//bounding box
QgsPointV2 p15( 1.0, 2.0 );
QCOMPARE( p15.boundingBox(), QgsRectangle( 1.0, 2.0, 1.0, 2.0 ) );
//modify points and test that bounding box is updated accordingly
p15.setX( 3.0 );
QCOMPARE( p15.boundingBox(), QgsRectangle( 3.0, 2.0, 3.0, 2.0 ) );
p15.setY( 6.0 );
QCOMPARE( p15.boundingBox(), QgsRectangle( 3.0, 6.0, 3.0, 6.0 ) );
p15.rx() = 4.0;
QCOMPARE( p15.boundingBox(), QgsRectangle( 4.0, 6.0, 4.0, 6.0 ) );
p15.ry() = 9.0;
QCOMPARE( p15.boundingBox(), QgsRectangle( 4.0, 9.0, 4.0, 9.0 ) );
p15.moveVertex( QgsVertexId( 0, 0, 0 ), QgsPointV2( 11.0, 13.0 ) );
QCOMPARE( p15.boundingBox(), QgsRectangle( 11.0, 13.0, 11.0, 13.0 ) );
p15 = QgsPointV2( 21.0, 23.0 );
QCOMPARE( p15.boundingBox(), QgsRectangle( 21.0, 23.0, 21.0, 23.0 ) );
//CRS transform
QgsCoordinateReferenceSystem sourceSrs;
sourceSrs.createFromSrid( 3994 );
QgsCoordinateReferenceSystem destSrs;
destSrs.createFromSrid( 4326 );
QgsCoordinateTransform tr( sourceSrs, destSrs );
QgsPointV2 p16( QgsWKBTypes::PointZM, 6374985, -3626584, 1, 2 );
p16.transform( tr, QgsCoordinateTransform::ForwardTransform );
QVERIFY( qgsDoubleNear( p16.x(), 175.771, 0.001 ) );
QVERIFY( qgsDoubleNear( p16.y(), -39.722, 0.001 ) );
QVERIFY( qgsDoubleNear( p16.z(), 57.2958, 0.001 ) );
QCOMPARE( p16.m(), 2.0 );
p16.transform( tr, QgsCoordinateTransform::ReverseTransform );
QVERIFY( qgsDoubleNear( p16.x(), 6374985, 1 ) );
QVERIFY( qgsDoubleNear( p16.y(), -3626584, 1 ) );
QVERIFY( qgsDoubleNear( p16.z(), 1.0, 0.001 ) );
QCOMPARE( p16.m(), 2.0 );
//QTransform transform
QTransform qtr = QTransform::fromScale( 2, 3 );
QgsPointV2 p17( QgsWKBTypes::PointZM, 10, 20, 30, 40 );
p17.transform( qtr );
QVERIFY( p17 == QgsPointV2( QgsWKBTypes::PointZM, 20, 60, 30, 40 ) );
//coordinateSequence
QList< QList< QList< QgsPointV2 > > > coord;
QgsPointV2 p18( QgsWKBTypes::PointZM, 1.0, 2.0, 3.0, 4.0 );
p18.coordinateSequence( coord );
QCOMPARE( coord.count(), 1 );
QCOMPARE( coord.at( 0 ).count(), 1 );
QCOMPARE( coord.at( 0 ).at( 0 ).count(), 1 );
QCOMPARE( coord.at( 0 ).at( 0 ).at( 0 ), p18 );
//low level editing
//insertVertex should have no effect
QgsPointV2 p19( QgsWKBTypes::PointZM, 3.0, 4.0, 6.0, 7.0 );
p19.insertVertex( QgsVertexId( 1, 2, 3 ), QgsPointV2( 6.0, 7.0 ) );
QCOMPARE( p19, QgsPointV2( QgsWKBTypes::PointZM, 3.0, 4.0, 6.0, 7.0 ) );
//moveVertex
p19.moveVertex( QgsVertexId( 0, 0, 0 ), QgsPointV2( QgsWKBTypes::PointZM, 1.0, 2.0, 3.0, 4.0 ) );
QCOMPARE( p19, QgsPointV2( QgsWKBTypes::PointZM, 1.0, 2.0, 3.0, 4.0 ) );
//invalid vertex id, should not crash
p19.moveVertex( QgsVertexId( 1, 2, 3 ), QgsPointV2( QgsWKBTypes::PointZM, 2.0, 3.0, 1.0, 2.0 ) );
QCOMPARE( p19, QgsPointV2( QgsWKBTypes::PointZM, 2.0, 3.0, 1.0, 2.0 ) );
//move PointZM using Point
p19.moveVertex( QgsVertexId( 0, 0, 0 ), QgsPointV2( QgsWKBTypes::Point, 11.0, 12.0 ) );
QCOMPARE( p19, QgsPointV2( QgsWKBTypes::PointZM, 11.0, 12.0, 1.0, 2.0 ) );
//move PointZM using PointZ
p19.moveVertex( QgsVertexId( 0, 0, 0 ), QgsPointV2( QgsWKBTypes::PointZ, 21.0, 22.0, 23.0 ) );
QCOMPARE( p19, QgsPointV2( QgsWKBTypes::PointZM, 21.0, 22.0, 23.0, 2.0 ) );
//move PointZM using PointM
p19.moveVertex( QgsVertexId( 0, 0, 0 ), QgsPointV2( QgsWKBTypes::PointM, 31.0, 32.0, 0.0, 43.0 ) );
QCOMPARE( p19, QgsPointV2( QgsWKBTypes::PointZM, 31.0, 32.0, 23.0, 43.0 ) );
//move Point using PointZM (z/m should be ignored)
QgsPointV2 p20( 3.0, 4.0 );
p20.moveVertex( QgsVertexId( 0, 0, 0 ), QgsPointV2( QgsWKBTypes::PointZM, 2.0, 3.0, 1.0, 2.0 ) );
QCOMPARE( p20, QgsPointV2( 2.0, 3.0 ) );
//deleteVertex - should do nothing, but not crash
p20.deleteVertex( QgsVertexId( 0, 0, 0 ) );
QCOMPARE( p20, QgsPointV2( 2.0, 3.0 ) );
//closestSegment
QgsPointV2 closest;
QgsVertexId after;
QCOMPARE( p20.closestSegment( QgsPointV2( 4.0, 6.0 ), closest, after, 0, 0 ), 13.0 );
QCOMPARE( closest, p20 );
QCOMPARE( after, QgsVertexId( 0, 0, 0 ) );
//nextVertex
QgsPointV2 p21( 3.0, 4.0 );
QgsPointV2 p22;
QgsVertexId v( 0, 0, -1 );
QVERIFY( p21.nextVertex( v, p22 ) );
QCOMPARE( p22, p21 );
QCOMPARE( v, QgsVertexId( 0, 0, 0 ) );
//no more vertices
QVERIFY( !p21.nextVertex( v, p22 ) );
v = QgsVertexId( 0, 1, -1 ); //test that ring number is maintained
QVERIFY( p21.nextVertex( v, p22 ) );
QCOMPARE( p22, p21 );
QCOMPARE( v, QgsVertexId( 0, 1, 0 ) );
v = QgsVertexId( 1, 0, -1 ); //test that part number is maintained
QVERIFY( p21.nextVertex( v, p22 ) );
QCOMPARE( p22, p21 );
QCOMPARE( v, QgsVertexId( 1, 0, 0 ) );
//vertexAt - will always be same as point
QCOMPARE( p21.vertexAt( QgsVertexId() ), p21 );
QCOMPARE( p21.vertexAt( QgsVertexId( 0, 0, 0 ) ), p21 );
//vertexAngle - undefined, but check that it doesn't crash
( void )p21.vertexAngle( QgsVertexId() );
//counts
QCOMPARE( p20.vertexCount(), 1 );
QCOMPARE( p20.ringCount(), 1 );
QCOMPARE( p20.partCount(), 1 );
//measures and other abstract geometry methods
QCOMPARE( p20.length(), 0.0 );
QCOMPARE( p20.perimeter(), 0.0 );
QCOMPARE( p20.area(), 0.0 );
QCOMPARE( p20.centroid(), p20 );
QVERIFY( !p20.hasCurvedSegments() );
QScopedPointer< QgsPointV2 >segmented( static_cast< QgsPointV2*>( p20.segmentize() ) );
QCOMPARE( *segmented, p20 );
//addZValue
QgsPointV2 p23( 1.0, 2.0 );
QVERIFY( p23.addZValue( 5.0 ) );
QCOMPARE( p23, QgsPointV2( QgsWKBTypes::PointZ, 1.0, 2.0, 5.0 ) );
QVERIFY( !p23.addZValue( 6.0 ) );
//addMValue
QgsPointV2 p24( 1.0, 2.0 );
QVERIFY( p24.addMValue( 5.0 ) );
QCOMPARE( p24, QgsPointV2( QgsWKBTypes::PointM, 1.0, 2.0, 0.0, 5.0 ) );
QVERIFY( !p24.addMValue( 6.0 ) );
}
void TestQgsGeometry::lineStringV2()
{
//test constructors
QgsLineStringV2 l1;
QVERIFY( l1.isEmpty() );
QCOMPARE( l1.numPoints(), 0 );
QCOMPARE( l1.vertexCount(), 0 );
QCOMPARE( l1.nCoordinates(), 0 );
QCOMPARE( l1.ringCount(), 0 );
QCOMPARE( l1.partCount(), 0 );
QVERIFY( !l1.is3D() );
QVERIFY( !l1.isMeasure() );
QCOMPARE( l1.wkbType(), QgsWKBTypes::LineString );
QCOMPARE( l1.wktTypeStr(), QString( "LineString" ) );
QCOMPARE( l1.geometryType(), QString( "LineString" ) );
QCOMPARE( l1.dimension(), 1 );
QVERIFY( !l1.hasCurvedSegments() );
QCOMPARE( l1.area(), 0.0 );
QCOMPARE( l1.perimeter(), 0.0 );
//addVertex
QgsLineStringV2 l2;
l2.addVertex( QgsPointV2( 1.0, 2.0 ) );
QVERIFY( !l2.isEmpty() );
QCOMPARE( l2.numPoints(), 1 );
QCOMPARE( l2.vertexCount(), 1 );
QCOMPARE( l2.nCoordinates(), 1 );
QCOMPARE( l2.ringCount(), 1 );
QCOMPARE( l2.partCount(), 1 );
QVERIFY( !l2.is3D() );
QVERIFY( !l2.isMeasure() );
QCOMPARE( l2.wkbType(), QgsWKBTypes::LineString );
QVERIFY( !l2.hasCurvedSegments() );
QCOMPARE( l2.area(), 0.0 );
QCOMPARE( l2.perimeter(), 0.0 );
//adding first vertex should set linestring z/m type
QgsLineStringV2 l3;
l3.addVertex( QgsPointV2( QgsWKBTypes::PointZ, 1.0, 2.0, 3.0 ) );
QVERIFY( !l3.isEmpty() );
QVERIFY( l3.is3D() );
QVERIFY( !l3.isMeasure() );
QCOMPARE( l3.wkbType(), QgsWKBTypes::LineStringZ );
QCOMPARE( l3.wktTypeStr(), QString( "LineStringZ" ) );
QgsLineStringV2 l4;
l4.addVertex( QgsPointV2( QgsWKBTypes::PointM, 1.0, 2.0, 0.0, 3.0 ) );
QVERIFY( !l4.isEmpty() );
QVERIFY( !l4.is3D() );
QVERIFY( l4.isMeasure() );
QCOMPARE( l4.wkbType(), QgsWKBTypes::LineStringM );
QCOMPARE( l4.wktTypeStr(), QString( "LineStringM" ) );
QgsLineStringV2 l5;
l5.addVertex( QgsPointV2( QgsWKBTypes::PointZM, 1.0, 2.0, 3.0, 4.0 ) );
QVERIFY( !l5.isEmpty() );
QVERIFY( l5.is3D() );
QVERIFY( l5.isMeasure() );
QCOMPARE( l5.wkbType(), QgsWKBTypes::LineStringZM );
QCOMPARE( l5.wktTypeStr(), QString( "LineStringZM" ) );
QgsLineStringV2 l25d;
l25d.addVertex( QgsPointV2( QgsWKBTypes::Point25D, 1.0, 2.0, 3.0 ) );
QVERIFY( !l25d.isEmpty() );
QVERIFY( l25d.is3D() );
QVERIFY( !l25d.isMeasure() );
QCOMPARE( l25d.wkbType(), QgsWKBTypes::LineString25D );
QCOMPARE( l25d.wktTypeStr(), QString( "LineStringZ" ) );
//adding subsequent vertices should not alter z/m type, regardless of points type
QgsLineStringV2 l6;
l6.addVertex( QgsPointV2( QgsWKBTypes::Point, 1.0, 2.0 ) ); //2d type
QCOMPARE( l6.wkbType(), QgsWKBTypes::LineString );
l6.addVertex( QgsPointV2( QgsWKBTypes::PointZ, 11.0, 12.0, 13.0 ) ); // add 3d point
QCOMPARE( l6.numPoints(), 2 );
QCOMPARE( l6.vertexCount(), 2 );
QCOMPARE( l6.nCoordinates(), 2 );
QCOMPARE( l6.ringCount(), 1 );
QCOMPARE( l6.partCount(), 1 );
QCOMPARE( l6.wkbType(), QgsWKBTypes::LineString ); //should still be 2d
QVERIFY( !l6.is3D() );
QCOMPARE( l6.area(), 0.0 );
QCOMPARE( l6.perimeter(), 0.0 );
QgsLineStringV2 l7;
l7.addVertex( QgsPointV2( QgsWKBTypes::PointZ, 1.0, 2.0, 3.0 ) ); //3d type
QCOMPARE( l7.wkbType(), QgsWKBTypes::LineStringZ );
l7.addVertex( QgsPointV2( QgsWKBTypes::Point, 11.0, 12.0 ) ); //add 2d point
QCOMPARE( l7.wkbType(), QgsWKBTypes::LineStringZ ); //should still be 3d
QCOMPARE( l7.pointN( 1 ), QgsPointV2( QgsWKBTypes::PointZ, 11.0, 12.0, 0.0 ) );
QVERIFY( l7.is3D() );
QCOMPARE( l7.numPoints(), 2 );
QCOMPARE( l7.vertexCount(), 2 );
QCOMPARE( l7.nCoordinates(), 2 );
QCOMPARE( l7.ringCount(), 1 );
QCOMPARE( l7.partCount(), 1 );
//clear
l7.clear();
QVERIFY( l7.isEmpty() );
QCOMPARE( l7.numPoints(), 0 );
QCOMPARE( l7.vertexCount(), 0 );
QCOMPARE( l7.nCoordinates(), 0 );
QCOMPARE( l7.ringCount(), 0 );
QCOMPARE( l7.partCount(), 0 );
QVERIFY( !l7.is3D() );
QVERIFY( !l7.isMeasure() );
QCOMPARE( l7.wkbType(), QgsWKBTypes::Unknown );
//setPoints
QgsLineStringV2 l8;
l8.setPoints( QList< QgsPointV2 >() << QgsPointV2( 1, 2 ) << QgsPointV2( 2, 3 ) << QgsPointV2( 3, 4 ) );
QVERIFY( !l8.isEmpty() );
QCOMPARE( l8.numPoints(), 3 );
QCOMPARE( l8.vertexCount(), 3 );
QCOMPARE( l8.nCoordinates(), 3 );
QCOMPARE( l8.ringCount(), 1 );
QCOMPARE( l8.partCount(), 1 );
QVERIFY( !l8.is3D() );
QVERIFY( !l8.isMeasure() );
QCOMPARE( l8.wkbType(), QgsWKBTypes::LineString );
QVERIFY( !l8.hasCurvedSegments() );
//setPoints with empty list, should clear linestring
l8.setPoints( QList< QgsPointV2 >() );
QVERIFY( l8.isEmpty() );
QCOMPARE( l8.numPoints(), 0 );
QCOMPARE( l8.vertexCount(), 0 );
QCOMPARE( l8.nCoordinates(), 0 );
QCOMPARE( l8.ringCount(), 0 );
QCOMPARE( l8.partCount(), 0 );
QCOMPARE( l8.wkbType(), QgsWKBTypes::Unknown );
//setPoints with z
l8.setPoints( QList< QgsPointV2 >() << QgsPointV2( QgsWKBTypes::PointZ, 1, 2, 3 ) << QgsPointV2( QgsWKBTypes::PointZ, 2, 3, 4 ) );
QCOMPARE( l8.numPoints(), 2 );
QVERIFY( l8.is3D() );
QVERIFY( !l8.isMeasure() );
QCOMPARE( l8.wkbType(), QgsWKBTypes::LineStringZ );
//setPoints with 25d
l8.setPoints( QList< QgsPointV2 >() << QgsPointV2( QgsWKBTypes::Point25D, 1, 2, 4 ) << QgsPointV2( QgsWKBTypes::Point25D, 2, 3, 4 ) );
QCOMPARE( l8.numPoints(), 2 );
QVERIFY( l8.is3D() );
QVERIFY( !l8.isMeasure() );
QCOMPARE( l8.wkbType(), QgsWKBTypes::LineString25D );
QCOMPARE( l8.pointN( 0 ), QgsPointV2( QgsWKBTypes::Point25D, 1, 2, 4 ) );
//setPoints with m
l8.setPoints( QList< QgsPointV2 >() << QgsPointV2( QgsWKBTypes::PointM, 1, 2, 0, 3 ) << QgsPointV2( QgsWKBTypes::PointM, 2, 3, 0, 4 ) );
QCOMPARE( l8.numPoints(), 2 );
QVERIFY( !l8.is3D() );
QVERIFY( l8.isMeasure() );
QCOMPARE( l8.wkbType(), QgsWKBTypes::LineStringM );
//setPoints with zm
l8.setPoints( QList< QgsPointV2 >() << QgsPointV2( QgsWKBTypes::PointZM, 1, 2, 4, 5 ) << QgsPointV2( QgsWKBTypes::PointZM, 2, 3, 4, 5 ) );
QCOMPARE( l8.numPoints(), 2 );
QVERIFY( l8.is3D() );
QVERIFY( l8.isMeasure() );
QCOMPARE( l8.wkbType(), QgsWKBTypes::LineStringZM );
//setPoints with MIXED dimensionality of points
l8.setPoints( QList< QgsPointV2 >() << QgsPointV2( QgsWKBTypes::PointZM, 1, 2, 4, 5 ) << QgsPointV2( QgsWKBTypes::PointM, 2, 3, 0, 5 ) );
QCOMPARE( l8.numPoints(), 2 );
QVERIFY( l8.is3D() );
QVERIFY( l8.isMeasure() );
QCOMPARE( l8.wkbType(), QgsWKBTypes::LineStringZM );
//test point
QCOMPARE( l8.pointN( 0 ), QgsPointV2( QgsWKBTypes::PointZM, 1, 2, 4, 5 ) );
QCOMPARE( l8.pointN( 1 ), QgsPointV2( QgsWKBTypes::PointZM, 2, 3, 0, 5 ) );
//out of range - just want no crash here
QgsPointV2 bad = l8.pointN( -1 );
bad = l8.pointN( 100 );
//test getters/setters
QgsLineStringV2 l9;
l9.setPoints( QList< QgsPointV2 >() << QgsPointV2( QgsWKBTypes::PointZM, 1, 2, 3, 4 )
<< QgsPointV2( QgsWKBTypes::PointZM, 11, 12, 13, 14 )
<< QgsPointV2( QgsWKBTypes::PointZM, 21, 22, 23, 24 ) );
QCOMPARE( l9.xAt( 0 ), 1.0 );
QCOMPARE( l9.xAt( 1 ), 11.0 );
QCOMPARE( l9.xAt( 2 ), 21.0 );
QCOMPARE( l9.xAt( -1 ), 0.0 ); //out of range
QCOMPARE( l9.xAt( 11 ), 0.0 ); //out of range
l9.setXAt( 0, 51.0 );
QCOMPARE( l9.xAt( 0 ), 51.0 );
l9.setXAt( 1, 61.0 );
QCOMPARE( l9.xAt( 1 ), 61.0 );
l9.setXAt( -1, 51.0 ); //out of range
l9.setXAt( 11, 51.0 ); //out of range
QCOMPARE( l9.yAt( 0 ), 2.0 );
QCOMPARE( l9.yAt( 1 ), 12.0 );
QCOMPARE( l9.yAt( 2 ), 22.0 );
QCOMPARE( l9.yAt( -1 ), 0.0 ); //out of range
QCOMPARE( l9.yAt( 11 ), 0.0 ); //out of range
l9.setYAt( 0, 52.0 );
QCOMPARE( l9.yAt( 0 ), 52.0 );
l9.setYAt( 1, 62.0 );
QCOMPARE( l9.yAt( 1 ), 62.0 );
l9.setYAt( -1, 52.0 ); //out of range
l9.setYAt( 11, 52.0 ); //out of range
QCOMPARE( l9.zAt( 0 ), 3.0 );
QCOMPARE( l9.zAt( 1 ), 13.0 );
QCOMPARE( l9.zAt( 2 ), 23.0 );
QCOMPARE( l9.zAt( -1 ), 0.0 ); //out of range
QCOMPARE( l9.zAt( 11 ), 0.0 ); //out of range
l9.setZAt( 0, 53.0 );
QCOMPARE( l9.zAt( 0 ), 53.0 );
l9.setZAt( 1, 63.0 );
QCOMPARE( l9.zAt( 1 ), 63.0 );
l9.setZAt( -1, 53.0 ); //out of range
l9.setZAt( 11, 53.0 ); //out of range
QCOMPARE( l9.mAt( 0 ), 4.0 );
QCOMPARE( l9.mAt( 1 ), 14.0 );
QCOMPARE( l9.mAt( 2 ), 24.0 );
QCOMPARE( l9.mAt( -1 ), 0.0 ); //out of range
QCOMPARE( l9.mAt( 11 ), 0.0 ); //out of range
l9.setMAt( 0, 54.0 );
QCOMPARE( l9.mAt( 0 ), 54.0 );
l9.setMAt( 1, 64.0 );
QCOMPARE( l9.mAt( 1 ), 64.0 );
l9.setMAt( -1, 54.0 ); //out of range
l9.setMAt( 11, 54.0 ); //out of range
//check zAt/setZAt with non-3d linestring
l9.setPoints( QList< QgsPointV2 >() << QgsPointV2( QgsWKBTypes::PointM, 1, 2, 0, 4 )
<< QgsPointV2( QgsWKBTypes::PointM, 11, 12, 0, 14 )
<< QgsPointV2( QgsWKBTypes::PointM, 21, 22, 0, 24 ) );
//basically we just don't want these to crash
QCOMPARE( l9.zAt( 0 ), 0.0 );
QCOMPARE( l9.zAt( 1 ), 0.0 );
l9.setZAt( 0, 53.0 );
l9.setZAt( 1, 63.0 );
//check mAt/setMAt with non-measure linestring
l9.setPoints( QList< QgsPointV2 >() << QgsPointV2( 1, 2 )
<< QgsPointV2( 11, 12 )
<< QgsPointV2( 21, 22 ) );
//basically we just don't want these to crash
QCOMPARE( l9.mAt( 0 ), 0.0 );
QCOMPARE( l9.mAt( 1 ), 0.0 );
l9.setMAt( 0, 53.0 );
l9.setMAt( 1, 63.0 );
//append linestring
//append to empty
QgsLineStringV2 l10;
l10.append( 0 );
QVERIFY( l10.isEmpty() );
QCOMPARE( l10.numPoints(), 0 );
QScopedPointer<QgsLineStringV2> toAppend( new QgsLineStringV2() );
toAppend->setPoints( QList< QgsPointV2 >() << QgsPointV2( 1, 2 )
<< QgsPointV2( 11, 12 )
<< QgsPointV2( 21, 22 ) );
l10.append( toAppend.data() );
QVERIFY( !l10.is3D() );
QVERIFY( !l10.isMeasure() );
QCOMPARE( l10.numPoints(), 3 );
QCOMPARE( l10.vertexCount(), 3 );
QCOMPARE( l10.nCoordinates(), 3 );
QCOMPARE( l10.ringCount(), 1 );
QCOMPARE( l10.partCount(), 1 );
QCOMPARE( l10.wkbType(), QgsWKBTypes::LineString );
QCOMPARE( l10.pointN( 0 ), toAppend->pointN( 0 ) );
QCOMPARE( l10.pointN( 1 ), toAppend->pointN( 1 ) );
QCOMPARE( l10.pointN( 2 ), toAppend->pointN( 2 ) );
//add more points
toAppend.reset( new QgsLineStringV2() );
toAppend->setPoints( QList< QgsPointV2 >() << QgsPointV2( 31, 32 )
<< QgsPointV2( 41, 42 )
<< QgsPointV2( 51, 52 ) );
l10.append( toAppend.data() );
QCOMPARE( l10.numPoints(), 6 );
QCOMPARE( l10.vertexCount(), 6 );
QCOMPARE( l10.nCoordinates(), 6 );
QCOMPARE( l10.ringCount(), 1 );
QCOMPARE( l10.partCount(), 1 );
QCOMPARE( l10.pointN( 3 ), toAppend->pointN( 0 ) );
QCOMPARE( l10.pointN( 4 ), toAppend->pointN( 1 ) );
QCOMPARE( l10.pointN( 5 ), toAppend->pointN( 2 ) );
//check dimensionality is inherited from append line if initially empty
l10.clear();
toAppend.reset( new QgsLineStringV2() );
toAppend->setPoints( QList< QgsPointV2 >() << QgsPointV2( QgsWKBTypes::PointZM, 31, 32, 33, 34 )
<< QgsPointV2( QgsWKBTypes::PointZM, 41, 42, 43 , 44 )
<< QgsPointV2( QgsWKBTypes::PointZM, 51, 52, 53, 54 ) );
l10.append( toAppend.data() );
QVERIFY( l10.is3D() );
QVERIFY( l10.isMeasure() );
QCOMPARE( l10.numPoints(), 3 );
QCOMPARE( l10.ringCount(), 1 );
QCOMPARE( l10.partCount(), 1 );
QCOMPARE( l10.wkbType(), QgsWKBTypes::LineStringZM );
QCOMPARE( l10.pointN( 0 ), toAppend->pointN( 0 ) );
QCOMPARE( l10.pointN( 1 ), toAppend->pointN( 1 ) );
QCOMPARE( l10.pointN( 2 ), toAppend->pointN( 2 ) );