@@ -1103,10 +1103,18 @@ unsigned char* QgsGeometryAnalyzer::locateBetweenWkbString( unsigned char* ptr,
1103
1103
{
1104
1104
currentLine.append ( pt1 );
1105
1105
}
1106
- currentLine.append ( pt2 );
1106
+
1107
+ if ( pt1 != pt2 ) // avoid duplicated entry if measure value equals m-value of vertex
1108
+ {
1109
+ currentLine.append ( pt2 );
1110
+ }
1111
+
1107
1112
if ( secondPointClipped || i == *nPoints - 1 ) // close current segment
1108
1113
{
1109
- result.append ( currentLine );
1114
+ if ( currentLine.size () > 1 )
1115
+ {
1116
+ result.append ( currentLine );
1117
+ }
1110
1118
currentLine.clear ();
1111
1119
}
1112
1120
}
@@ -1158,12 +1166,20 @@ bool QgsGeometryAnalyzer::clipSegmentByRange( double x1, double y1, double m1, d
1158
1166
bool reversed = m1 > m2;
1159
1167
double tmp;
1160
1168
1161
- // reverse m1, m2 if necessary
1169
+ // reverse m1, m2 if necessary (and consequently also x1,x2 / y1, y2)
1162
1170
if ( reversed )
1163
1171
{
1164
1172
tmp = m1;
1165
1173
m1 = m2;
1166
1174
m2 = tmp;
1175
+
1176
+ tmp = x1;
1177
+ x1 = x2;
1178
+ x2 = tmp;
1179
+
1180
+ tmp = y1 ;
1181
+ y1 = y2;
1182
+ y2 = tmp;
1167
1183
}
1168
1184
1169
1185
// reverse range1, range2 if necessary
@@ -1183,9 +1199,18 @@ bool QgsGeometryAnalyzer::clipSegmentByRange( double x1, double y1, double m1, d
1183
1199
// segment completely inside of range
1184
1200
if ( m2 <= range2 && m1 >= range1 )
1185
1201
{
1186
- pt1.setX ( x1 ); pt1.setY ( y1 );
1187
- pt2.setX ( x2 ); pt2.setY ( y2 );
1202
+ if ( reversed )
1203
+ {
1204
+ pt1.setX ( x2 ); pt1.setY ( y2 );
1205
+ pt2.setX ( x1 ); pt2.setY ( y1 );
1206
+ }
1207
+ else
1208
+ {
1209
+ pt1.setX ( x1 ); pt1.setY ( y1 );
1210
+ pt2.setX ( x2 ); pt2.setY ( y2 );
1211
+ }
1188
1212
secondPointClipped = false ;
1213
+ return true ;
1189
1214
}
1190
1215
1191
1216
// m1 inside and m2 not
@@ -1294,3 +1319,58 @@ void QgsGeometryAnalyzer::locateAlongSegment( double x1, double y1, double m1, d
1294
1319
pt1.setY ( y1 + dist * ( y2 - y1 ) );
1295
1320
pt1Ok = true ;
1296
1321
}
1322
+
1323
+ QgsGeometry* QgsGeometryAnalyzer::testLocateBetweenMeasures ( double fromMeasure, double toMeasure, QgsGeometry* lineGeom, QList<double >& zValues )
1324
+ {
1325
+ // assume single line
1326
+ QgsPolyline line = lineGeom->asPolyline ();
1327
+
1328
+ QgsMultiPolyline output;
1329
+ QgsPolyline currentLine;
1330
+
1331
+ double x, y, z, prevx, prevy, prevz;
1332
+
1333
+ QgsPoint pt1, pt2;
1334
+ bool measureInSegment; // true if measure is contained in the segment
1335
+ bool secondPointClipped; // true if second point is != segment endpoint
1336
+
1337
+ for ( int i = 0 ; i < line.size (); ++i )
1338
+ {
1339
+ x = line.at ( i ).x ();
1340
+ y = line.at ( i ).y ();
1341
+ z = zValues.at ( i );
1342
+
1343
+ if ( i > 0 )
1344
+ {
1345
+ measureInSegment = clipSegmentByRange ( prevx, prevy, prevz, x, y, z, fromMeasure, toMeasure, pt1, pt2, secondPointClipped );
1346
+ if ( measureInSegment )
1347
+ {
1348
+ if ( currentLine.size () < 1 ) // no points collected yet, so the first point needs to be added to the line
1349
+ {
1350
+ currentLine.append ( pt1 );
1351
+ }
1352
+
1353
+ if ( pt1 != pt2 ) // avoid duplicated entry if measure value equals m-value of vertex
1354
+ {
1355
+ currentLine.append ( pt2 );
1356
+ }
1357
+
1358
+ if ( secondPointClipped || i == line.size () - 1 ) // close current segment
1359
+ {
1360
+ if ( currentLine.size () > 1 )
1361
+ {
1362
+ output.append ( currentLine );
1363
+ }
1364
+ currentLine.clear ();
1365
+ }
1366
+ }
1367
+ }
1368
+ prevx = x; prevy = y; prevz = z;
1369
+ }
1370
+ return QgsGeometry::fromMultiPolyline ( output );
1371
+ }
1372
+
1373
+ QgsGeometry* QgsGeometryAnalyzer::testLocateAlongMeasures ( double measure, QgsGeometry* lineGeom, QList<double >& zValues )
1374
+ {
1375
+ return 0 ;
1376
+ }
0 commit comments