Skip to content

Commit c20717a

Browse files
committed
Protect against centroid failures
1 parent ce541cb commit c20717a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/analysis/processing/qgsalgorithmkmeansclustering.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,20 @@ QVariantMap QgsKMeansClusteringAlgorithm::processAlgorithm( const QVariantMap &p
109109
if ( !feat.hasGeometry() )
110110
continue;
111111

112-
n++;
113-
114112
QgsPointXY point;
115113
if ( QgsWkbTypes::flatType( feat.geometry().wkbType() ) == QgsWkbTypes::Point )
116114
point = QgsPointXY( *qgsgeometry_cast< const QgsPoint * >( feat.geometry().constGet() ) );
117115
else
118116
{
119117
QgsGeometry centroid = feat.geometry().centroid();
118+
if ( !centroid )
119+
continue; // centroid failed, e.g. empty linestring
120+
120121
point = QgsPointXY( *qgsgeometry_cast< const QgsPoint * >( centroid.constGet() ) );
121122
}
122123

124+
n++;
125+
123126
idToObj.insert( feat.id(), clusterFeatures.size() );
124127
clusterFeatures.emplace_back( Feature( point ) );
125128
}

0 commit comments

Comments
 (0)