QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
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 & )
53 std::unique_ptr< QgsProcessingParameterDistance > length = std::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"LENGTH" ), QObject::tr(
"Length of the transect" ),
54 5.0, QStringLiteral(
"INPUT" ),
false, 0 );
55 length->setIsDynamic(
true );
57 length->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
58 addParameter( length.release() );
60 std::unique_ptr< QgsProcessingParameterNumber >
angle = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"ANGLE" ), QObject::tr(
"Angle in degrees from the original line at the vertices" ),
QgsProcessingParameterNumber::Double,
61 90.0,
false, 0, 360 );
62 angle->setIsDynamic(
true );
64 angle->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
65 addParameter(
angle.release() );
67 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"SIDE" ), QObject::tr(
"Side to create the transects" ), QStringList() << QObject::tr(
"Left" ) << QObject::tr(
"Right" ) << QObject::tr(
"Both" ),
false ) );
72 QString QgsTransectAlgorithm::shortHelpString()
const
75 return QObject::tr(
"This algorithm creates transects on vertices for (multi)linestring.\n" ) +
76 QObject::tr(
"A transect is a line oriented from an angle (by default perpendicular) to the input polylines (at vertices)." ) +
77 QStringLiteral(
"\n\n" ) +
78 QObject::tr(
"Field(s) from feature(s) are returned in the transect with these new fields:\n" ) +
79 QObject::tr(
"- TR_FID: ID of the original feature\n" ) +
80 QObject::tr(
"- TR_ID: ID of the transect. Each transect have an unique ID\n" ) +
81 QObject::tr(
"- TR_SEGMENT: ID of the segment of the linestring\n" ) +
82 QObject::tr(
"- TR_ANGLE: Angle in degrees from the original line at the vertex\n" ) +
83 QObject::tr(
"- TR_LENGTH: Total length of the transect returned\n" ) +
84 QObject::tr(
"- TR_ORIENT: Side of the transect (only on the left or right of the line, or both side)\n" );
88 QgsTransectAlgorithm *QgsTransectAlgorithm::createInstance()
const
90 return new QgsTransectAlgorithm();
95 const Side orientation =
static_cast< QgsTransectAlgorithm::Side
>( parameterAsInt( parameters, QStringLiteral(
"SIDE" ), context ) );
96 const double angle = fabs( parameterAsDouble( parameters, QStringLiteral(
"ANGLE" ), context ) );
100 angleProperty = parameters.
value( QStringLiteral(
"ANGLE" ) ).value<
QgsProperty >();
102 double length = parameterAsDouble( parameters, QStringLiteral(
"LENGTH" ), context );
106 lengthProperty = parameters.
value( QStringLiteral(
"LENGTH" ) ).value<
QgsProperty >();
108 if ( orientation == QgsTransectAlgorithm::Both )
111 std::unique_ptr< QgsFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
119 fields.
append(
QgsField( QStringLiteral(
"TR_FID" ), QVariant::Int, QString(), 20 ) );
120 fields.
append(
QgsField( QStringLiteral(
"TR_ID" ), QVariant::Int, QString(), 20 ) );
121 fields.
append(
QgsField( QStringLiteral(
"TR_SEGMENT" ), QVariant::Int, QString(), 20 ) );
122 fields.
append(
QgsField( QStringLiteral(
"TR_ANGLE" ), QVariant::Double, QString(), 5, 2 ) );
123 fields.
append(
QgsField( QStringLiteral(
"TR_LENGTH" ), QVariant::Double, QString(), 20, 6 ) );
124 fields.
append(
QgsField( QStringLiteral(
"TR_ORIENT" ), QVariant::Int, QString(), 1 ) );
133 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, fields,
142 const double step = source->featureCount() > 0 ? 100.0 / source->featureCount() : 1;
160 if ( dynamicLength || dynamicAngle )
165 double evaluatedLength = length;
168 double evaluatedAngle =
angle;
181 const int i = vertexId.
vertex;
184 attrs << current << number << i + 1 << evaluatedAngle <<
185 ( ( orientation == QgsTransectAlgorithm::Both ) ? evaluatedLength * 2 : evaluatedLength ) <<
188 const double angleAtVertex = line->
vertexAngle( vertexId );
189 outFeat.
setGeometry( calcTransect( *it, angleAtVertex, evaluatedLength, orientation, evaluatedAngle ) );
199 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
204 QgsGeometry QgsTransectAlgorithm::calcTransect(
const QgsPoint &point,
const double angleAtVertex,
const double length,
const QgsTransectAlgorithm::Side orientation,
const double angle )
211 if ( ( orientation == QgsTransectAlgorithm::Right ) || ( orientation == QgsTransectAlgorithm::Both ) )
213 pLeft = point.
project( length,
angle + 180.0 / M_PI * angleAtVertex );
214 if ( orientation != QgsTransectAlgorithm::Both )
218 if ( ( orientation == QgsTransectAlgorithm::Left ) || ( orientation == QgsTransectAlgorithm::Both ) )
220 pRight = point.
project( -length,
angle + 180.0 / M_PI * angleAtVertex );
221 if ( orientation != QgsTransectAlgorithm::Both )
225 line.append( pLeft );
226 line.append( pRight );
vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setProgress(double progress)
Sets the current progress for the feedback object.
@ Double
Double/float values.
A store for object properties.
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...
Point geometry type, with support for z-dimension and m-values.
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.
Container of fields for a vector layer.
Multi line string geometry collection.
static Type addZ(Type type) SIP_HOLDGIL
Adds the z dimension to a WKB type and returns the new type.
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
@ Double
Double value (including negative values)
@ TypeVectorLine
Vector line layers.
An input feature source (such as vector layers) parameter for processing algorithms.
Type
The WKB type describes the number of dimensions a geometry has.
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)
Line string geometry type, with support for z-dimension and m-values.
QVariant value(const QgsExpressionContext &context, const QVariant &defaultValue=QVariant(), bool *ok=nullptr) const
Calculates the current value of the property, including any transforms which are set for the property...
QgsPoint project(double distance, double azimuth, double inclination=90.0) const SIP_HOLDGIL
Returns a new point which corresponds to this point projected by a specified distance with specified ...
int numGeometries() const SIP_HOLDGIL
Returns the number of geometries within the collection.
A feature sink output for processing algorithms.
static Type addM(Type type) SIP_HOLDGIL
Adds the m dimension to a WKB type and returns the new type.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Contains information about the context in which a processing algorithm is executed.
vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
static bool hasM(Type type) SIP_HOLDGIL
Tests whether a WKB type contains m values.
Definition for a property.
QgsVertexId vertexId() const
Returns vertex ID of the current item.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
QgsPointSequence QgsPolyline
Polyline as represented as a vector of points.
The vertex_iterator class provides STL-style iterator for vertices.
bool nextFeature(QgsFeature &f)
A geometry is the spatial representation of a feature.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
QgsLineString * lineStringN(int index)
Returns the line string with the specified index.
QgsExpressionContext & expressionContext()
Returns the expression context.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
QgsFeatureSource subclass which proxies methods to an underlying QgsFeatureSource,...
Utility class for identifying a unique vertex within a geometry.
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.
static bool hasZ(Type type) SIP_HOLDGIL
Tests whether a WKB type contains the z-dimension.
A vector of attributes. Mostly equal to QVector<QVariant>.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
An enum based parameter for processing algorithms, allowing for selection from predefined values.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
Wrapper for iterator of features from vector data provider or vector layer.
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)
Custom exception class for processing related exceptions.
double vertexAngle(QgsVertexId vertex) const override
Returns approximate angle at a vertex.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
@ DoublePositive
Positive double value (including 0)
Encapsulate a field in an attribute table or data source.