Skip to content
Permalink
Browse files

Merge pull request #2730 from PeterPetrik/13669_duplicate_circular_st…

…ring_nodes

fix #13669 (Circular string generates duplicated nodes)
  • Loading branch information
nyalldawson committed Jan 31, 2016
2 parents 4c8fcc5 + 84e8b10 commit 6a91603fe704c8e210330ec59280f5c293de4ef9
Showing with 59 additions and 14 deletions.
  1. +38 −14 src/core/geometry/qgslinestringv2.cpp
  2. +21 −0 tests/src/core/testqgsgeometry.cpp
@@ -447,27 +447,51 @@ void QgsLineStringV2::append( const QgsLineStringV2* line )
setZMTypeFromSubGeometry( line, QgsWKBTypes::LineString );
}

// do not store duplicit points
if ( numPoints() > 0 &&
line->numPoints() > 0 &&
endPoint() == line->startPoint() )
{
mX.pop_back();
mY.pop_back();

if ( is3D() )
{
mZ.pop_back();
}
if ( isMeasure() )
{
mM.pop_back();
}
}

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

if ( line->is3D() )
{
mZ += line->mZ;
}
else
if ( is3D() )
{
// 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() )
{
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 ( isMeasure() )
{
// 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 );
if ( line->isMeasure() )
{
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
@@ -1108,6 +1108,27 @@ void TestQgsGeometry::lineStringV2()
QCOMPARE( l10.pointN( 1 ), QgsPointV2( QgsWKBTypes::Point25D, 31, 32, 33 ) );
QCOMPARE( l10.pointN( 2 ), QgsPointV2( QgsWKBTypes::Point25D, 41, 42, 43 ) );

//append another line the closes the original geometry.
//Make sure there are not duplicit points except start and end point
l10.clear();
toAppend.reset( new QgsLineStringV2() );
toAppend->setPoints( QList< QgsPointV2 >()
<< QgsPointV2( 1, 1 )
<< QgsPointV2( 5, 5 )
<< QgsPointV2( 10, 1 ) );
l10.append( toAppend.data() );
QCOMPARE( l10.numPoints(), 3 );
QCOMPARE( l10.vertexCount(), 3 );
toAppend.reset( new QgsLineStringV2() );
toAppend->setPoints( QList< QgsPointV2 >()
<< QgsPointV2( 10, 1 )
<< QgsPointV2( 1, 1 ) );
l10.append( toAppend.data() );

QVERIFY( l10.isClosed() );
QCOMPARE( l10.numPoints(), 4 );
QCOMPARE( l10.vertexCount(), 4 );

//equality
QgsLineStringV2 e1;
QgsLineStringV2 e2;

0 comments on commit 6a91603

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