23QString QgsMultiRingConstantBufferAlgorithm::name()
const
25 return QStringLiteral(
"multiringconstantbuffer" );
28QString QgsMultiRingConstantBufferAlgorithm::displayName()
const
30 return QObject::tr(
"Multi-ring buffer (constant distance)" );
33QStringList QgsMultiRingConstantBufferAlgorithm::tags()
const
35 return QObject::tr(
"buffer,grow,multiple,rings,distance,donut" ).split(
',' );
38QString QgsMultiRingConstantBufferAlgorithm::group()
const
40 return QObject::tr(
"Vector geometry" );
43QString QgsMultiRingConstantBufferAlgorithm::groupId()
const
45 return QStringLiteral(
"vectorgeometry" );
48QString QgsMultiRingConstantBufferAlgorithm::outputName()
const
50 return QObject::tr(
"Multi-ring buffer (constant distance)" );
53QString QgsMultiRingConstantBufferAlgorithm::shortHelpString()
const
55 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." );
63QgsMultiRingConstantBufferAlgorithm *QgsMultiRingConstantBufferAlgorithm::createInstance()
const
65 return new QgsMultiRingConstantBufferAlgorithm();
68void QgsMultiRingConstantBufferAlgorithm::initParameters(
const QVariantMap & )
70 std::unique_ptr<QgsProcessingParameterNumber> rings = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"RINGS" ), QObject::tr(
"Number of rings" ),
Qgis::ProcessingNumberParameterType::Integer, 1,
false, 0 );
71 rings->setIsDynamic(
true );
73 rings->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
74 addParameter( rings.release() );
76 std::unique_ptr<QgsProcessingParameterDistance> distance = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral(
"DISTANCE" ), QObject::tr(
"Distance between rings" ), 1, QStringLiteral(
"INPUT" ),
false );
77 distance->setIsDynamic(
true );
79 distance->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
80 addParameter( distance.release() );
83bool QgsMultiRingConstantBufferAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const
85 const QgsVectorLayer *layer = qobject_cast<const QgsVectorLayer *>( l );
97 mRingsNumber = parameterAsInt( parameters, QStringLiteral(
"RINGS" ), context );
99 if ( mDynamicRingsNumber )
100 mRingsNumberProperty = parameters.value( QStringLiteral(
"RINGS" ) ).value<
QgsProperty>();
102 mDistance = parameterAsDouble( parameters, QStringLiteral(
"DISTANCE" ), context );
104 if ( mDynamicDistance )
105 mDistanceProperty = parameters.value( QStringLiteral(
"DISTANCE" ) ).value<
QgsProperty>();
110QgsFields QgsMultiRingConstantBufferAlgorithm::outputFields(
const QgsFields &inputFields )
const
113 fields.
append(
QgsField( QStringLiteral(
"ringId" ), QMetaType::Type::Int, QString(), 10, 0 ) );
114 fields.
append(
QgsField( QStringLiteral(
"distance" ), QMetaType::Type::Double, QString(), 20, 6 ) );
130 double currentDistance = 0;
133 int rings = mRingsNumber;
134 if ( mDynamicRingsNumber )
137 double distance = mDistance;
138 if ( mDynamicDistance )
148 for (
int i = 1; i <= rings; ++i )
151 currentDistance = i * distance;
152 outputGeometry = feature.
geometry().
buffer( currentDistance, 40 );
154 if ( outputGeometry.
isNull() )
156 feedback->
reportError( QObject::tr(
"Error calculating buffer for feature %1" ).arg( feature.
id() ) );
160 if ( distance < 0.0 )
172 previousGeometry = outputGeometry;
174 attrs << i << currentDistance;
176 outputs.append( out );
180 if ( distance < 0.0 )
187 outputs.append( out );
@ RegeneratesPrimaryKey
Algorithm always drops any existing primary keys or FID values and regenerates them in outputs.
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
@ MultiPolygon
MultiPolygon.
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
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...
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
A geometry is the spatial representation of a feature.
QgsGeometry symDifference(const QgsGeometry &geometry, const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Returns a geometry representing the points making up this geometry that do not make up other.
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...
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
Base class for all map layer types.
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
bool supportInPlaceEdit(const QgsMapLayer *layer) const override
Checks whether this algorithm supports in-place editing on the given layer Default implementation for...
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.
@ IntegerPositive
Positive integer values (including 0)
@ DoublePositive
Positive double value (including 0)
A store for object properties.
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.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE Qgis::WkbType wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
QList< QgsFeature > QgsFeatureList