Skip to content
Permalink
Browse files

Merge pull request #42363 from nyalldawson/fix_42350

When running "point on surface" with "create point for each part" option enabled, discard incoming fid fields and regenerate
  • Loading branch information
nyalldawson committed Mar 23, 2021
1 parent cb93e3b commit c84f73da9896f289b1256734a31282b59a09bcf3
@@ -50,6 +50,14 @@ QString QgsPointOnSurfaceAlgorithm::outputName() const
return QObject::tr( "Point" );
}

QgsFeatureSink::SinkFlags QgsPointOnSurfaceAlgorithm::sinkFlags() const
{
if ( mAllParts )
return QgsProcessingFeatureBasedAlgorithm::sinkFlags() | QgsFeatureSink::RegeneratePrimaryKey;
else
return QgsProcessingFeatureBasedAlgorithm::sinkFlags();
}

QString QgsPointOnSurfaceAlgorithm::shortHelpString() const
{
return QObject::tr( "Returns a point guaranteed to lie on the surface of a geometry." );
@@ -86,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();

@@ -98,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;
@@ -115,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;
@@ -51,6 +51,7 @@ class QgsPointOnSurfaceAlgorithm : public QgsProcessingFeatureBasedAlgorithm
QString outputName() const override;
QgsProcessing::SourceType outputLayerType() const override { return QgsProcessing::TypeVectorPoint; }
QgsWkbTypes::Type outputWkbType( QgsWkbTypes::Type inputWkbType ) const override { Q_UNUSED( inputWkbType ) return QgsWkbTypes::Point; }
QgsFeatureSink::SinkFlags sinkFlags() const override;

bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;

0 comments on commit c84f73d

Please sign in to comment.