25 QString QgsPointsAlongGeometryAlgorithm::name()
const 27 return QStringLiteral(
"pointsalonglines" );
30 QString QgsPointsAlongGeometryAlgorithm::displayName()
const 32 return QObject::tr(
"Points along geometry" );
35 QStringList QgsPointsAlongGeometryAlgorithm::tags()
const 37 return QObject::tr(
"create,interpolate,points,lines,regular,distance,by" ).split(
',' );
40 QString QgsPointsAlongGeometryAlgorithm::group()
const 42 return QObject::tr(
"Vector geometry" );
45 QString QgsPointsAlongGeometryAlgorithm::groupId()
const 47 return QStringLiteral(
"vectorgeometry" );
50 QString QgsPointsAlongGeometryAlgorithm::outputName()
const 52 return QObject::tr(
"Interpolated points" );
55 QString 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." );
64 QString QgsPointsAlongGeometryAlgorithm::shortDescription()
const 66 return QObject::tr(
"Creates regularly spaced points along line features." );
69 QList<int> QgsPointsAlongGeometryAlgorithm::inputLayerTypes()
const 89 QgsFields QgsPointsAlongGeometryAlgorithm::outputFields(
const QgsFields &inputFields )
const 92 output.
append(
QgsField( QStringLiteral(
"distance" ), QVariant::Double ) );
93 output.
append(
QgsField( QStringLiteral(
"angle" ), QVariant::Double ) );
97 QgsPointsAlongGeometryAlgorithm *QgsPointsAlongGeometryAlgorithm::createInstance()
const 99 return new QgsPointsAlongGeometryAlgorithm();
102 void QgsPointsAlongGeometryAlgorithm::initParameters(
const QVariantMap & )
104 std::unique_ptr< QgsProcessingParameterDistance> distance = qgis::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"DISTANCE" ),
105 QObject::tr(
"Distance" ), 1.0, QStringLiteral(
"INPUT" ),
false, 0 );
106 distance->setIsDynamic(
true );
108 distance->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
109 addParameter( distance.release() );
111 std::unique_ptr< QgsProcessingParameterDistance> startOffset = qgis::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"START_OFFSET" ),
112 QObject::tr(
"Start offset" ), 0.0, QStringLiteral(
"INPUT" ),
false, 0 );
113 startOffset->setIsDynamic(
true );
115 startOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
116 addParameter( startOffset.release() );
118 std::unique_ptr< QgsProcessingParameterDistance> endOffset = qgis::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"END_OFFSET" ),
119 QObject::tr(
"End offset" ), 0.0, QStringLiteral(
"INPUT" ),
false, 0 );
120 endOffset->setIsDynamic(
true );
122 endOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
123 addParameter( endOffset.release() );
126 QIcon QgsPointsAlongGeometryAlgorithm::icon()
const 131 QString QgsPointsAlongGeometryAlgorithm::svgIconPath()
const 142 QgsFeatureSink::SinkFlags QgsPointsAlongGeometryAlgorithm::sinkFlags()
const 149 mDistance = parameterAsDouble( parameters, QStringLiteral(
"DISTANCE" ), context );
151 if ( mDynamicDistance )
152 mDistanceProperty = parameters.value( QStringLiteral(
"DISTANCE" ) ).value<
QgsProperty >();
154 mStartOffset = parameterAsDouble( parameters, QStringLiteral(
"START_OFFSET" ), context );
156 if ( mDynamicStartOffset )
157 mStartOffsetProperty = parameters.value( QStringLiteral(
"START_OFFSET" ) ).value<
QgsProperty >();
159 mEndOffset = parameterAsDouble( parameters, QStringLiteral(
"END_OFFSET" ), context );
161 if ( mDynamicEndOffset )
162 mEndOffsetProperty = parameters.value( QStringLiteral(
"END_OFFSET" ) ).value<
QgsProperty >();
174 double distance = mDistance;
175 if ( mDynamicDistance )
176 distance = mDistanceProperty.valueAsDouble( context.
expressionContext(), distance );
180 double startOffset = mStartOffset;
181 if ( mDynamicStartOffset )
184 double endOffset = mEndOffset;
185 if ( mDynamicEndOffset )
189 : geometry.
length() - endOffset;
191 double currentDistance = startOffset;
193 out.reserve( static_cast< int >( std::ceil( ( totalLength - startOffset ) / distance ) ) );
194 while ( currentDistance <= totalLength )
201 outAttr << currentDistance <<
angle;
203 out.append( outputFeature );
204 currentDistance += distance;
213 outAttr << QVariant() << QVariant();
Base class for providing feedback from a processing algorithm.
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
QList< QgsFeature > QgsFeatureList
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
QgsGeometry interpolate(double distance) const
Returns an interpolated point on the geometry at the specified distance.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Positive double value (including 0)
bool hasGeometry() const
Returns true if the feature has an associated geometry.
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
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)
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
Type
The WKB type describes the number of dimensions a geometry has.
static Type addM(Type type)
Adds the m dimension to a WKB type and returns the new type.
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false) ...
Encapsulate a field in an attribute table or data source.
A store for object properties.
double length() const
Returns the planar, 2-dimensional length of geometry.
QgsExpressionContext & expressionContext()
Returns the expression context.
Definition for a property.
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
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.
double interpolateAngle(double distance) const
Returns the angle parallel to the linestring or polygon boundary at the specified distance along the ...
bool isCanceled() const
Tells whether the operation has been canceled already.
virtual double perimeter() const
Returns the planar, 2-dimensional perimeter of the geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
SourceType
Data source types enum.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
QgsWkbTypes::GeometryType type
Contains information about the context in which a processing algorithm is executed.
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...