24 QString QgsTransectAlgorithm::name()
const 26 return QStringLiteral(
"transect" );
29 QString QgsTransectAlgorithm::displayName()
const 31 return QObject::tr(
"Transect" );
34 QStringList QgsTransectAlgorithm::tags()
const 36 return QObject::tr(
"transect,station,lines,extend," ).split(
',' );
39 QString QgsTransectAlgorithm::group()
const 41 return QObject::tr(
"Vector geometry" );
44 QString QgsTransectAlgorithm::groupId()
const 46 return QStringLiteral(
"vectorgeometry" );
49 void QgsTransectAlgorithm::initAlgorithm(
const QVariantMap & )
56 90.0,
false, 0, 360 ) );
57 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"SIDE" ), QObject::tr(
"Side to create the transects" ), QStringList() << QObject::tr(
"Left" ) << QObject::tr(
"Right" ) << QObject::tr(
"Both" ),
false ) );
62 QString QgsTransectAlgorithm::shortHelpString()
const 65 return QObject::tr(
"This algorithm creates transects on vertices for (multi)linestring.\n" ) +
66 QObject::tr(
"A transect is a line oriented from an angle (by default perpendicular) to the input polylines (at vertices)." ) +
67 QStringLiteral(
"\n\n" ) +
68 QObject::tr(
"Field(s) from feature(s) are returned in the transect with these new fields:\n" ) +
69 QObject::tr(
"- TR_FID: ID of the original feature\n" ) +
70 QObject::tr(
"- TR_ID: ID of the transect. Each transect have an unique ID\n" ) +
71 QObject::tr(
"- TR_SEGMENT: ID of the segment of the linestring\n" ) +
72 QObject::tr(
"- TR_ANGLE: Angle in degrees from the original line at the vertex\n" ) +
73 QObject::tr(
"- TR_LENGTH: Total length of the transect returned\n" ) +
74 QObject::tr(
"- TR_ORIENT: Side of the transect (only on the left or right of the line, or both side)\n" );
78 QgsTransectAlgorithm *QgsTransectAlgorithm::createInstance()
const 80 return new QgsTransectAlgorithm();
85 Side orientation =
static_cast< QgsTransectAlgorithm::Side
>( parameterAsInt( parameters, QStringLiteral(
"SIDE" ), context ) );
86 double angle = fabs( parameterAsDouble( parameters, QStringLiteral(
"ANGLE" ), context ) );
87 double length = parameterAsDouble( parameters, QStringLiteral(
"LENGTH" ), context );
89 if ( orientation == QgsTransectAlgorithm::Both )
92 std::unique_ptr< QgsFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
98 fields.
append(
QgsField( QStringLiteral(
"TR_FID" ), QVariant::Int, QString(), 20 ) );
99 fields.
append(
QgsField( QStringLiteral(
"TR_ID" ), QVariant::Int, QString(), 20 ) );
100 fields.
append(
QgsField( QStringLiteral(
"TR_SEGMENT" ), QVariant::Int, QString(), 20 ) );
101 fields.
append(
QgsField( QStringLiteral(
"TR_ANGLE" ), QVariant::Double, QString(), 5, 2 ) );
102 fields.
append(
QgsField( QStringLiteral(
"TR_LENGTH" ), QVariant::Double, QString(), 20, 6 ) );
103 fields.
append(
QgsField( QStringLiteral(
"TR_ORIENT" ), QVariant::Int, QString(), 1 ) );
112 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, fields,
113 outputWkb, source->sourceCrs() ) );
121 double step = source->featureCount() > 0 ? 100.0 / source->featureCount() : 1;
151 attrs << current << number << i + 1 << angle <<
152 ( ( orientation == QgsTransectAlgorithm::Both ) ? length * 2 : length ) <<
155 double angleAtVertex = line->
vertexAngle( vertexId );
156 outFeat.
setGeometry( calcTransect( *it, angleAtVertex, length, orientation, angle ) );
165 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
170 QgsGeometry QgsTransectAlgorithm::calcTransect(
const QgsPoint &point,
const double angleAtVertex,
const double length,
const QgsTransectAlgorithm::Side orientation,
const double angle )
177 if ( ( orientation == QgsTransectAlgorithm::Right ) || ( orientation == QgsTransectAlgorithm::Both ) )
179 pLeft = point.
project( length, angle + 180.0 / M_PI * angleAtVertex );
180 if ( orientation != QgsTransectAlgorithm::Both )
184 if ( ( orientation == QgsTransectAlgorithm::Left ) || ( orientation == QgsTransectAlgorithm::Both ) )
186 pRight = point.
project( -length, angle + 180.0 / M_PI * angleAtVertex );
187 if ( orientation != QgsTransectAlgorithm::Both )
191 line.append( pLeft );
192 line.append( pRight );
Wrapper for iterator of features from vector data provider or vector layer.
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
Base class for providing feedback from a processing algorithm.
static QgsGeometry fromPolyline(const QgsPolyline &polyline)
Creates a new LineString geometry from a list of QgsPoint points.
QVector< QgsPoint > QgsPolyline
Polyline as represented as a vector of points.
QgsVertexId vertexId() const
Returns vertex ID of the current item.
void setProgress(double progress)
Sets the current progress for the feedback object.
Multi line string geometry collection.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
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...
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)
A feature sink output for processing algorithms.
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.
An enum based parameter for processing algorithms, allowing for selection from predefined values...
Utility class for identifying a unique vertex within a geometry.
vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry...
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type.
Custom exception class for processing related exceptions.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Append a field. The field must have unique name, otherwise it is rejected (returns false) ...
Encapsulate a field in an attribute table or data source.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
The vertex_iterator class provides STL-style iterator for vertices.
QgsPoint project(double distance, double azimuth, double inclination=90.0) const
Returns a new point which correspond to this point projected by a specified distance with specified a...
Point geometry type, with support for z-dimension and m-values.
A numeric parameter for processing algorithms.
int numGeometries() const
Returns the number of geometries within the collection.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
bool isCanceled() const
Tells whether the operation has been canceled already.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
An input feature source (such as vector layers) parameter for processing algorithms.
double vertexAngle(QgsVertexId vertex) const override
Returns approximate angle at a vertex.
Line string geometry type, with support for z-dimension and m-values.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
bool nextFeature(QgsFeature &f)
Contains information about the context in which a processing algorithm is executed.