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
89 "This algorithm creates tapered buffers along line geometries, using a specified start and "
90 "end buffer diameter corresponding to the buffer diameter at the start and end of the linestrings."
94QString QgsTaperedBufferAlgorithm::shortDescription()
const
96 return QObject::tr(
"Creates tapered buffers along line geometries." );
99QList<int> QgsTaperedBufferAlgorithm::inputLayerTypes()
const
104QgsTaperedBufferAlgorithm *QgsTaperedBufferAlgorithm::createInstance()
const
106 return new QgsTaperedBufferAlgorithm();
109void QgsTaperedBufferAlgorithm::initParameters(
const QVariantMap & )
112 startWidth->setIsDynamic(
true );
114 startWidth->setDynamicLayerParameterName( u
"INPUT"_s );
115 addParameter( startWidth.release() );
118 endWidth->setIsDynamic(
true );
120 endWidth->setDynamicLayerParameterName( u
"INPUT"_s );
121 addParameter( endWidth.release() );
124 segments->setIsDynamic(
true );
126 segments->setDynamicLayerParameterName( u
"INPUT"_s );
127 addParameter( segments.release() );
132 QGS_MARK_ALGORITHM_SOURCE
138 int segments = mSegments;
139 if ( mDynamicSegments )
142 double startWidth = mStartWidth;
143 if ( mDynamicStartWidth )
144 startWidth = mStartWidthProperty.valueAsDouble( context.
expressionContext(), startWidth );
146 double endWidth = mEndWidth;
147 if ( mDynamicEndWidth )
151 if ( outputGeometry.
isNull() )
153 feedback->
reportError( QObject::tr(
"Error buffering geometry %1: %2" ).arg( feature.
id() ).arg( outputGeometry.
lastError() ) );
161QString QgsVariableWidthBufferByMAlgorithm::name()
const
163 return u
"bufferbym"_s;
166QString QgsVariableWidthBufferByMAlgorithm::displayName()
const
168 return QObject::tr(
"Variable width buffer (by M value)" );
171QStringList QgsVariableWidthBufferByMAlgorithm::tags()
const
173 return QObject::tr(
"variable,distance,length,line,buffer" ).split(
',' );
176QString QgsVariableWidthBufferByMAlgorithm::group()
const
178 return QObject::tr(
"Vector geometry" );
181QString QgsVariableWidthBufferByMAlgorithm::groupId()
const
183 return u
"vectorgeometry"_s;
186QString QgsVariableWidthBufferByMAlgorithm::outputName()
const
188 return QObject::tr(
"Buffered" );
203 mSegments = parameterAsInt( parameters, u
"Segments"_s, context );
205 if ( mDynamicSegments )
206 mSegmentsProperty = parameters.value( u
"Segments"_s ).value<
QgsProperty>();
211QString QgsVariableWidthBufferByMAlgorithm::shortHelpString()
const
214 "This algorithm creates variable width buffers along lines, using the M value of the line geometries "
215 "as the diameter of the buffer at each vertex."
219QString QgsVariableWidthBufferByMAlgorithm::shortDescription()
const
222 "Creates variable width buffers along lines, using the M value of the line geometries "
223 "as the diameter of the buffer at each vertex."
227QList<int> QgsVariableWidthBufferByMAlgorithm::inputLayerTypes()
const
232QgsVariableWidthBufferByMAlgorithm *QgsVariableWidthBufferByMAlgorithm::createInstance()
const
234 return new QgsVariableWidthBufferByMAlgorithm();
237void QgsVariableWidthBufferByMAlgorithm::initParameters(
const QVariantMap & )
240 segments->setIsDynamic(
true );
242 segments->setDynamicLayerParameterName( u
"INPUT"_s );
243 addParameter( segments.release() );
248 QGS_MARK_ALGORITHM_SOURCE
254 int segments = mSegments;
255 if ( mDynamicSegments )
259 if ( outputGeometry.
isNull() )
261 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