QGIS API Documentation 3.38.0-Grenoble (exported)
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
20#include "qgscurve.h"
21
23
24QString QgsInterpolatePointAlgorithm::name() const
25{
26 return QStringLiteral( "interpolatepoint" );
27}
28
29QString QgsInterpolatePointAlgorithm::displayName() const
30{
31 return QObject::tr( "Interpolate point on line" );
32}
33
34QStringList QgsInterpolatePointAlgorithm::tags() const
35{
36 return QObject::tr( "linestring,reference,referencing,distance,interpolate" ).split( ',' );
37}
38
39QString QgsInterpolatePointAlgorithm::group() const
40{
41 return QObject::tr( "Vector geometry" );
42}
43
44QString QgsInterpolatePointAlgorithm::groupId() const
45{
46 return QStringLiteral( "vectorgeometry" );
47}
48
49QString QgsInterpolatePointAlgorithm::outputName() const
50{
51 return QObject::tr( "Interpolated points" );
52}
53
54QString QgsInterpolatePointAlgorithm::shortHelpString() const
55{
56 return QObject::tr( "This algorithm creates a point geometry interpolated at a set distance along line or curve geometries.\n\n"
57 "Z and M values are linearly interpolated from existing values.\n\n"
58 "If a multipart geometry is encountered, only the first part is considered when "
59 "interpolating the point.\n\n"
60 "If the specified distance is greater than the curve's length, the resultant feature will have a null geometry." );
61}
62
63QString QgsInterpolatePointAlgorithm::shortDescription() const
64{
65 return QObject::tr( "Interpolates a point along lines at a set distance." );
66}
67
68QList<int> QgsInterpolatePointAlgorithm::inputLayerTypes() const
69{
70 return QList<int>() << static_cast< int >( Qgis::ProcessingSourceType::VectorLine ) << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
71}
72
73Qgis::ProcessingSourceType QgsInterpolatePointAlgorithm::outputLayerType() const
74{
76}
77
78Qgis::WkbType QgsInterpolatePointAlgorithm::outputWkbType( Qgis::WkbType inputType ) const
79{
81 if ( QgsWkbTypes::hasZ( inputType ) )
82 out = QgsWkbTypes::addZ( out );
83 if ( QgsWkbTypes::hasM( inputType ) )
84 out = QgsWkbTypes::addM( out );
85 return out;
86}
87
88QgsInterpolatePointAlgorithm *QgsInterpolatePointAlgorithm::createInstance() const
89{
90 return new QgsInterpolatePointAlgorithm();
91}
92
93void QgsInterpolatePointAlgorithm::initParameters( const QVariantMap & )
94{
95 std::unique_ptr< QgsProcessingParameterDistance> distance = std::make_unique< QgsProcessingParameterDistance >( QStringLiteral( "DISTANCE" ),
96 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
135
136
ProcessingSourceType
Processing data source types.
Definition qgis.h:2995
@ VectorPoint
Vector point layers.
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
@ 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.
Definition qgis.h:201
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
Definition qgis.h:3148
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 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.
QList< QgsFeature > QgsFeatureList