Skip to content

Commit

Permalink
Better error reporting in Point on Surface
Browse files Browse the repository at this point in the history
(cherry picked from commit 954ad35)
  • Loading branch information
nyalldawson committed Apr 17, 2021
1 parent 5f35ded commit 99892f1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/analysis/processing/qgsalgorithmpointonsurface.cpp
Expand Up @@ -94,7 +94,7 @@ QgsFeatureList QgsPointOnSurfaceAlgorithm::processFeature( const QgsFeature &f,
{
QgsFeatureList list;
QgsFeature feature = f;
if ( feature.hasGeometry() )
if ( feature.hasGeometry() && !feature.geometry().isEmpty() )
{
QgsGeometry geom = feature.geometry();

Expand All @@ -106,13 +106,15 @@ QgsFeatureList QgsPointOnSurfaceAlgorithm::processFeature( const QgsFeature &f,
{
const QgsGeometryCollection *geomCollection = static_cast<const QgsGeometryCollection *>( geom.constGet() );

for ( int i = 0; i < geomCollection->partCount(); ++i )
const int partCount = geomCollection->partCount();
list.reserve( partCount );
for ( int i = 0; i < partCount; ++i )
{
QgsGeometry partGeometry( geomCollection->geometryN( i )->clone() );
QgsGeometry outputGeometry = partGeometry.pointOnSurface();
if ( outputGeometry.isNull() )
{
feedback->pushInfo( QObject::tr( "Error calculating point on surface for feature %1 part %2: %3" ).arg( feature.id() ).arg( i ).arg( outputGeometry.lastError() ) );
feedback->reportError( QObject::tr( "Error calculating point on surface for feature %1 part %2: %3" ).arg( feature.id() ).arg( i ).arg( outputGeometry.lastError() ) );
}
feature.setGeometry( outputGeometry );
list << feature;
Expand All @@ -123,7 +125,7 @@ QgsFeatureList QgsPointOnSurfaceAlgorithm::processFeature( const QgsFeature &f,
QgsGeometry outputGeometry = feature.geometry().pointOnSurface();
if ( outputGeometry.isNull() )
{
feedback->pushInfo( QObject::tr( "Error calculating point on surface for feature %1: %2" ).arg( feature.id() ).arg( outputGeometry.lastError() ) );
feedback->reportError( QObject::tr( "Error calculating point on surface for feature %1: %2" ).arg( feature.id() ).arg( outputGeometry.lastError() ) );
}
feature.setGeometry( outputGeometry );
list << feature;
Expand Down

0 comments on commit 99892f1

Please sign in to comment.