23QString QgsBufferAlgorithm::name()
const
25 return QStringLiteral(
"buffer" );
28QString QgsBufferAlgorithm::displayName()
const
30 return QObject::tr(
"Buffer" );
33QStringList QgsBufferAlgorithm::tags()
const
35 return QObject::tr(
"buffer,grow,fixed,variable,distance" ).split(
',' );
38QString QgsBufferAlgorithm::group()
const
40 return QObject::tr(
"Vector geometry" );
43QString QgsBufferAlgorithm::groupId()
const
45 return QStringLiteral(
"vectorgeometry" );
48void QgsBufferAlgorithm::initAlgorithm(
const QVariantMap & )
52 auto bufferParam = std::make_unique < QgsProcessingParameterDistance >( QStringLiteral(
"DISTANCE" ), QObject::tr(
"Distance" ), 10, QStringLiteral(
"INPUT" ) );
53 bufferParam->setIsDynamic(
true );
55 bufferParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
56 addParameter( bufferParam.release() );
58 segmentParam->setHelp( QObject::tr(
"The segments parameter controls the number of line segments to use to approximate a quarter circle when creating rounded offsets." ) );
59 addParameter( segmentParam.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 ) );
66 auto keepDisjointParam = std::make_unique < QgsProcessingParameterBoolean >( QStringLiteral(
"SEPARATE_DISJOINT" ), QObject::tr(
"Keep disjoint results separate" ),
false );
68 keepDisjointParam->setHelp( QObject::tr(
"If checked, then any disjoint parts in the buffer results will be output as separate single-part features." ) );
69 addParameter( keepDisjointParam.release() );
74QString QgsBufferAlgorithm::shortHelpString()
const
76 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"
77 "The segments parameter controls the number of line segments to use to approximate a quarter circle when creating rounded offsets.\n\n"
78 "The end cap style parameter controls how line endings are handled in the buffer.\n\n"
79 "The join style parameter specifies whether round, miter or beveled joins should be used when offsetting corners in a line.\n\n"
80 "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." );
83QgsBufferAlgorithm *QgsBufferAlgorithm::createInstance()
const
85 return new QgsBufferAlgorithm();
90 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
95 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, source->fields(),
Qgis::WkbType::MultiPolygon, source->sourceCrs() ) );
100 const bool dissolve = parameterAsBoolean( parameters, QStringLiteral(
"DISSOLVE" ), context );
101 const bool keepDisjointSeparate = parameterAsBoolean( parameters, QStringLiteral(
"SEPARATE_DISJOINT" ), context );
102 const int segments = parameterAsInt( parameters, QStringLiteral(
"SEGMENTS" ), context );
105 const double miterLimit = parameterAsDouble( parameters, QStringLiteral(
"MITER_LIMIT" ), context );
106 const double bufferDistance = parameterAsDouble( parameters, QStringLiteral(
"DISTANCE" ), context );
108 QgsExpressionContext expressionContext = createExpressionContext( parameters, context, source.get() );
112 bufferProperty = parameters.
value( QStringLiteral(
"DISTANCE" ) ).value<
QgsProperty >();
115 const long count = source->featureCount();
121 const double step = count > 0 ? 100.0 / count : 1;
124 QVector< QgsGeometry > bufferedGeometriesForDissolve;
133 if ( dissolveAttrs.isEmpty() )
139 double distance = bufferDistance;
143 distance = bufferProperty.
valueAsDouble( expressionContext, bufferDistance );
147 if ( outputGeometry.
isNull() )
153 bufferedGeometriesForDissolve << outputGeometry;
159 if ( !keepDisjointSeparate )
180 else if ( !dissolve )
190 if ( dissolve && !bufferedGeometriesForDissolve.isEmpty() )
197 if ( !keepDisjointSeparate )
218 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
222QgsProcessingAlgorithm::Flags QgsBufferAlgorithm::flags()
const
231 const bool keepDisjointSeparate = parameterAsBoolean( parameters, QStringLiteral(
"SEPARATE_DISJOINT" ), context );
234 if ( sink == QLatin1String(
"OUTPUT" ) )
238 const VectorProperties inputProps = sourceProperties.value( QStringLiteral(
"INPUT" ) );
239 result.
fields = inputProps.fields;
240 result.
crs = inputProps.crs;
247 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
250 result.
fields = source->fields();
251 result.
crs = source->sourceCrs();
261bool QgsBufferAlgorithm::supportInPlaceEdit(
const QgsMapLayer *layer )
const
263 const QgsVectorLayer *vlayer = qobject_cast< const QgsVectorLayer * >( layer );
@ Warning
Warning message.
JoinStyle
Join styles for buffers.
EndCapStyle
End cap styles for buffers.
@ MultiPolygon
MultiPolygon.
Abstract base class for all geometries.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
This class wraps a request for features to a vector layer (or directly its vector data provider).
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
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.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
A geometry is the spatial representation of a feature.
QgsAbstractGeometry::const_part_iterator const_parts_begin() const
Returns STL-style const iterator pointing to the first part of the geometry.
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...
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
static QgsGeometry unaryUnion(const QVector< QgsGeometry > &geometries, const QgsGeometryParameters ¶meters=QgsGeometryParameters())
Compute the unary union on a list of geometries.
Base class for all map layer types.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
@ Available
Properties are available.
virtual Flags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
@ FlagSupportsInPlaceEdits
Algorithm supports in-place editing.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
@ FlagSkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Base class for providing feedback from a processing algorithm.
A boolean parameter for processing algorithms.
@ FlagAdvanced
Parameter is an advanced parameter which should be hidden from users by default.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
A numeric parameter for processing algorithms.
@ Double
Double/float values.
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...
@ TypeVectorPolygon
Vector polygon layers.
Definition for a property.
@ Double
Double value (including negative values)
A store for object properties.
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...
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.
Properties of a vector source or sink used in an algorithm.
Qgis::WkbType wkbType
Geometry (WKB) type.
QgsCoordinateReferenceSystem crs
Coordinate Reference System.
QgsProcessingAlgorithm::PropertyAvailability availability
Availability of the properties. By default properties are not available.