22using namespace Qt::StringLiterals;
26QString QgsTaperedBufferAlgorithm::name()
const
28 return u
"taperedbuffer"_s;
31QString QgsTaperedBufferAlgorithm::displayName()
const
33 return QObject::tr(
"Tapered buffers" );
36QStringList QgsTaperedBufferAlgorithm::tags()
const
38 return QObject::tr(
"variable,distance,length,line,buffer" ).split(
',' );
41QString QgsTaperedBufferAlgorithm::group()
const
43 return QObject::tr(
"Vector geometry" );
46QString QgsTaperedBufferAlgorithm::groupId()
const
48 return u
"vectorgeometry"_s;
51QString QgsTaperedBufferAlgorithm::outputName()
const
53 return QObject::tr(
"Buffered" );
68 mStartWidth = parameterAsDouble( parameters, u
"START_WIDTH"_s, context );
70 if ( mDynamicStartWidth )
71 mStartWidthProperty = parameters.value( u
"START_WIDTH"_s ).value<
QgsProperty>();
73 mEndWidth = parameterAsDouble( parameters, u
"END_WIDTH"_s, context );
75 if ( mDynamicEndWidth )
76 mEndWidthProperty = parameters.value( u
"END_WIDTH"_s ).value<
QgsProperty>();
78 mSegments = parameterAsInt( parameters, u
"Segments"_s, context );
80 if ( mDynamicSegments )
81 mSegmentsProperty = parameters.value( u
"Segments"_s ).value<
QgsProperty>();
86QString QgsTaperedBufferAlgorithm::shortHelpString()
const
88 return QObject::tr(
"This algorithm creates tapered buffers along line geometries, using a specified start and "
89 "end buffer diameter corresponding to the buffer diameter at the start and end of the linestrings." );
92QString QgsTaperedBufferAlgorithm::shortDescription()
const
94 return QObject::tr(
"Creates tapered buffers along line geometries." );
97QList<int> QgsTaperedBufferAlgorithm::inputLayerTypes()
const
102QgsTaperedBufferAlgorithm *QgsTaperedBufferAlgorithm::createInstance()
const
104 return new QgsTaperedBufferAlgorithm();
107void QgsTaperedBufferAlgorithm::initParameters(
const QVariantMap & )
110 startWidth->setIsDynamic(
true );
112 startWidth->setDynamicLayerParameterName( u
"INPUT"_s );
113 addParameter( startWidth.release() );
116 endWidth->setIsDynamic(
true );
118 endWidth->setDynamicLayerParameterName( u
"INPUT"_s );
119 addParameter( endWidth.release() );
122 segments->setIsDynamic(
true );
124 segments->setDynamicLayerParameterName( u
"INPUT"_s );
125 addParameter( segments.release() );
134 int segments = mSegments;
135 if ( mDynamicSegments )
138 double startWidth = mStartWidth;
139 if ( mDynamicStartWidth )
140 startWidth = mStartWidthProperty.valueAsDouble( context.
expressionContext(), startWidth );
142 double endWidth = mEndWidth;
143 if ( mDynamicEndWidth )
147 if ( outputGeometry.
isNull() )
149 feedback->
reportError( QObject::tr(
"Error buffering geometry %1: %2" ).arg( feature.
id() ).arg( outputGeometry.
lastError() ) );
157QString QgsVariableWidthBufferByMAlgorithm::name()
const
159 return u
"bufferbym"_s;
162QString QgsVariableWidthBufferByMAlgorithm::displayName()
const
164 return QObject::tr(
"Variable width buffer (by M value)" );
167QStringList QgsVariableWidthBufferByMAlgorithm::tags()
const
169 return QObject::tr(
"variable,distance,length,line,buffer" ).split(
',' );
172QString QgsVariableWidthBufferByMAlgorithm::group()
const
174 return QObject::tr(
"Vector geometry" );
177QString QgsVariableWidthBufferByMAlgorithm::groupId()
const
179 return u
"vectorgeometry"_s;
182QString QgsVariableWidthBufferByMAlgorithm::outputName()
const
184 return QObject::tr(
"Buffered" );
199 mSegments = parameterAsInt( parameters, u
"Segments"_s, context );
201 if ( mDynamicSegments )
202 mSegmentsProperty = parameters.value( u
"Segments"_s ).value<
QgsProperty>();
207QString QgsVariableWidthBufferByMAlgorithm::shortHelpString()
const
209 return QObject::tr(
"This algorithm creates variable width buffers along lines, using the M value of the line geometries "
210 "as the diameter of the buffer at each vertex." );
213QString QgsVariableWidthBufferByMAlgorithm::shortDescription()
const
215 return QObject::tr(
"Creates variable width buffers along lines, using the M value of the line geometries "
216 "as the diameter of the buffer at each vertex." );
219QList<int> QgsVariableWidthBufferByMAlgorithm::inputLayerTypes()
const
224QgsVariableWidthBufferByMAlgorithm *QgsVariableWidthBufferByMAlgorithm::createInstance()
const
226 return new QgsVariableWidthBufferByMAlgorithm();
229void QgsVariableWidthBufferByMAlgorithm::initParameters(
const QVariantMap & )
232 segments->setIsDynamic(
true );
234 segments->setDynamicLayerParameterName( u
"INPUT"_s );
235 addParameter( segments.release() );
244 int segments = mSegments;
245 if ( mDynamicSegments )
249 if ( outputGeometry.
isNull() )
251 feedback->
reportError( QObject::tr(
"Error buffering geometry %1: %2" ).arg( feature.
id() ).arg( outputGeometry.
lastError() ) );
ProcessingSourceType
Processing data source types.
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
WkbType
The WKB type describes the number of dimensions a geometry has.
@ MultiPolygon
MultiPolygon.
@ Double
Double/float values.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
A geometry is the spatial representation of a feature.
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
QgsGeometry variableWidthBufferByM(int segments) const
Calculates a variable width buffer for a (multi)linestring geometry, where the width at each node is ...
QgsGeometry taperedBuffer(double startWidth, double endWidth, int segments) const
Calculates a variable width buffer ("tapered buffer") for a (multi)curve geometry.
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
Base class for providing feedback from a processing algorithm.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
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...
Definition for a property.
@ IntegerPositiveGreaterZero
Non-zero positive integer values.
@ DoublePositive
Positive double value (including 0).
A store for object properties.
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.
int valueAsInt(const QgsExpressionContext &context, int defaultValue=0, bool *ok=nullptr) const
Calculates the current value of the property and interprets it as an integer.
QList< QgsFeature > QgsFeatureList