QGIS API Documentation 3.99.0-Master (357b655ed83)
Loading...
Searching...
No Matches
qgsalgorithmtransect.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmtransect.cpp
3 -------------------------
4 begin : October 2017
5 copyright : (C) 2017 by Loïc Bartoletti
6 email : lituus at free dot fr
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 "qgslinestring.h"
21#include "qgsmultilinestring.h"
22
23#include <QString>
24
25using namespace Qt::StringLiterals;
26
28
29QString QgsTransectAlgorithm::name() const
30{
31 return u"transect"_s;
32}
33
34QString QgsTransectAlgorithm::displayName() const
35{
36 return QObject::tr( "Transect" );
37}
38
39QString QgsTransectAlgorithm::shortHelpString() const
40{
41 return QObject::tr( "This algorithm creates transects on vertices for (multi)linestrings.\n" )
42 + QObject::tr( "A transect is a line oriented from an angle (by default perpendicular) to the input polylines (at vertices)." )
43 + u"\n\n"_s
44 + QObject::tr( "Field(s) from feature(s) are returned in the transect with these new fields:\n" )
45 + QObject::tr( "- TR_FID: ID of the original feature\n" )
46 + QObject::tr( "- TR_ID: ID of the transect. Each transect have an unique ID\n" )
47 + QObject::tr( "- TR_SEGMENT: ID of the segment of the linestring\n" )
48 + QObject::tr( "- TR_ANGLE: Angle in degrees from the original line at the vertex\n" )
49 + QObject::tr( "- TR_LENGTH: Total length of the transect returned\n" )
50 + QObject::tr( "- TR_ORIENT: Side of the transect (only on the left or right of the line, or both side)\n" );
51}
52
53QgsTransectAlgorithm *QgsTransectAlgorithm::createInstance() const
54{
55 return new QgsTransectAlgorithm();
56}
57
58void QgsTransectAlgorithm::addAlgorithmParams()
59{
60 // No additional parameters for the basic transect algorithm (vertex-based only)
61}
62
63bool QgsTransectAlgorithm::prepareAlgorithmTransectParameters( const QVariantMap &, QgsProcessingContext &, QgsProcessingFeedback * )
64{
65 // No additional preparation needed for basic transect algorithm
66 return true;
67}
68
69std::vector<QgsPoint> QgsTransectAlgorithm::generateSamplingPoints( const QgsLineString &line, const QVariantMap &, QgsProcessingContext & )
70{
71 std::vector<QgsPoint> samplingPoints;
72
73 for ( auto it = line.vertices_begin(); it != line.vertices_end(); ++it )
74 samplingPoints.push_back( *it );
75
76 return samplingPoints;
77}
78
79double QgsTransectAlgorithm::calculateAzimuth( const QgsLineString &line, const QgsPoint &, int pointIndex )
80{
81 return line.vertexAngle( QgsVertexId( 0, 0, pointIndex ) );
82}
83
vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
Line string geometry type, with support for z-dimension and m-values.
double vertexAngle(QgsVertexId vertex) const override
Returns approximate angle at a vertex.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
Contains information about the context in which a processing algorithm is executed.
Base class for providing feedback from a processing algorithm.
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:34