Skip to content

Commit 24b7c4e

Browse files
committed
Fix errors in locateBetween
1 parent 2bf6af1 commit 24b7c4e

File tree

3 files changed

+93
-5
lines changed

3 files changed

+93
-5
lines changed

python/analysis/qgsgeometryanalyzer.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class QgsGeometryAnalyzer
5757
bool eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer* eventLayer, int lineField, int eventField, const QString& outputLayer,
5858
const QString& outputFormat, int locationField1, int locationField2 = -1, QgsVectorDataProvider* memoryProvider = 0, QProgressDialog* p = 0 );
5959

60+
//locate without the need to give wkb. Only for debugging
61+
QgsGeometry* testLocateBetweenMeasures( double fromMeasure, double toMeasure, QgsGeometry* lineGeom, QList<double>& zValues );
62+
QgsGeometry* testLocateAlongMeasures( double measure, QgsGeometry* lineGeom, QList<double>& zValues );
63+
6064
private:
6165

6266
QList<double> simpleMeasure( QgsGeometry* geometry );

src/analysis/vector/qgsgeometryanalyzer.cpp

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,10 +1103,18 @@ unsigned char* QgsGeometryAnalyzer::locateBetweenWkbString( unsigned char* ptr,
11031103
{
11041104
currentLine.append( pt1 );
11051105
}
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+
11071112
if ( secondPointClipped || i == *nPoints - 1 ) //close current segment
11081113
{
1109-
result.append( currentLine );
1114+
if ( currentLine.size() > 1 )
1115+
{
1116+
result.append( currentLine );
1117+
}
11101118
currentLine.clear();
11111119
}
11121120
}
@@ -1158,12 +1166,20 @@ bool QgsGeometryAnalyzer::clipSegmentByRange( double x1, double y1, double m1, d
11581166
bool reversed = m1 > m2;
11591167
double tmp;
11601168

1161-
//reverse m1, m2 if necessary
1169+
//reverse m1, m2 if necessary (and consequently also x1,x2 / y1, y2)
11621170
if ( reversed )
11631171
{
11641172
tmp = m1;
11651173
m1 = m2;
11661174
m2 = tmp;
1175+
1176+
tmp = x1;
1177+
x1 = x2;
1178+
x2 = tmp;
1179+
1180+
tmp = y1;
1181+
y1 = y2;
1182+
y2 = tmp;
11671183
}
11681184

11691185
//reverse range1, range2 if necessary
@@ -1183,9 +1199,18 @@ bool QgsGeometryAnalyzer::clipSegmentByRange( double x1, double y1, double m1, d
11831199
//segment completely inside of range
11841200
if ( m2 <= range2 && m1 >= range1 )
11851201
{
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+
}
11881212
secondPointClipped = false;
1213+
return true;
11891214
}
11901215

11911216
//m1 inside and m2 not
@@ -1294,3 +1319,58 @@ void QgsGeometryAnalyzer::locateAlongSegment( double x1, double y1, double m1, d
12941319
pt1.setY( y1 + dist * ( y2 - y1 ) );
12951320
pt1Ok = true;
12961321
}
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+
}

src/analysis/vector/qgsgeometryanalyzer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ class ANALYSIS_EXPORT QgsGeometryAnalyzer
111111
bool eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer* eventLayer, int lineField, int eventField, const QString& outputLayer,
112112
const QString& outputFormat, int locationField1, int locationField2 = -1, QgsVectorDataProvider* memoryProvider = 0, QProgressDialog* p = 0 );
113113

114+
//locate without the need to give wkb. Only for debugging
115+
QgsGeometry* testLocateBetweenMeasures( double fromMeasure, double toMeasure, QgsGeometry* lineGeom, QList<double>& zValues );
116+
QgsGeometry* testLocateAlongMeasures( double measure, QgsGeometry* lineGeom, QList<double>& zValues );
117+
114118
private:
115119

116120
QList<double> simpleMeasure( QgsGeometry* geometry );

0 commit comments

Comments
 (0)