Skip to content

Commit ff36573

Browse files
committed
Fix crash in QgsLineStringV2::append if non z/m line appended
to a LineString with z/m Add a bunch of unit tests for QgsLineStringV2 and fix some other minor issues which they identified.
1 parent 7443431 commit ff36573

File tree

3 files changed

+577
-11
lines changed

3 files changed

+577
-11
lines changed

src/core/geometry/qgslinestringv2.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ QDomElement QgsLineStringV2::asGML3( QDomDocument& doc, int precision, const QSt
132132

133133
QDomElement elemCurve = doc.createElementNS( ns, "Curve" );
134134
QDomElement elemSegments = doc.createElementNS( ns, "segments" );
135-
QDomElement elemArcString = doc.createElementNS( ns, "LineString" );
135+
QDomElement elemArcString = doc.createElementNS( ns, "LineStringSegment" );
136136
elemArcString.appendChild( QgsGeometryUtils::pointsToGML3( pts, doc, precision, ns, is3D() ) );
137137
elemSegments.appendChild( elemArcString );
138138
elemCurve.appendChild( elemSegments );
@@ -303,11 +303,7 @@ void QgsLineStringV2::setPoints( const QList<QgsPointV2>& points )
303303

304304
if ( points.isEmpty() )
305305
{
306-
mWkbType = QgsWKBTypes::Unknown;
307-
mX.clear();
308-
mY.clear();
309-
mZ.clear();
310-
mM.clear();
306+
clear();
311307
return;
312308
}
313309

@@ -366,8 +362,26 @@ void QgsLineStringV2::append( const QgsLineStringV2* line )
366362

367363
mX += line->mX;
368364
mY += line->mY;
369-
mZ += line->mZ;
370-
mM += line->mM;
365+
366+
if ( line->is3D() )
367+
{
368+
mZ += line->mZ;
369+
}
370+
else
371+
{
372+
// if append line does not have z coordinates, fill with 0 to match number of points in final line
373+
mZ.insert( mZ.count(), mX.size() - mZ.size(), 0 );
374+
}
375+
376+
if ( line->is3D() )
377+
{
378+
mM += line->mM;
379+
}
380+
else
381+
{
382+
// if append line does not have m values, fill with 0 to match number of points in final line
383+
mM.insert( mM.count(), mX.size() - mM.size(), 0 );
384+
}
371385

372386
mBoundingBox = QgsRectangle(); //set bounding box invalid
373387
}
@@ -524,7 +538,7 @@ bool QgsLineStringV2::deleteVertex( const QgsVertexId& position )
524538

525539
void QgsLineStringV2::addVertex( const QgsPointV2& pt )
526540
{
527-
if ( mWkbType == QgsWKBTypes::Unknown )
541+
if ( mWkbType == QgsWKBTypes::Unknown || mX.isEmpty() )
528542
{
529543
setZMTypeFromSubGeometry( &pt, QgsWKBTypes::LineString );
530544
}

src/core/geometry/qgslinestringv2.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ class CORE_EXPORT QgsLineStringV2: public QgsCurveV2
107107
*/
108108
void setMAt( int index, double m );
109109

110-
/** Resets the line string to match the specified list of points.
110+
/** Resets the line string to match the specified list of points. The line string will
111+
* inherit the dimensionality of the first point in the list.
111112
* @param points new points for line string. If empty, line string will be cleared.
112113
*/
113114
void setPoints( const QList<QgsPointV2>& points );

0 commit comments

Comments
 (0)