24 QString QgsBufferAlgorithm::name()
const 26 return QStringLiteral(
"buffer" );
29 QString QgsBufferAlgorithm::displayName()
const 31 return QObject::tr(
"Buffer" );
34 QStringList QgsBufferAlgorithm::tags()
const 36 return QObject::tr(
"buffer,grow,fixed,variable,distance" ).split(
',' );
39 QString QgsBufferAlgorithm::group()
const 41 return QObject::tr(
"Vector geometry" );
44 QString QgsBufferAlgorithm::groupId()
const 46 return QStringLiteral(
"vectorgeometry" );
49 void QgsBufferAlgorithm::initAlgorithm(
const QVariantMap & )
53 auto bufferParam = qgis::make_unique < QgsProcessingParameterDistance >( QStringLiteral(
"DISTANCE" ), QObject::tr(
"Distance" ), 10, QStringLiteral(
"INPUT" ) );
54 bufferParam->setIsDynamic(
true );
56 bufferParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
57 addParameter( bufferParam.release() );
60 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"END_CAP_STYLE" ), QObject::tr(
"End cap style" ), QStringList() << QObject::tr(
"Round" ) << QObject::tr(
"Flat" ) << QObject::tr(
"Square" ),
false, 0 ) );
61 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"JOIN_STYLE" ), QObject::tr(
"Join style" ), QStringList() << QObject::tr(
"Round" ) << QObject::tr(
"Miter" ) << QObject::tr(
"Bevel" ),
false, 0 ) );
68 QString QgsBufferAlgorithm::shortHelpString()
const 70 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" 71 "The segments parameter controls the number of line segments to use to approximate a quarter circle when creating rounded offsets.\n\n" 72 "The end cap style parameter controls how line endings are handled in the buffer.\n\n" 73 "The join style parameter specifies whether round, miter or beveled joins should be used when offsetting corners in a line.\n\n" 74 "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." );
77 QgsBufferAlgorithm *QgsBufferAlgorithm::createInstance()
const 79 return new QgsBufferAlgorithm();
84 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
89 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, source->fields(),
QgsWkbTypes::MultiPolygon, source->sourceCrs() ) );
94 bool dissolve = parameterAsBool( parameters, QStringLiteral(
"DISSOLVE" ), context );
95 int segments = parameterAsInt( parameters, QStringLiteral(
"SEGMENTS" ), context );
98 double miterLimit = parameterAsDouble( parameters, QStringLiteral(
"MITER_LIMIT" ), context );
99 double bufferDistance = parameterAsDouble( parameters, QStringLiteral(
"DISTANCE" ), context );
101 QgsExpressionContext expressionContext = createExpressionContext( parameters, context, source.get() );
105 bufferProperty = parameters.
value( QStringLiteral(
"DISTANCE" ) ).value<
QgsProperty >();
108 long count = source->featureCount();
114 double step = count > 0 ? 100.0 / count : 1;
117 QVector< QgsGeometry > bufferedGeometriesForDissolve;
126 if ( dissolveAttrs.isEmpty() )
132 double distance = bufferDistance;
136 distance = bufferProperty.valueAsDouble( expressionContext, bufferDistance );
140 if ( outputGeometry.
isNull() )
145 bufferedGeometriesForDissolve << outputGeometry;
171 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
175 QgsProcessingAlgorithm::Flags QgsBufferAlgorithm::flags()
const 182 bool QgsBufferAlgorithm::supportInPlaceEdit(
const QgsMapLayer *layer )
const 188 return vlayer->
wkbType() == QgsWkbTypes::Type::Polygon || vlayer->
wkbType() == QgsWkbTypes::Type::MultiPolygon;
A boolean parameter for processing algorithms.
Wrapper for iterator of features from vector data provider or vector layer.
bool isCanceled() const
Tells whether the operation has been canceled already.
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
Base class for all map layer types.
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...
bool isNull() const
Returns true if the geometry is null (ie, contains no underlying geometry accessible via geometry() )...
QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
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.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
EndCapStyle
End cap styles for buffers.
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...
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...
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
This class wraps a request for features to a vector layer (or directly its vector data provider)...
Custom exception class for processing related exceptions.
A store for object properties.
Double value (including negative values)
A numeric parameter for processing algorithms.
Definition for a property.
Algorithm supports in-place editing.
virtual Flags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users...
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...
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
An input feature source (such as vector layers) parameter for processing algorithms.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
bool nextFeature(QgsFeature &f)
JoinStyle
Join styles for buffers.
Represents a vector layer which manages a vector based data sets.
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...