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 QString QgsCentroidAlgorithm::shortHelpString()
const 55 return QObject::tr(
"This algorithm creates a new point layer, with points representing the centroid of the geometries in an input layer.\n\n" 56 "The attributes associated to each point in the output layer are the same ones associated to the original features." );
59 QgsCentroidAlgorithm *QgsCentroidAlgorithm::createInstance()
const 61 return new QgsCentroidAlgorithm();
64 void QgsCentroidAlgorithm::initParameters(
const QVariantMap & )
66 std::unique_ptr< QgsProcessingParameterBoolean> allParts = qgis::make_unique< QgsProcessingParameterBoolean >(
67 QStringLiteral(
"ALL_PARTS" ),
68 QObject::tr(
"Create point on surface for each part" ),
70 allParts->setIsDynamic(
true );
72 allParts->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
73 addParameter( allParts.release() );
78 mAllParts = parameterAsBool( parameters, QStringLiteral(
"ALL_PARTS" ), context );
80 if ( mDynamicAllParts )
81 mAllPartsProperty = parameters.value( QStringLiteral(
"ALL_PARTS" ) ).value<
QgsProperty >();
94 bool allParts = mAllParts;
95 if ( mDynamicAllParts )
96 allParts = mAllPartsProperty.valueAsBool( context.
expressionContext(), allParts );
102 for (
int i = 0; i < geomCollection->
partCount(); ++i )
106 if ( !outputGeometry )
108 feedback->
pushInfo( QObject::tr(
"Error calculating centroid for feature %1 part %2: %3" ).arg( feature.
id() ).arg( i ).arg( outputGeometry.lastError() ) );
117 if ( !outputGeometry )
119 feedback->
pushInfo( QObject::tr(
"Error calculating centroid for feature %1: %2" ).arg( feature.
id() ).arg( outputGeometry.
lastError() ) );
Base class for providing feedback from a processing algorithm.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QList< QgsFeature > QgsFeatureList
A geometry is the spatial representation of a feature.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
A store for object properties.
QgsExpressionContext & expressionContext()
Returns the expression context.
Definition for a property.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
int partCount() const override
Returns count of parts contained in the geometry.
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Contains information about the context in which a processing algorithm is executed.
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...
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.