22 QString QgsMultiRingConstantBufferAlgorithm::name()
const 24 return QStringLiteral(
"multiringconstantbuffer" );
27 QString QgsMultiRingConstantBufferAlgorithm::displayName()
const 29 return QObject::tr(
"Multi-ring buffer (constant distance)" );
32 QStringList QgsMultiRingConstantBufferAlgorithm::tags()
const 34 return QObject::tr(
"buffer,grow,multiple,rings,distance,donut" ).split(
',' );
37 QString QgsMultiRingConstantBufferAlgorithm::group()
const 39 return QObject::tr(
"Vector geometry" );
42 QString QgsMultiRingConstantBufferAlgorithm::groupId()
const 44 return QStringLiteral(
"vectorgeometry" );
47 QString QgsMultiRingConstantBufferAlgorithm::outputName()
const 49 return QObject::tr(
"Multi-ring buffer (constant distance)" );
52 QString QgsMultiRingConstantBufferAlgorithm::shortHelpString()
const 54 return QObject::tr(
"This algorithm computes multi-ring ('donuts') buffer for all the features in an input layer, using a fixed or dynamic distance and rings number." );
57 QgsMultiRingConstantBufferAlgorithm *QgsMultiRingConstantBufferAlgorithm::createInstance()
const 59 return new QgsMultiRingConstantBufferAlgorithm();
62 void QgsMultiRingConstantBufferAlgorithm::initParameters(
const QVariantMap & )
64 std::unique_ptr< QgsProcessingParameterNumber> rings = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"RINGS" ),
67 rings->setIsDynamic(
true );
69 rings->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
70 addParameter( rings.release() );
72 std::unique_ptr< QgsProcessingParameterDistance > distance = qgis::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"DISTANCE" ),
73 QObject::tr(
"Distance between rings" ), 1, QStringLiteral(
"INPUT" ),
false, 0 );
74 distance->setIsDynamic(
true );
76 distance->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
77 addParameter( distance.release() );
82 mRingsNumber = parameterAsInt( parameters, QStringLiteral(
"RINGS" ), context );
84 if ( mDynamicRingsNumber )
85 mRingsNumberProperty = parameters.value( QStringLiteral(
"RINGS" ) ).value<
QgsProperty >();
87 mDistance = parameterAsDouble( parameters, QStringLiteral(
"DISTANCE" ), context );
89 if ( mDynamicDistance )
90 mDistanceProperty = parameters.value( QStringLiteral(
"DISTANCE" ) ).value<
QgsProperty >();
95 QgsFields QgsMultiRingConstantBufferAlgorithm::outputFields(
const QgsFields &inputFields )
const 98 fields.
append(
QgsField( QStringLiteral(
"ringId" ), QVariant::Int, QString(), 10, 0 ) );
99 fields.
append(
QgsField( QStringLiteral(
"distance" ), QVariant::Double, QString(), 20, 6 ) );
105 double currentDistance = 0;
108 int rings = mRingsNumber;
109 if ( mDynamicRingsNumber )
112 double distance = mDistance;
113 if ( mDynamicDistance )
118 for (
int i = 1; i <= rings; ++i )
121 currentDistance = i * distance;
122 outputGeometry = feature.
geometry().
buffer( currentDistance, 40 );
123 if ( !outputGeometry )
125 feedback->
reportError( QObject::tr(
"Error calculating buffer for feature %1" ).arg( feature.
id() ) );
137 previousGeometry = outputGeometry;
139 attrs << i << currentDistance;
141 outputs.append( out );
Positive integer values (including 0)
Base class for providing feedback from a processing algorithm.
QList< QgsFeature > QgsFeatureList
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
QgsGeometry buffer(double distance, int segments) const
Returns a buffer region around this geometry having the given width and with a specified number of se...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Positive double value (including 0)
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Append a field. The field must have unique name, otherwise it is rejected (returns false) ...
Encapsulate a field in an attribute table or data source.
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.
double valueAsDouble(const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property and interprets it as a double.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
QgsGeometry symDifference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other...
Contains information about the context in which a processing algorithm is executed.
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...