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 = parameterAsBoolean( 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
185 if ( sink == QStringLiteral(
"OUTPUT" ) )
189 const VectorProperties inputProps = sourceProperties.value( QStringLiteral(
"INPUT" ) );
190 result.
fields = inputProps.fields;
191 result.
crs = inputProps.crs;
198 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
201 result.
fields = source->fields();
202 result.
crs = source->sourceCrs();
212 bool QgsBufferAlgorithm::supportInPlaceEdit(
const QgsMapLayer *layer )
const
214 const QgsVectorLayer *vlayer = qobject_cast< const QgsVectorLayer * >( layer );
218 return vlayer->
wkbType() == QgsWkbTypes::Type::Polygon || vlayer->
wkbType() == QgsWkbTypes::Type::MultiPolygon;