Skip to content
Permalink
Browse files

Protect against centroid failures

  • Loading branch information
nyalldawson committed Jun 26, 2018
1 parent ce541cb commit c20717a03c29ddd8eb04011dd813d0361fe34e03
Showing with 5 additions and 2 deletions.
  1. +5 −2 src/analysis/processing/qgsalgorithmkmeansclustering.cpp
@@ -109,17 +109,20 @@ QVariantMap QgsKMeansClusteringAlgorithm::processAlgorithm( const QVariantMap &p
if ( !feat.hasGeometry() )
continue;

n++;

QgsPointXY point;
if ( QgsWkbTypes::flatType( feat.geometry().wkbType() ) == QgsWkbTypes::Point )
point = QgsPointXY( *qgsgeometry_cast< const QgsPoint * >( feat.geometry().constGet() ) );
else
{
QgsGeometry centroid = feat.geometry().centroid();
if ( !centroid )
continue; // centroid failed, e.g. empty linestring

point = QgsPointXY( *qgsgeometry_cast< const QgsPoint * >( centroid.constGet() ) );
}

n++;

idToObj.insert( feat.id(), clusterFeatures.size() );
clusterFeatures.emplace_back( Feature( point ) );
}

0 comments on commit c20717a

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