Skip to content
Permalink
Browse files

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.
  • Loading branch information
nyalldawson committed Nov 24, 2015
1 parent 7443431 commit ff36573a74ed3bed8439bc6dc1a62ec3b3b80d96
Showing with 577 additions and 11 deletions.
  1. +23 −9 src/core/geometry/qgslinestringv2.cpp
  2. +2 −1 src/core/geometry/qgslinestringv2.h
  3. +552 −1 tests/src/core/testqgsgeometry.cpp
@@ -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 );
@@ -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;
}

@@ -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
}
@@ -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 );
}
@@ -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 );

0 comments on commit ff36573

Please sign in to comment.
You can’t perform that action at this time.