@@ -50,6 +50,14 @@ QString QgsPointOnSurfaceAlgorithm::outputName() const
50
50
return QObject::tr ( " Point" );
51
51
}
52
52
53
+ QgsFeatureSink::SinkFlags QgsPointOnSurfaceAlgorithm::sinkFlags () const
54
+ {
55
+ if ( mAllParts )
56
+ return QgsProcessingFeatureBasedAlgorithm::sinkFlags () | QgsFeatureSink::RegeneratePrimaryKey;
57
+ else
58
+ return QgsProcessingFeatureBasedAlgorithm::sinkFlags ();
59
+ }
60
+
53
61
QString QgsPointOnSurfaceAlgorithm::shortHelpString () const
54
62
{
55
63
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,
86
94
{
87
95
QgsFeatureList list;
88
96
QgsFeature feature = f;
89
- if ( feature.hasGeometry () )
97
+ if ( feature.hasGeometry () && !feature. geometry (). isEmpty () )
90
98
{
91
99
QgsGeometry geom = feature.geometry ();
92
100
@@ -98,13 +106,15 @@ QgsFeatureList QgsPointOnSurfaceAlgorithm::processFeature( const QgsFeature &f,
98
106
{
99
107
const QgsGeometryCollection *geomCollection = static_cast <const QgsGeometryCollection *>( geom.constGet () );
100
108
101
- for ( int i = 0 ; i < geomCollection->partCount (); ++i )
109
+ const int partCount = geomCollection->partCount ();
110
+ list.reserve ( partCount );
111
+ for ( int i = 0 ; i < partCount; ++i )
102
112
{
103
113
QgsGeometry partGeometry ( geomCollection->geometryN ( i )->clone () );
104
114
QgsGeometry outputGeometry = partGeometry.pointOnSurface ();
105
115
if ( outputGeometry.isNull () )
106
116
{
107
- feedback->pushInfo ( QObject::tr ( " Error calculating point on surface for feature %1 part %2: %3" ).arg ( feature.id () ).arg ( i ).arg ( outputGeometry.lastError () ) );
117
+ feedback->reportError ( QObject::tr ( " Error calculating point on surface for feature %1 part %2: %3" ).arg ( feature.id () ).arg ( i ).arg ( outputGeometry.lastError () ) );
108
118
}
109
119
feature.setGeometry ( outputGeometry );
110
120
list << feature;
@@ -115,7 +125,7 @@ QgsFeatureList QgsPointOnSurfaceAlgorithm::processFeature( const QgsFeature &f,
115
125
QgsGeometry outputGeometry = feature.geometry ().pointOnSurface ();
116
126
if ( outputGeometry.isNull () )
117
127
{
118
- feedback->pushInfo ( QObject::tr ( " Error calculating point on surface for feature %1: %2" ).arg ( feature.id () ).arg ( outputGeometry.lastError () ) );
128
+ feedback->reportError ( QObject::tr ( " Error calculating point on surface for feature %1: %2" ).arg ( feature.id () ).arg ( outputGeometry.lastError () ) );
119
129
}
120
130
feature.setGeometry ( outputGeometry );
121
131
list << feature;
0 commit comments