24QString QgsCentroidAlgorithm::name()
const
26 return QStringLiteral(
"centroids" );
29QString QgsCentroidAlgorithm::displayName()
const
31 return QObject::tr(
"Centroids" );
34QStringList QgsCentroidAlgorithm::tags()
const
36 return QObject::tr(
"centroid,center,average,point,middle" ).split(
',' );
39QString QgsCentroidAlgorithm::group()
const
41 return QObject::tr(
"Vector geometry" );
44QString QgsCentroidAlgorithm::groupId()
const
46 return QStringLiteral(
"vectorgeometry" );
49QString QgsCentroidAlgorithm::outputName()
const
51 return QObject::tr(
"Centroids" );
62QString QgsCentroidAlgorithm::shortHelpString()
const
64 return QObject::tr(
"This algorithm creates a new point layer with points representing the centroid of the geometries in an input layer.\n\n"
65 "The attributes associated to each point in the output layer are the same ones associated to the original features." );
68QString QgsCentroidAlgorithm::shortDescription()
const
70 return QObject::tr(
"Creates a new point layer with points representing the centroid of the geometries in an input layer." );
78QgsCentroidAlgorithm *QgsCentroidAlgorithm::createInstance()
const
80 return new QgsCentroidAlgorithm();
83void QgsCentroidAlgorithm::initParameters(
const QVariantMap & )
85 auto allParts = std::make_unique<QgsProcessingParameterBoolean>(
86 QStringLiteral(
"ALL_PARTS" ),
87 QObject::tr(
"Create centroid for each part" ),
90 allParts->setIsDynamic(
true );
92 allParts->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
93 addParameter( allParts.release() );
98 mAllParts = parameterAsBoolean( parameters, QStringLiteral(
"ALL_PARTS" ), context );
100 if ( mDynamicAllParts )
101 mAllPartsProperty = parameters.value( QStringLiteral(
"ALL_PARTS" ) ).value<
QgsProperty>();
114 bool allParts = mAllParts;
115 if ( mDynamicAllParts )
116 allParts = mAllPartsProperty.valueAsBool( context.
expressionContext(), allParts );
122 const int partCount = geomCollection->
partCount();
123 list.reserve( partCount );
124 for (
int i = 0; i < partCount; ++i )
128 if ( outputGeometry.
isNull() )
130 feedback->
reportError( QObject::tr(
"Error calculating centroid for feature %1 part %2: %3" ).arg( feature.
id() ).arg( i ).arg( outputGeometry.
lastError() ) );
139 if ( outputGeometry.
isNull() )
141 feedback->
reportError( QObject::tr(
"Error calculating centroid for feature %1: %2" ).arg( feature.
id() ).arg( outputGeometry.
lastError() ) );
@ RegeneratesPrimaryKeyInSomeScenarios
Algorithm may drop the existing primary keys or FID values in some scenarios, depending on algorithm ...
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
QFlags< SinkFlag > SinkFlags
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
int partCount() const override
Returns count of parts contained in the geometry.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
A geometry is the spatial representation of a feature.
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
virtual QgsFeatureSink::SinkFlags sinkFlags() const
Returns the feature sink flags to be used for the output.
Base class for providing feedback from a processing algorithm.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
static bool isDynamic(const QVariantMap ¶meters, const QString &name)
Returns true if the parameter with matching name is a dynamic parameter, and must be evaluated once f...
Definition for a property.
A store for object properties.
QList< QgsFeature > QgsFeatureList