QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsalgorithminterpolatepoint.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithminterpolatepoint.cpp
3 ---------------------
4 begin : August 2018
5 copyright : (C) 2018 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19
20#include "qgscurve.h"
22
24
25QString QgsInterpolatePointAlgorithm::name() const
26{
27 return QStringLiteral( "interpolatepoint" );
28}
29
30QString QgsInterpolatePointAlgorithm::displayName() const
31{
32 return QObject::tr( "Interpolate point on line" );
33}
34
35QStringList QgsInterpolatePointAlgorithm::tags() const
36{
37 return QObject::tr( "linestring,reference,referencing,distance,interpolate" ).split( ',' );
38}
39
40QString QgsInterpolatePointAlgorithm::group() const
41{
42 return QObject::tr( "Vector geometry" );
43}
44
45QString QgsInterpolatePointAlgorithm::groupId() const
46{
47 return QStringLiteral( "vectorgeometry" );
48}
49
50QString QgsInterpolatePointAlgorithm::outputName() const
51{
52 return QObject::tr( "Interpolated points" );
53}
54
55QString QgsInterpolatePointAlgorithm::shortHelpString() const
56{
57 return QObject::tr( "This algorithm creates a point geometry interpolated at a set distance along line or curve geometries.\n\n"
58 "Z and M values are linearly interpolated from existing values.\n\n"
59 "If a multipart geometry is encountered, only the first part is considered when "
60 "interpolating the point.\n\n"
61 "If the specified distance is greater than the curve's length, the resultant feature will have a null geometry." );
62}
63
64QString QgsInterpolatePointAlgorithm::shortDescription() const
65{
66 return QObject::tr( "Interpolates a point along lines at a set distance." );
67}
68
69QList<int> QgsInterpolatePointAlgorithm::inputLayerTypes() const
70{
71 return QList<int>() << static_cast<int>( Qgis::ProcessingSourceType::VectorLine ) << static_cast<int>( Qgis::ProcessingSourceType::VectorPolygon );
72}
73
74Qgis::ProcessingSourceType QgsInterpolatePointAlgorithm::outputLayerType() const
75{
77}
78
79Qgis::WkbType QgsInterpolatePointAlgorithm::outputWkbType( Qgis::WkbType inputType ) const
80{
82 if ( QgsWkbTypes::hasZ( inputType ) )
83 out = QgsWkbTypes::addZ( out );
84 if ( QgsWkbTypes::hasM( inputType ) )
85 out = QgsWkbTypes::addM( out );
86 return out;
87}
88
89QgsInterpolatePointAlgorithm *QgsInterpolatePointAlgorithm::createInstance() const
90{
91 return new QgsInterpolatePointAlgorithm();
92}
93
94void QgsInterpolatePointAlgorithm::initParameters( const QVariantMap & )
95{
96 auto distance = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral( "DISTANCE" ), QObject::tr( "Distance" ), 0.0, QStringLiteral( "INPUT" ), false, 0 );
97 distance->setIsDynamic( true );
98 distance->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "DISTANCE" ), QObject::tr( "Distance" ), QgsPropertyDefinition::DoublePositive ) );
99 distance->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
100 addParameter( distance.release() );
101}
102
103Qgis::ProcessingFeatureSourceFlags QgsInterpolatePointAlgorithm::sourceFlags() const
104{
105 // skip geometry checks - this algorithm doesn't care about invalid geometries
107}
108
109bool QgsInterpolatePointAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
110{
111 mDistance = parameterAsDouble( parameters, QStringLiteral( "DISTANCE" ), context );
112 mDynamicDistance = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "DISTANCE" ) );
113 if ( mDynamicDistance )
114 mDistanceProperty = parameters.value( QStringLiteral( "DISTANCE" ) ).value<QgsProperty>();
115
116 return true;
117}
118
119QgsFeatureList QgsInterpolatePointAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback * )
120{
121 QgsFeature f = feature;
122 if ( f.hasGeometry() )
123 {
124 const QgsGeometry geometry = f.geometry();
125 double distance = mDistance;
126 if ( mDynamicDistance )
127 distance = mDistanceProperty.valueAsDouble( context.expressionContext(), distance );
128
129 f.setGeometry( geometry.interpolate( distance ) );
130 }
131 return QgsFeatureList() << f;
132}
133
ProcessingSourceType
Processing data source types.
Definition qgis.h:3531
@ VectorPoint
Vector point layers.
Definition qgis.h:3534
@ VectorPolygon
Vector polygon layers.
Definition qgis.h:3536
@ VectorLine
Vector line layers.
Definition qgis.h:3535
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Definition qgis.h:3711
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:277
@ Point
Point.
Definition qgis.h:279
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
Definition qgis.h:3722
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
QgsGeometry geometry
Definition qgsfeature.h:69
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.
QgsGeometry interpolate(double distance) const
Returns an interpolated point on the geometry at the specified distance.
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 &parameters, 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.
Definition qgsproperty.h:45
@ DoublePositive
Positive double value (including 0).
Definition qgsproperty.h:56
A store for object properties.
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.
QList< QgsFeature > QgsFeatureList