diff --git a/python/plugins/processing/tests/testdata/custom/voronoi_points_extent_clip.json b/python/plugins/processing/tests/testdata/custom/voronoi_points_extent_clip.json
new file mode 100644
index 00000000000..38c85c3e80f
--- /dev/null
+++ b/python/plugins/processing/tests/testdata/custom/voronoi_points_extent_clip.json
@@ -0,0 +1,30 @@
+{
+"type": "FeatureCollection",
+"name": "SuspectPoints_20dp",
+"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
+"xy_coordinate_resolution": 1e-20,
+"features": [
+{ "type": "Feature", "properties": { "rownum": 1 }, "geometry": { "type": "Point", "coordinates": [ -4.06625270109031067278, 10.91291423849551200931 ] } },
+{ "type": "Feature", "properties": { "rownum": 2 }, "geometry": { "type": "Point", "coordinates": [ -4.0670860347665094281, 10.91291423849551200931 ] } },
+{ "type": "Feature", "properties": { "rownum": 3 }, "geometry": { "type": "Point", "coordinates": [ -4.06541936741411191747, 10.91291423849551200931 ] } },
+{ "type": "Feature", "properties": { "rownum": 4 }, "geometry": { "type": "Point", "coordinates": [ -4.06625270109031067278, 10.91458090611198095132 ] } },
+{ "type": "Feature", "properties": { "rownum": 5 }, "geometry": { "type": "Point", "coordinates": [ -4.06625270109031067278, 10.91374757230374648032 ] } },
+{ "type": "Feature", "properties": { "rownum": 6 }, "geometry": { "type": "Point", "coordinates": [ -4.06541936741411191747, 10.91374757230374648032 ] } },
+{ "type": "Feature", "properties": { "rownum": 7 }, "geometry": { "type": "Point", "coordinates": [ -4.06541936741411191747, 10.91458090611198095132 ] } },
+{ "type": "Feature", "properties": { "rownum": 8 }, "geometry": { "type": "Point", "coordinates": [ -4.06458603373791405033, 10.9124975715913947738 ] } },
+{ "type": "Feature", "properties": { "rownum": 9 }, "geometry": { "type": "Point", "coordinates": [ -4.06458603373791405033, 10.91374757230374648032 ] } },
+{ "type": "Feature", "properties": { "rownum": 10 }, "geometry": { "type": "Point", "coordinates": [ -4.06541936741411191747, 10.91083090397492405543 ] } },
+{ "type": "Feature", "properties": { "rownum": 11 }, "geometry": { "type": "Point", "coordinates": [ -4.06541936741411191747, 10.90958090326257234892 ] } },
+{ "type": "Feature", "properties": { "rownum": 12 }, "geometry": { "type": "Point", "coordinates": [ -4.06458603373791405033, 10.91124757087904129094 ] } },
+{ "type": "Feature", "properties": { "rownum": 13 }, "geometry": { "type": "Point", "coordinates": [ -4.06708603476650853992, 10.91208090468727576194 ] } },
+{ "type": "Feature", "properties": { "rownum": 14 }, "geometry": { "type": "Point", "coordinates": [ -4.06541936741411191747, 10.91208090468727576194 ] } },
+{ "type": "Feature", "properties": { "rownum": 15 }, "geometry": { "type": "Point", "coordinates": [ -4.0637527000617161832, 10.91208090468727576194 ] } },
+{ "type": "Feature", "properties": { "rownum": 16 }, "geometry": { "type": "Point", "coordinates": [ -4.06875270211890516237, 10.91291423849551023295 ] } },
+{ "type": "Feature", "properties": { "rownum": 17 }, "geometry": { "type": "Point", "coordinates": [ -4.06875270211890516237, 10.91208090468727576194 ] } },
+{ "type": "Feature", "properties": { "rownum": 18 }, "geometry": { "type": "Point", "coordinates": [ -4.0670860347665094281, 10.91374757230374648032 ] } },
+{ "type": "Feature", "properties": { "rownum": 19 }, "geometry": { "type": "Point", "coordinates": [ -4.06875270211890516237, 10.91374757230374648032 ] } },
+{ "type": "Feature", "properties": { "rownum": 20 }, "geometry": { "type": "Point", "coordinates": [ -4.0637527000617161832, 10.91124757087904129094 ] } },
+{ "type": "Feature", "properties": { "rownum": 21 }, "geometry": { "type": "Point", "coordinates": [ -4.0637527000617161832, 10.90958090326257234892 ] } },
+{ "type": "Feature", "properties": { "rownum": 22 }, "geometry": { "type": "Point", "coordinates": [ -4.0637527000617161832, 10.91041423707080681993 ] } }
+]
+}
diff --git a/python/plugins/processing/tests/testdata/expected/voronoi_polygons_extent_clip.gml b/python/plugins/processing/tests/testdata/expected/voronoi_polygons_extent_clip.gml
new file mode 100644
index 00000000000..ee0d4ab709d
--- /dev/null
+++ b/python/plugins/processing/tests/testdata/expected/voronoi_polygons_extent_clip.gml
@@ -0,0 +1,164 @@
+
+
+ 10.9095809032626 -4.0687527021189110.914580906112 -4.06375270006172
+
+
+
+ 10.9095809032626 -4.0687527021189110.9124975715914 -4.06791936844271
+ 10.9095809032626 -4.06875270211891 10.9124975715914 -4.06875270211891 10.9124975715914 -4.06791936844271 10.9097197925827 -4.06791936844271 10.9095809032626 -4.06802353544931 10.9095809032626 -4.06875270211891
+ 17
+
+
+
+
+ 10.9124975715914 -4.0679193684427110.9133309053996 -4.06666936792841
+ 10.9133309053996 -4.06791936844271 10.9133309053996 -4.06791936844271 10.9133309053996 -4.06666936792841 10.9124975715914 -4.06666936792841 10.9124975715914 -4.06791936844271 10.9133309053996 -4.06791936844271
+ 2
+
+
+
+
+ 10.9095809032626 -4.0680235354493110.9102059036187 -4.06458603373791
+ 10.9095809032626 -4.06802353544931 10.9097197925827 -4.06791936844271 10.9102059036187 -4.06719020177311 10.9102059036187 -4.06469020048045 10.9099975701667 -4.06458603373791 10.9095809032626 -4.06458603373791 10.9095809032626 -4.06802353544931
+ 11
+
+
+
+
+ 10.9124975715914 -4.0687527021189110.9133309053996 -4.06791936844271
+ 10.9133309053996 -4.06875270211891 10.9133309053996 -4.06791936844271 10.9124975715914 -4.06791936844271 10.9124975715914 -4.06875270211891 10.9133309053996 -4.06875270211891
+ 16
+
+
+
+
+ 10.9133309053996 -4.0687527021189110.914580906112 -4.06791936844271
+ 10.914580906112 -4.06875270211891 10.914580906112 -4.06791936844271 10.9133309053996 -4.06791936844271 10.9133309053996 -4.06791936844271 10.9133309053996 -4.06875270211891 10.914580906112 -4.06875270211891
+ 19
+
+
+
+
+ 10.9120809048193 -4.0666693679284110.9133309053996 -4.06583603425221
+ 10.9133309053996 -4.06666936792841 10.9133309053996 -4.06583603425221 10.9124975715914 -4.06583603425221 10.9120809048193 -4.06625270109031 10.9124975715914 -4.06666936792841 10.9133309053996 -4.06666936792841
+ 1
+
+
+
+
+ 10.9097197925827 -4.0679193684427110.9124975715914 -4.06625270109031
+ 10.9120809048193 -4.06625270109031 10.9114559043311 -4.06625270109031 10.9102059036187 -4.06719020177311 10.9097197925827 -4.06791936844271 10.9124975715914 -4.06791936844271 10.9124975715914 -4.06666936792841 10.9120809048193 -4.06625270109031
+ 13
+
+
+
+
+ 10.9141642392079 -4.0670860348985510.914580906112 -4.06583603425221
+ 10.914580906112 -4.06583603425221 10.9141642392079 -4.06583603425221 10.9141642392079 -4.06666936792841 10.914580906112 -4.06708603489855 10.914580906112 -4.06583603425221
+ 4
+
+
+
+
+ 10.9133309053996 -4.0679193684427110.914580906112 -4.06666936792841
+ 10.914580906112 -4.06708603489855 10.9141642392079 -4.06666936792841 10.9133309053996 -4.06666936792841 10.9133309053996 -4.06791936844271 10.914580906112 -4.06791936844271 10.914580906112 -4.06708603489855
+ 18
+
+
+
+
+ 10.9102059036187 -4.0671902017731110.9114559043311 -4.06465547818892
+ 10.9114559043311 -4.06625270109031 10.9114559043311 -4.06521103406108 10.9103447927628 -4.06465547818892 10.9102059036187 -4.06469020048045 10.9102059036187 -4.06719020177311 10.9114559043311 -4.06625270109031
+ 10
+
+
+
+
+ 10.9133309053996 -4.0666693679284110.9141642392079 -4.06583603425221
+ 10.9141642392079 -4.06666936792841 10.9141642392079 -4.06583603425221 10.9133309053996 -4.06583603425221 10.9133309053996 -4.06666936792841 10.9141642392079 -4.06666936792841
+ 5
+
+
+
+
+ 10.9114559043311 -4.0662527010903110.9124975715914 -4.06479436709094
+ 10.9120809048193 -4.06625270109031 10.9124975715914 -4.06583603425221 10.9124975715914 -4.06510686731855 10.9118725712352 -4.06479436709094 10.9114559043311 -4.06521103406108 10.9114559043311 -4.06625270109031 10.9120809048193 -4.06625270109031
+ 14
+
+
+
+
+ 10.9133309053996 -4.0658360342522110.9141642392079 -4.06500270057601
+ 10.9141642392079 -4.06583603425221 10.9141642392079 -4.06500270057601 10.9133309053996 -4.06500270057601 10.9133309053996 -4.06583603425221 10.9141642392079 -4.06583603425221
+ 6
+
+
+
+
+ 10.9099975701667 -4.0646902004804510.9108309039749 -4.06375270006172
+ 10.9099975701667 -4.06375270006172 10.9099975701667 -4.06458603373791 10.9102059036187 -4.06469020048045 10.9103447927628 -4.06465547818892 10.9108309039749 -4.06416936689982 10.9108309039749 -4.06375270006172 10.9099975701667 -4.06375270006172
+ 22
+
+
+
+
+ 10.9124975715914 -4.0658360342522110.9133309053996 -4.06479436709095
+ 10.9133309053996 -4.06583603425221 10.9133309053996 -4.06500270057601 10.9131225719476 -4.06479436709095 10.9124975715914 -4.06510686731855 10.9124975715914 -4.06583603425221 10.9133309053996 -4.06583603425221
+ 3
+
+
+
+
+ 10.9103447927628 -4.0652110340610810.9118725712352 -4.06416936689982
+ 10.9114559043311 -4.06521103406108 10.9118725712352 -4.06479436709094 10.9118725712352 -4.06437770038488 10.9116642377832 -4.06416936689982 10.9108309039749 -4.06416936689982 10.9103447927628 -4.06465547818892 10.9114559043311 -4.06521103406108
+ 12
+
+
+
+
+ 10.9118725712352 -4.0651068673185510.9131225719476 -4.06375270006172
+ 10.9131225716835 -4.06375270006172 10.9118725712352 -4.06437770038488 10.9118725712352 -4.06479436709094 10.9124975715914 -4.06510686731855 10.9131225719476 -4.06479436709095 10.9131225719476 -4.06375270006172 10.9131225716835 -4.06375270006172
+ 8
+
+
+
+
+ 10.9141642392079 -4.0658360342522110.914580906112 -4.06458603360588
+ 10.914580906112 -4.06458603360588 10.9141642392079 -4.06500270057601 10.9141642392079 -4.06583603425221 10.914580906112 -4.06583603425221 10.914580906112 -4.06458603360588
+ 7
+
+
+
+
+ 10.9131225719476 -4.0650027005760110.914580906112 -4.06375270006172
+ 10.914580906112 -4.06375270006172 10.9131225719476 -4.06375270006172 10.9131225719476 -4.06479436709095 10.9133309053996 -4.06500270057601 10.9141642392079 -4.06500270057601 10.914580906112 -4.06458603360588 10.914580906112 -4.06375270006172
+ 9
+
+
+
+
+ 10.9108309039749 -4.0641693668998210.9116642377832 -4.06375270006172
+ 10.9108309039749 -4.06375270006172 10.9108309039749 -4.06416936689982 10.9116642377832 -4.06416936689982 10.9116642377832 -4.06375270006172 10.9108309039749 -4.06375270006172
+ 20
+
+
+
+
+ 10.9116642377832 -4.0643777003848810.9131225716835 -4.06375270006172
+ 10.9116642377832 -4.06375270006172 10.9116642377832 -4.06416936689982 10.9118725712352 -4.06437770038488 10.9131225716835 -4.06375270006172 10.9116642377832 -4.06375270006172
+ 15
+
+
+
+
+ 10.9095809032626 -4.0645860337379110.9099975701667 -4.06375270006172
+ 10.9095809032626 -4.06375270006172 10.9095809032626 -4.06458603373791 10.9099975701667 -4.06458603373791 10.9099975701667 -4.06375270006172 10.9095809032626 -4.06375270006172
+ 21
+
+
+
diff --git a/python/plugins/processing/tests/testdata/expected/voronoi_polygons_extent_clip.xsd b/python/plugins/processing/tests/testdata/expected/voronoi_polygons_extent_clip.xsd
new file mode 100644
index 00000000000..5aa196653ee
--- /dev/null
+++ b/python/plugins/processing/tests/testdata/expected/voronoi_polygons_extent_clip.xsd
@@ -0,0 +1,54 @@
+
+
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/python/plugins/processing/tests/testdata/qgis_algorithm_tests3.yaml b/python/plugins/processing/tests/testdata/qgis_algorithm_tests3.yaml
index d4671838d2e..932e2ec9c24 100644
--- a/python/plugins/processing/tests/testdata/qgis_algorithm_tests3.yaml
+++ b/python/plugins/processing/tests/testdata/qgis_algorithm_tests3.yaml
@@ -354,6 +354,25 @@ tests:
geometry:
precision: 2
+ - algorithm: native:voronoipolygons
+ name: Voronoi polygons, ensure filtering output to only polygon parts
+ params:
+ BUFFER: 0.0
+ COPY_ATTRIBUTES: true
+ INPUT:
+ name: custom/voronoi_points_extent_clip.json
+ type: vector
+ TOLERANCE: 0.0
+ results:
+ OUTPUT:
+ name: expected/voronoi_polygons_extent_clip.gml
+ type: vector
+ compare:
+ fields:
+ gml_id: skip
+ geometry:
+ precision: 2
+
- algorithm: native:explodelines
name: Explode lines
params:
diff --git a/src/analysis/processing/qgsalgorithmvoronoipolygons.cpp b/src/analysis/processing/qgsalgorithmvoronoipolygons.cpp
index 9e32f4621ac..723ef00a76b 100644
--- a/src/analysis/processing/qgsalgorithmvoronoipolygons.cpp
+++ b/src/analysis/processing/qgsalgorithmvoronoipolygons.cpp
@@ -168,7 +168,8 @@ QString QgsVoronoiPolygonsAlgorithm::voronoiWithAttributes( const QVariantMap &p
std::unique_ptr engine;
std::unique_ptr extentEngine( QgsGeometry::createGeometryEngine( clippingGeom.constGet() ) );
const QVector collection = voronoiDiagram.asGeometryCollection();
- for ( int i = 0; i < collection.length(); i++ )
+ int i = 0;
+ for ( const QgsGeometry &collectionPart : collection )
{
if ( feedback->isCanceled() )
{
@@ -176,21 +177,28 @@ QString QgsVoronoiPolygonsAlgorithm::voronoiWithAttributes( const QVariantMap &p
}
QgsFeature f;
f.setFields( fields );
- f.setGeometry( QgsGeometry( extentEngine->intersection( collection[i].constGet() ) ) );
- const QList intersected = index.intersects( collection[i].boundingBox() );
- engine.reset( QgsGeometry::createGeometryEngine( collection[i].constGet() ) );
- engine->prepareGeometry();
- for ( const QgsFeatureId id : intersected )
+
+ QgsGeometry voronoiClippedToExtent = QgsGeometry( extentEngine->intersection( collectionPart.constGet() ) );
+ voronoiClippedToExtent.convertGeometryCollectionToSubclass( Qgis::GeometryType::Polygon );
+ if ( !voronoiClippedToExtent.isEmpty() )
{
- if ( engine->intersects( index.geometry( id ).constGet() ) )
+ f.setGeometry( QgsGeometry( voronoiClippedToExtent.constGet()->simplifiedTypeRef()->clone() ) );
+ const QList intersected = index.intersects( collectionPart.boundingBox() );
+ engine.reset( QgsGeometry::createGeometryEngine( collectionPart.constGet() ) );
+ engine->prepareGeometry();
+ for ( const QgsFeatureId id : intersected )
{
- f.setAttributes( attributeCache.value( id ) );
- break;
+ if ( engine->intersects( index.geometry( id ).constGet() ) )
+ {
+ f.setAttributes( attributeCache.value( id ) );
+ break;
+ }
}
+ if ( !sink->addFeature( f, QgsFeatureSink::FastInsert ) )
+ throw QgsProcessingException( writeFeatureError( sink.get(), parameters, QStringLiteral( "OUTPUT" ) ) );
}
- if ( !sink->addFeature( f, QgsFeatureSink::FastInsert ) )
- throw QgsProcessingException( writeFeatureError( sink.get(), parameters, QStringLiteral( "OUTPUT" ) ) );
feedback->setProgress( 50 + i * step );
+ i++;
}
}