25QString QgsPointsAlongGeometryAlgorithm::name()
const
27 return QStringLiteral(
"pointsalonglines" );
30QString QgsPointsAlongGeometryAlgorithm::displayName()
const
32 return QObject::tr(
"Points along geometry" );
35QStringList QgsPointsAlongGeometryAlgorithm::tags()
const
37 return QObject::tr(
"create,interpolate,points,lines,regular,distance,by" ).split(
',' );
40QString QgsPointsAlongGeometryAlgorithm::group()
const
42 return QObject::tr(
"Vector geometry" );
45QString QgsPointsAlongGeometryAlgorithm::groupId()
const
47 return QStringLiteral(
"vectorgeometry" );
50QString QgsPointsAlongGeometryAlgorithm::outputName()
const
52 return QObject::tr(
"Interpolated points" );
55QString QgsPointsAlongGeometryAlgorithm::shortHelpString()
const
57 return QObject::tr(
"This algorithm creates a points layer, with points distributed along the lines of an "
58 "input vector layer. The distance between points (measured along the line) is defined as a parameter.\n\n"
59 "Start and end offset distances can be defined, so the first and last point will not fall exactly on the line's "
60 "first and last nodes. These start and end offsets are defined as distances, measured along the line from the first and last "
61 "nodes of the lines." );
64QString QgsPointsAlongGeometryAlgorithm::shortDescription()
const
66 return QObject::tr(
"Creates regularly spaced points along line features." );
74QList<int> QgsPointsAlongGeometryAlgorithm::inputLayerTypes()
const
94QgsFields QgsPointsAlongGeometryAlgorithm::outputFields(
const QgsFields &inputFields )
const
97 output.
append(
QgsField( QStringLiteral(
"distance" ), QMetaType::Type::Double ) );
98 output.
append(
QgsField( QStringLiteral(
"angle" ), QMetaType::Type::Double ) );
102QgsPointsAlongGeometryAlgorithm *QgsPointsAlongGeometryAlgorithm::createInstance()
const
104 return new QgsPointsAlongGeometryAlgorithm();
107void QgsPointsAlongGeometryAlgorithm::initParameters(
const QVariantMap & )
109 std::unique_ptr< QgsProcessingParameterDistance> distance = std::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"DISTANCE" ),
110 QObject::tr(
"Distance" ), 1.0, QStringLiteral(
"INPUT" ),
false, 0 );
111 distance->setIsDynamic(
true );
113 distance->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
114 addParameter( distance.release() );
116 std::unique_ptr< QgsProcessingParameterDistance> startOffset = std::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"START_OFFSET" ),
117 QObject::tr(
"Start offset" ), 0.0, QStringLiteral(
"INPUT" ),
false, 0 );
118 startOffset->setIsDynamic(
true );
120 startOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
121 addParameter( startOffset.release() );
123 std::unique_ptr< QgsProcessingParameterDistance> endOffset = std::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"END_OFFSET" ),
124 QObject::tr(
"End offset" ), 0.0, QStringLiteral(
"INPUT" ),
false, 0 );
125 endOffset->setIsDynamic(
true );
127 endOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
128 addParameter( endOffset.release() );
131QIcon QgsPointsAlongGeometryAlgorithm::icon()
const
136QString QgsPointsAlongGeometryAlgorithm::svgIconPath()
const
154 mDistance = parameterAsDouble( parameters, QStringLiteral(
"DISTANCE" ), context );
156 if ( mDynamicDistance )
157 mDistanceProperty = parameters.value( QStringLiteral(
"DISTANCE" ) ).value<
QgsProperty >();
159 mStartOffset = parameterAsDouble( parameters, QStringLiteral(
"START_OFFSET" ), context );
161 if ( mDynamicStartOffset )
162 mStartOffsetProperty = parameters.value( QStringLiteral(
"START_OFFSET" ) ).value<
QgsProperty >();
164 mEndOffset = parameterAsDouble( parameters, QStringLiteral(
"END_OFFSET" ), context );
166 if ( mDynamicEndOffset )
167 mEndOffsetProperty = parameters.value( QStringLiteral(
"END_OFFSET" ) ).value<
QgsProperty >();
179 double distance = mDistance;
180 if ( mDynamicDistance )
181 distance = mDistanceProperty.valueAsDouble( context.
expressionContext(), distance );
185 double startOffset = mStartOffset;
186 if ( mDynamicStartOffset )
189 double endOffset = mEndOffset;
190 if ( mDynamicEndOffset )
194 : geometry.
length() - endOffset;
196 double currentDistance = startOffset;
198 out.reserve(
static_cast< int >( std::ceil( ( totalLength - startOffset ) / distance ) ) );
199 while ( currentDistance <= totalLength )
206 outAttr << currentDistance <<
angle;
208 out.append( outputFeature );
209 currentDistance += distance;
218 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...
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 bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static 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