Skip to content

Commit

Permalink
Fix crash in QgsLineStringV2::append if non z/m line appended
Browse files Browse the repository at this point in the history
to a LineString with z/m

Add a bunch of unit tests for QgsLineStringV2 and fix some other
minor issues which they identified.
  • Loading branch information
nyalldawson committed Nov 24, 2015
1 parent 7443431 commit ff36573
Show file tree
Hide file tree
Showing 3 changed files with 577 additions and 11 deletions.
32 changes: 23 additions & 9 deletions src/core/geometry/qgslinestringv2.cpp
Expand Up @@ -132,7 +132,7 @@ QDomElement QgsLineStringV2::asGML3( QDomDocument& doc, int precision, const QSt

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

if ( points.isEmpty() )
{
mWkbType = QgsWKBTypes::Unknown;
mX.clear();
mY.clear();
mZ.clear();
mM.clear();
clear();
return;
}

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

mX += line->mX;
mY += line->mY;
mZ += line->mZ;
mM += line->mM;

if ( line->is3D() )
{
mZ += line->mZ;
}
else
{
// if append line does not have z coordinates, fill with 0 to match number of points in final line
mZ.insert( mZ.count(), mX.size() - mZ.size(), 0 );
}

if ( line->is3D() )
{
mM += line->mM;
}
else
{
// if append line does not have m values, fill with 0 to match number of points in final line
mM.insert( mM.count(), mX.size() - mM.size(), 0 );
}

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

void QgsLineStringV2::addVertex( const QgsPointV2& pt )
{
if ( mWkbType == QgsWKBTypes::Unknown )
if ( mWkbType == QgsWKBTypes::Unknown || mX.isEmpty() )
{
setZMTypeFromSubGeometry( &pt, QgsWKBTypes::LineString );
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/geometry/qgslinestringv2.h
Expand Up @@ -107,7 +107,8 @@ class CORE_EXPORT QgsLineStringV2: public QgsCurveV2
*/
void setMAt( int index, double m );

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

0 comments on commit ff36573

Please sign in to comment.