23 QString QgsCentroidAlgorithm::name()
const
25 return QStringLiteral(
"centroids" );
28 QString QgsCentroidAlgorithm::displayName()
const
30 return QObject::tr(
"Centroids" );
33 QStringList QgsCentroidAlgorithm::tags()
const
35 return QObject::tr(
"centroid,center,average,point,middle" ).split(
',' );
38 QString QgsCentroidAlgorithm::group()
const
40 return QObject::tr(
"Vector geometry" );
43 QString QgsCentroidAlgorithm::groupId()
const
45 return QStringLiteral(
"vectorgeometry" );
48 QString QgsCentroidAlgorithm::outputName()
const
50 return QObject::tr(
"Centroids" );
53 QgsFeatureSink::SinkFlags QgsCentroidAlgorithm::sinkFlags()
const
61 QString QgsCentroidAlgorithm::shortHelpString()
const
63 return QObject::tr(
"This algorithm creates a new point layer, with points representing the centroid of the geometries in an input layer.\n\n"
64 "The attributes associated to each point in the output layer are the same ones associated to the original features." );
67 QgsCentroidAlgorithm *QgsCentroidAlgorithm::createInstance()
const
69 return new QgsCentroidAlgorithm();
72 void QgsCentroidAlgorithm::initParameters(
const QVariantMap & )
74 std::unique_ptr< QgsProcessingParameterBoolean> allParts = std::make_unique< QgsProcessingParameterBoolean >(
75 QStringLiteral(
"ALL_PARTS" ),
76 QObject::tr(
"Create centroid for each part" ),
78 allParts->setIsDynamic(
true );
80 allParts->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
81 addParameter( allParts.release() );
86 mAllParts = parameterAsBoolean( parameters, QStringLiteral(
"ALL_PARTS" ), context );
88 if ( mDynamicAllParts )
89 mAllPartsProperty = parameters.value( QStringLiteral(
"ALL_PARTS" ) ).value<
QgsProperty >();
102 bool allParts = mAllParts;
103 if ( mDynamicAllParts )
104 allParts = mAllPartsProperty.valueAsBool( context.
expressionContext(), allParts );
110 const int partCount = geomCollection->
partCount();
111 list.reserve( partCount );
112 for (
int i = 0; i < partCount; ++i )
116 if ( outputGeometry.
isNull() )
118 feedback->
reportError( QObject::tr(
"Error calculating centroid for feature %1 part %2: %3" ).arg( feature.
id() ).arg( i ).arg( outputGeometry.
lastError() ) );
127 if ( outputGeometry.
isNull() )
129 feedback->
reportError( QObject::tr(
"Error calculating centroid for feature %1: %2" ).arg( feature.
id() ).arg( outputGeometry.
lastError() ) );