Skip to content

Commit 53d4d0b

Browse files
committed
Fix filterVertices for multipoint geometries
1 parent f7618d0 commit 53d4d0b

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎src/core/geometry/qgsmultipoint.cpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,20 @@ double QgsMultiPoint::segmentLength( QgsVertexId ) const
182182
return 0.0;
183183
}
184184

185+
void QgsMultiPoint::filterVertices( const std::function<bool ( const QgsPoint & )> &filter )
186+
{
187+
mGeometries.erase( std::remove_if( mGeometries.begin(), mGeometries.end(), // clazy:exclude=detaching-member
188+
[&filter]( const QgsAbstractGeometry * part )
189+
{
190+
if ( const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( part ) )
191+
{
192+
return !filter( *point );
193+
}
194+
else
195+
return true;
196+
} ), mGeometries.end() ); // clazy:exclude=detaching-member
197+
}
198+
185199
bool QgsMultiPoint::wktOmitChildType() const
186200
{
187201
return true;

‎src/core/geometry/qgsmultipoint.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class CORE_EXPORT QgsMultiPoint: public QgsGeometryCollection
4747
double segmentLength( QgsVertexId startVertex ) const override;
4848

4949
#ifndef SIP_RUN
50+
void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) override;
5051

5152
/**
5253
* Cast the \a geom to a QgsLineString.

‎tests/src/core/testqgsgeometry.cpp‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4538,7 +4538,7 @@ void TestQgsGeometry::lineString()
45384538
filterLine.filterVertices( filter ); // no crash
45394539
filterLine.setPoints( QgsPointSequence() << QgsPoint( 11, 2, 3, 4, QgsWkbTypes::PointZM ) << QgsPoint( 1, 2, 3, 4, QgsWkbTypes::PointZM ) << QgsPoint( 4, 12, 13, 14, QgsWkbTypes::PointZM ) << QgsPoint( 111, 12, 23, 24, QgsWkbTypes::PointZM ) );
45404540
filterLine.filterVertices( filter );
4541-
QCOMPARE( swapLine.asWkt( 2 ), QStringLiteral( "LineStringZM (2 11 3 4, 12 11 13 14, 12 111 23 24)" ) );
4541+
QCOMPARE( filterLine.asWkt( 2 ), QStringLiteral( "LineStringZM (1 2 3 4, 4 12 13 14)" ) );
45424542
}
45434543

45444544
void TestQgsGeometry::polygon()
@@ -11583,6 +11583,20 @@ void TestQgsGeometry::multiPoint()
1158311583
mp.addGeometry( new QgsPoint( QgsWkbTypes::PointZM, 10, 1, 4, 8 ) );
1158411584
QVERIFY( !mp.removeDuplicateNodes() );
1158511585
QCOMPARE( mp.numGeometries(), 2 );
11586+
11587+
// filter vertex
11588+
QgsMultiPoint filterPoint;
11589+
auto filter = []( const QgsPoint & point )-> bool
11590+
{
11591+
return point.x() < 5;
11592+
};
11593+
filterPoint.filterVertices( filter ); // no crash
11594+
filterPoint.addGeometry( new QgsPoint( QgsWkbTypes::PointZM, 10, 0, 4, 8 ) );
11595+
filterPoint.addGeometry( new QgsPoint( QgsWkbTypes::PointZM, 3, 0, 4, 8 ) );
11596+
filterPoint.addGeometry( new QgsPoint( QgsWkbTypes::PointZM, 1, 0, 4, 8 ) );
11597+
filterPoint.addGeometry( new QgsPoint( QgsWkbTypes::PointZM, 11, 0, 4, 8 ) );
11598+
filterPoint.filterVertices( filter );
11599+
QCOMPARE( filterPoint.asWkt( 2 ), QStringLiteral( "MultiPointZM ((3 0 4 8),(1 0 4 8))" ) );
1158611600
}
1158711601

1158811602
void TestQgsGeometry::multiLineString()

0 commit comments

Comments
 (0)