@@ -126,6 +126,8 @@ class TestQgsGeometry : public QObject
126
126
127
127
void isSimple ();
128
128
129
+ void reshapeGeometryLineMerge ();
130
+
129
131
private:
130
132
// ! A helper method to do a render check to see if the geometry op is as expected
131
133
bool renderCheck ( const QString &testName, const QString &comment = QLatin1String( QLatin1String( " " ) ), int mismatchCount = 0 );
@@ -1078,7 +1080,27 @@ void TestQgsGeometry::lineString()
1078
1080
QCOMPARE ( fromPts.xAt ( 2 ), 21.0 );
1079
1081
QCOMPARE ( fromPts.yAt ( 2 ), 22.0 );
1080
1082
1081
-
1083
+ // from QVector<QgsPoint>
1084
+ QVector<QgsPoint> ptsVector;
1085
+ ptsVector << QgsPoint ( 10 , 20 ) << QgsPoint ( 30 , 40 );
1086
+ QgsLineString fromVector ( ptsVector );
1087
+ QCOMPARE ( fromVector.wkbType (), QgsWkbTypes::LineString );
1088
+ QCOMPARE ( fromVector.numPoints (), 2 );
1089
+ QCOMPARE ( fromVector.xAt ( 0 ), 10.0 );
1090
+ QCOMPARE ( fromVector.yAt ( 0 ), 20.0 );
1091
+ QCOMPARE ( fromVector.xAt ( 1 ), 30.0 );
1092
+ QCOMPARE ( fromVector.yAt ( 1 ), 40.0 );
1093
+ QVector<QgsPoint> ptsVector3D;
1094
+ ptsVector3D << QgsPoint ( QgsWkbTypes::PointZ, 10 , 20 , 100 ) << QgsPoint ( QgsWkbTypes::PointZ, 30 , 40 , 200 );
1095
+ QgsLineString fromVector3D ( ptsVector3D );
1096
+ QCOMPARE ( fromVector3D.wkbType (), QgsWkbTypes::LineStringZ );
1097
+ QCOMPARE ( fromVector3D.numPoints (), 2 );
1098
+ QCOMPARE ( fromVector3D.xAt ( 0 ), 10.0 );
1099
+ QCOMPARE ( fromVector3D.yAt ( 0 ), 20.0 );
1100
+ QCOMPARE ( fromVector3D.zAt ( 0 ), 100.0 );
1101
+ QCOMPARE ( fromVector3D.xAt ( 1 ), 30.0 );
1102
+ QCOMPARE ( fromVector3D.yAt ( 1 ), 40.0 );
1103
+ QCOMPARE ( fromVector3D.zAt ( 1 ), 200.0 );
1082
1104
1083
1105
// addVertex
1084
1106
QgsLineString l2;
@@ -5452,5 +5474,48 @@ void TestQgsGeometry::isSimple()
5452
5474
}
5453
5475
}
5454
5476
5477
+ void TestQgsGeometry::reshapeGeometryLineMerge ()
5478
+ {
5479
+ int res;
5480
+ QgsGeometry g2D = QgsGeometry::fromWkt ( " LINESTRING(10 10, 20 20)" );
5481
+ QgsGeometry g3D = QgsGeometry::fromWkt ( " LINESTRINGZ(10 10 1, 20 20 2)" );
5482
+
5483
+ // prepare 2D reshaping line
5484
+ QVector<QgsPoint> v2D_1, v2D_2;
5485
+ v2D_1 << QgsPoint ( 20 , 20 ) << QgsPoint ( 30 , 30 );
5486
+ v2D_2 << QgsPoint ( 10 , 10 ) << QgsPoint ( -10 , -10 );
5487
+ QgsLineString line2D_1 ( v2D_1 ), line2D_2 ( v2D_2 );
5488
+
5489
+ // prepare 3D reshaping line
5490
+ QVector<QgsPoint> v3D_1, v3D_2;
5491
+ v3D_1 << QgsPoint ( QgsWkbTypes::PointZ, 20 , 20 , 2 ) << QgsPoint ( QgsWkbTypes::PointZ, 30 , 30 , 3 );
5492
+ v3D_2 << QgsPoint ( QgsWkbTypes::PointZ, 10 , 10 , 1 ) << QgsPoint ( QgsWkbTypes::PointZ, -10 , -10 , -1 );
5493
+ QgsLineString line3D_1 ( v3D_1 ), line3D_2 ( v3D_2 );
5494
+
5495
+ // append with 2D line
5496
+ QgsGeometry g2D_1 = g2D;
5497
+ res = g2D_1.reshapeGeometry ( line2D_1 );
5498
+ QCOMPARE ( res, 0 );
5499
+ QCOMPARE ( g2D_1.exportToWkt (), QString ( " LineString (10 10, 20 20, 30 30)" ) );
5500
+
5501
+ // prepend with 2D line
5502
+ QgsGeometry g2D_2 = g2D;
5503
+ res = g2D_2.reshapeGeometry ( line2D_2 );
5504
+ QCOMPARE ( res, 0 );
5505
+ QCOMPARE ( g2D_2.exportToWkt (), QString ( " LineString (-10 -10, 10 10, 20 20)" ) );
5506
+
5507
+ // append with 3D line
5508
+ QgsGeometry g3D_1 = g3D;
5509
+ res = g3D_1.reshapeGeometry ( line3D_1 );
5510
+ QCOMPARE ( res, 0 );
5511
+ QCOMPARE ( g3D_1.exportToWkt (), QString ( " LineStringZ (10 10 1, 20 20 2, 30 30 3)" ) );
5512
+
5513
+ // prepend with 3D line
5514
+ QgsGeometry g3D_2 = g3D;
5515
+ res = g3D_2.reshapeGeometry ( line3D_2 );
5516
+ QCOMPARE ( res, 0 );
5517
+ QCOMPARE ( g3D_2.exportToWkt (), QString ( " LineStringZ (-10 -10 -1, 10 10 1, 20 20 2)" ) );
5518
+ }
5519
+
5455
5520
QGSTEST_MAIN ( TestQgsGeometry )
5456
5521
#include " testqgsgeometry.moc"
0 commit comments