23 QString QgsMultiRingConstantBufferAlgorithm::name()
const 25 return QStringLiteral(
"multiringconstantbuffer" );
28 QString QgsMultiRingConstantBufferAlgorithm::displayName()
const 30 return QObject::tr(
"Multi-ring buffer (constant distance)" );
33 QStringList QgsMultiRingConstantBufferAlgorithm::tags()
const 35 return QObject::tr(
"buffer,grow,multiple,rings,distance,donut" ).split(
',' );
38 QString QgsMultiRingConstantBufferAlgorithm::group()
const 40 return QObject::tr(
"Vector geometry" );
43 QString QgsMultiRingConstantBufferAlgorithm::groupId()
const 45 return QStringLiteral(
"vectorgeometry" );
48 QString QgsMultiRingConstantBufferAlgorithm::outputName()
const 50 return QObject::tr(
"Multi-ring buffer (constant distance)" );
53 QString 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." );
58 QgsMultiRingConstantBufferAlgorithm *QgsMultiRingConstantBufferAlgorithm::createInstance()
const 60 return new QgsMultiRingConstantBufferAlgorithm();
63 void QgsMultiRingConstantBufferAlgorithm::initParameters(
const QVariantMap & )
65 std::unique_ptr< QgsProcessingParameterNumber> rings = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"RINGS" ),
68 rings->setIsDynamic(
true );
70 rings->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
71 addParameter( rings.release() );
73 std::unique_ptr< QgsProcessingParameterDistance > distance = qgis::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"DISTANCE" ),
74 QObject::tr(
"Distance between rings" ), 1, QStringLiteral(
"INPUT" ), false );
75 distance->setIsDynamic(
true );
77 distance->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
78 addParameter( distance.release() );
81 bool QgsMultiRingConstantBufferAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const 90 return layer->
wkbType() == QgsWkbTypes::Type::Polygon || layer->
wkbType() == QgsWkbTypes::Type::MultiPolygon;
95 mRingsNumber = parameterAsInt( parameters, QStringLiteral(
"RINGS" ), context );
97 if ( mDynamicRingsNumber )
98 mRingsNumberProperty = parameters.value( QStringLiteral(
"RINGS" ) ).value<
QgsProperty >();
100 mDistance = parameterAsDouble( parameters, QStringLiteral(
"DISTANCE" ), context );
102 if ( mDynamicDistance )
103 mDistanceProperty = parameters.value( QStringLiteral(
"DISTANCE" ) ).value<
QgsProperty >();
108 QgsFields QgsMultiRingConstantBufferAlgorithm::outputFields(
const QgsFields &inputFields )
const 111 fields.
append(
QgsField( QStringLiteral(
"ringId" ), QVariant::Int, QString(), 10, 0 ) );
112 fields.
append(
QgsField( QStringLiteral(
"distance" ), QVariant::Double, QString(), 20, 6 ) );
121 QgsFeatureSink::SinkFlags QgsMultiRingConstantBufferAlgorithm::sinkFlags()
const 128 double currentDistance = 0;
131 int rings = mRingsNumber;
132 if ( mDynamicRingsNumber )
135 double distance = mDistance;
136 if ( mDynamicDistance )
146 for (
int i = 1; i <= rings; ++i )
149 currentDistance = i * distance;
150 outputGeometry = feature.
geometry().
buffer( currentDistance, 40 );
152 if ( outputGeometry.
isNull() )
154 feedback->
reportError( QObject::tr(
"Error calculating buffer for feature %1" ).arg( feature.
id() ) );
158 if ( distance < 0.0 )
170 previousGeometry = outputGeometry;
172 attrs << i << currentDistance;
174 outputs.append( out );
178 if ( distance < 0.0 )
185 outputs.append( out );
Base class for all map layer types.
Positive integer values (including 0)
Base class for providing feedback from a processing algorithm.
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
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)
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false) ...
Encapsulate a field in an attribute table or data source.
A store for object properties.
QgsExpressionContext & expressionContext()
Returns the expression context.
Definition for a property.
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
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.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool supportInPlaceEdit(const QgsMapLayer *layer) const override
Checks whether this algorithm supports in-place editing on the given layer Default implementation for...
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
QgsGeometry symDifference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other...
Represents a vector layer which manages a vector based data sets.
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...