26using namespace Qt::StringLiterals;
30QString QgsPointsAlongGeometryAlgorithm::name()
const
32 return u
"pointsalonglines"_s;
35QString QgsPointsAlongGeometryAlgorithm::displayName()
const
37 return QObject::tr(
"Points along geometry" );
40QStringList QgsPointsAlongGeometryAlgorithm::tags()
const
42 return QObject::tr(
"create,interpolate,points,lines,regular,distance,by" ).split(
',' );
45QString QgsPointsAlongGeometryAlgorithm::group()
const
47 return QObject::tr(
"Vector geometry" );
50QString QgsPointsAlongGeometryAlgorithm::groupId()
const
52 return u
"vectorgeometry"_s;
55QString QgsPointsAlongGeometryAlgorithm::outputName()
const
57 return QObject::tr(
"Interpolated points" );
60QString QgsPointsAlongGeometryAlgorithm::shortHelpString()
const
63 "This algorithm creates a points layer, with points distributed along the lines of an "
64 "input vector layer. The distance between points (measured along the line) is defined as a parameter.\n\n"
65 "Start and end offset distances can be defined, so the first and last point will not fall exactly on the line's "
66 "first and last nodes. These start and end offsets are defined as distances, measured along the line from the first and last "
71QString QgsPointsAlongGeometryAlgorithm::shortDescription()
const
73 return QObject::tr(
"Creates regularly spaced points along line features." );
81QList<int> QgsPointsAlongGeometryAlgorithm::inputLayerTypes()
const
101QgsFields QgsPointsAlongGeometryAlgorithm::outputFields(
const QgsFields &inputFields )
const
104 newFields.
append(
QgsField( u
"distance"_s, QMetaType::Type::Double ) );
105 newFields.
append(
QgsField( u
"angle"_s, QMetaType::Type::Double ) );
109QgsPointsAlongGeometryAlgorithm *QgsPointsAlongGeometryAlgorithm::createInstance()
const
111 return new QgsPointsAlongGeometryAlgorithm();
114void QgsPointsAlongGeometryAlgorithm::initParameters(
const QVariantMap & )
116 auto distance = std::make_unique<QgsProcessingParameterDistance>( u
"DISTANCE"_s, QObject::tr(
"Distance" ), 1.0, u
"INPUT"_s,
false, 0 );
117 distance->setIsDynamic(
true );
119 distance->setDynamicLayerParameterName( u
"INPUT"_s );
120 addParameter( distance.release() );
122 auto startOffset = std::make_unique<QgsProcessingParameterDistance>( u
"START_OFFSET"_s, QObject::tr(
"Start offset" ), 0.0, u
"INPUT"_s,
false, 0 );
123 startOffset->setIsDynamic(
true );
125 startOffset->setDynamicLayerParameterName( u
"INPUT"_s );
126 addParameter( startOffset.release() );
128 auto endOffset = std::make_unique<QgsProcessingParameterDistance>( u
"END_OFFSET"_s, QObject::tr(
"End offset" ), 0.0, u
"INPUT"_s,
false, 0 );
129 endOffset->setIsDynamic(
true );
131 endOffset->setDynamicLayerParameterName( u
"INPUT"_s );
132 addParameter( endOffset.release() );
135QIcon QgsPointsAlongGeometryAlgorithm::icon()
const
140QString QgsPointsAlongGeometryAlgorithm::svgIconPath()
const
158 mDistance = parameterAsDouble( parameters, u
"DISTANCE"_s, context );
160 if ( mDynamicDistance )
161 mDistanceProperty = parameters.value( u
"DISTANCE"_s ).value<
QgsProperty>();
163 mStartOffset = parameterAsDouble( parameters, u
"START_OFFSET"_s, context );
165 if ( mDynamicStartOffset )
166 mStartOffsetProperty = parameters.value( u
"START_OFFSET"_s ).value<
QgsProperty>();
168 mEndOffset = parameterAsDouble( parameters, u
"END_OFFSET"_s, context );
170 if ( mDynamicEndOffset )
171 mEndOffsetProperty = parameters.value( u
"END_OFFSET"_s ).value<
QgsProperty>();
183 double distance = mDistance;
184 if ( mDynamicDistance )
185 distance = mDistanceProperty.valueAsDouble( context.
expressionContext(), distance );
189 double startOffset = mStartOffset;
190 if ( mDynamicStartOffset )
193 double endOffset = mEndOffset;
194 if ( mDynamicEndOffset )
199 double currentDistance = startOffset;
201 out.reserve(
static_cast<int>( std::ceil( ( totalLength - startOffset ) / distance ) ) );
202 while ( currentDistance <= totalLength )
209 outAttr << currentDistance <<
angle;
211 out.append( outputFeature );
212 currentDistance += distance;
221 outAttr << QVariant() << QVariant();
ProcessingSourceType
Processing data source types.
@ VectorPoint
Vector point layers.
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
@ RegeneratesPrimaryKey
Algorithm always drops any existing primary keys or FID values and regenerates them in outputs.
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
WkbType
The WKB type describes the number of dimensions a geometry has.
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
virtual double perimeter() const
Returns the planar, 2-dimensional perimeter of the geometry.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
QFlags< SinkFlag > SinkFlags
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
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.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
A geometry is the spatial representation of a feature.
double length() const
Returns the planar, 2-dimensional length of geometry.
QgsGeometry interpolate(double distance) const
Returns an interpolated point on the geometry at the specified distance.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
double interpolateAngle(double distance) const
Returns the angle parallel to the linestring or polygon boundary at the specified distance along the ...
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.
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...
static QgsFields combineFields(const QgsFields &fieldsA, const QgsFields &fieldsB, const QString &fieldsBPrefix=QString())
Combines two field lists, avoiding duplicate field names (in a case-insensitive manner).
Definition for a property.
@ 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.
static Qgis::WkbType addM(Qgis::WkbType type)
Adds the m dimension to a WKB type and returns the new type.
static Qgis::WkbType addZ(Qgis::WkbType type)
Adds the z dimension to a WKB type and returns the new type.
static Q_INVOKABLE bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static Q_INVOKABLE bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored).
QList< QgsFeature > QgsFeatureList