22 QString QgsBufferAlgorithm::name()
const 24 return QStringLiteral(
"buffer" );
27 QString QgsBufferAlgorithm::displayName()
const 29 return QObject::tr(
"Buffer" );
32 QStringList QgsBufferAlgorithm::tags()
const 34 return QObject::tr(
"buffer,grow,fixed,variable,distance" ).split(
',' );
37 QString QgsBufferAlgorithm::group()
const 39 return QObject::tr(
"Vector geometry" );
42 QString QgsBufferAlgorithm::groupId()
const 44 return QStringLiteral(
"vectorgeometry" );
47 void QgsBufferAlgorithm::initAlgorithm(
const QVariantMap & )
52 bufferParam->setIsDynamic(
true );
54 bufferParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
55 addParameter( bufferParam.release() );
58 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"END_CAP_STYLE" ), QObject::tr(
"End cap style" ), QStringList() << QObject::tr(
"Round" ) << QObject::tr(
"Flat" ) << QObject::tr(
"Square" ),
false ) );
59 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"JOIN_STYLE" ), QObject::tr(
"Join style" ), QStringList() << QObject::tr(
"Round" ) << QObject::tr(
"Miter" ) << QObject::tr(
"Bevel" ),
false ) );
60 addParameter(
new QgsProcessingParameterNumber( QStringLiteral(
"MITER_LIMIT" ), QObject::tr(
"Miter limit" ), QgsProcessingParameterNumber::Double, 2,
false, 1 ) );
66 QString QgsBufferAlgorithm::shortHelpString()
const 68 return QObject::tr(
"This algorithm computes a buffer area for all the features in an input layer, using a fixed or dynamic distance.\n\n" 69 "The segments parameter controls the number of line segments to use to approximate a quarter circle when creating rounded offsets.\n\n" 70 "The end cap style parameter controls how line endings are handled in the buffer.\n\n" 71 "The join style parameter specifies whether round, miter or beveled joins should be used when offsetting corners in a line.\n\n" 72 "The miter limit parameter is only applicable for miter join styles, and controls the maximum distance from the offset curve to use when creating a mitered join." );
75 QgsBufferAlgorithm *QgsBufferAlgorithm::createInstance()
const 77 return new QgsBufferAlgorithm();
82 std::unique_ptr< QgsFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
87 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, source->fields(),
QgsWkbTypes::Polygon, source->sourceCrs() ) );
92 bool dissolve = parameterAsBool( parameters, QStringLiteral(
"DISSOLVE" ), context );
93 int segments = parameterAsInt( parameters, QStringLiteral(
"SEGMENTS" ), context );
96 double miterLimit = parameterAsDouble( parameters, QStringLiteral(
"MITER_LIMIT" ), context );
97 double bufferDistance = parameterAsDouble( parameters, QStringLiteral(
"DISTANCE" ), context );
99 QgsExpressionContext expressionContext = createExpressionContext( parameters, context, dynamic_cast< QgsProcessingFeatureSource * >( source.get() ) );
103 bufferProperty = parameters.
value( QStringLiteral(
"DISTANCE" ) ).value<
QgsProperty >();
106 long count = source->featureCount();
111 double step = count > 0 ? 100.0 / count : 1;
114 QVector< QgsGeometry > bufferedGeometriesForDissolve;
123 if ( dissolveAttrs.isEmpty() )
129 double distance = bufferDistance;
133 distance = bufferProperty.
valueAsDouble( expressionContext, bufferDistance );
137 if ( !outputGeometry )
142 bufferedGeometriesForDissolve << outputGeometry;
164 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
A boolean parameter for processing algorithms.
Wrapper for iterator of features from vector data provider or vector layer.
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
Base class for providing feedback from a processing algorithm.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
void setProgress(double progress)
Sets the current progress for the feedback object.
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...
QVariant value(const QgsExpressionContext &context, const QVariant &defaultValue=QVariant(), bool *ok=nullptr) const
Calculates the current value of the property, including any transforms which are set for the property...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
EndCapStyle
End cap styles for buffers.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning)
add a message to the instance (and create it if necessary)
A feature sink output for processing algorithms.
An enum based parameter for processing algorithms, allowing for selection from predefined values...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Custom exception class for processing related exceptions.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
A store for object properties.
Double value (including negative values)
A numeric parameter for processing algorithms.
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.
bool isCanceled() const
Tells whether the operation has been canceled already.
An input feature source (such as vector layers) parameter for processing algorithms.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool nextFeature(QgsFeature &f)
JoinStyle
Join styles for buffers.
Contains information about the context in which a processing algorithm is executed.
static QgsGeometry unaryUnion(const QVector< QgsGeometry > &geometries)
Compute the unary union on a list of geometries.
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...