24QString QgsLineIntersectionAlgorithm::name()
const
26 return QStringLiteral(
"lineintersections" );
29QString QgsLineIntersectionAlgorithm::displayName()
const
31 return QObject::tr(
"Line intersections" );
34QStringList QgsLineIntersectionAlgorithm::tags()
const
36 return QObject::tr(
"line,intersection" ).split(
',' );
39QString QgsLineIntersectionAlgorithm::group()
const
41 return QObject::tr(
"Vector overlay" );
44QString QgsLineIntersectionAlgorithm::groupId()
const
46 return QStringLiteral(
"vectoroverlay" );
49void QgsLineIntersectionAlgorithm::initAlgorithm(
const QVariantMap & )
57 QStringLiteral(
"INPUT_FIELDS" ),
58 QObject::tr(
"Input fields to keep (leave empty to keep all fields)" ), QVariant(),
62 QStringLiteral(
"INTERSECT_FIELDS" ),
63 QObject::tr(
"Intersect fields to keep (leave empty to keep all fields)" ), QVariant(),
67 std::unique_ptr< QgsProcessingParameterString > prefix = std::make_unique< QgsProcessingParameterString >( QStringLiteral(
"INTERSECT_FIELDS_PREFIX" ), QObject::tr(
"Intersect fields prefix" ), QString(),
false,
true );
69 addParameter( prefix.release() );
74QString QgsLineIntersectionAlgorithm::shortHelpString()
const
76 return QObject::tr(
"This algorithm creates point features where the lines in the Intersect layer intersect the lines in the Input layer." );
84QgsLineIntersectionAlgorithm *QgsLineIntersectionAlgorithm::createInstance()
const
86 return new QgsLineIntersectionAlgorithm();
91 std::unique_ptr< QgsFeatureSource > sourceA( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
95 std::unique_ptr< QgsFeatureSource > sourceB( parameterAsSource( parameters, QStringLiteral(
"INTERSECT" ), context ) );
99 const QStringList fieldsA = parameterAsStrings( parameters, QStringLiteral(
"INPUT_FIELDS" ), context );
100 const QStringList fieldsB = parameterAsStrings( parameters, QStringLiteral(
"INTERSECT_FIELDS" ), context );
105 QString intersectFieldsPrefix = parameterAsString( parameters, QStringLiteral(
"INTERSECT_FIELDS_PREFIX" ), context );
109 intersectFieldsPrefix );
119 double step = sourceA->featureCount() > 0 ? 100.0 / sourceA->featureCount() : 1;
135 if ( !lines.empty() )
139 engine->prepareGeometry();
155 if ( engine->intersects( tmpGeom.
constGet() ) )
160 for (
int a : std::as_const( fieldIndicesA ) )
162 outAttributes.append( inFeatureA.
attribute( a ) );
164 for (
int b : std::as_const( fieldIndicesB ) )
166 outAttributes.append( inFeatureB.
attribute( b ) );
175 if ( part.isMultipart() )
177 points = part.asMultiPoint();
181 points.append( part.asPoint() );
194 points.append( intersectGeom.
asPoint() );
197 for (
const QgsPointXY &j : std::as_const( points ) )
213 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
@ VectorPoint
Vector point layers.
@ VectorLine
Vector line layers.
@ RegeneratesPrimaryKey
Algorithm always drops any existing primary keys or FID values and regenerates them in outputs.
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
@ GeometryCollection
GeometryCollection.
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets the feature IDs that should be fetched.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
QgsMultiPointXY asMultiPoint() const
Returns the contents of the geometry as a multi-point.
QVector< QgsGeometry > asGeometryCollection() const
Returns contents of the geometry as a list of geometries.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QgsGeometry intersection(const QgsGeometry &geometry, const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Returns a geometry representing the points shared by this geometry and other.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry, double precision=0.0)
Creates and returns a new geometry engine representing the specified geometry using precision on a gr...
Qgis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
A class to represent a 2D point.
Contains information about the context in which a processing algorithm is executed.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
A vector layer or feature source field parameter for processing algorithms.
static QgsFields indicesToFields(const QList< int > &indices, const QgsFields &fields)
Returns a subset of fields based on the indices of desired fields.
static QList< int > fieldNamesToIndices(const QStringList &fieldNames, const QgsFields &fields)
Returns a list of field indices parsed from the given list of field names.
static QgsFields combineFields(const QgsFields &fieldsA, const QgsFields &fieldsB, const QString &fieldsBPrefix=QString())
Combines two field lists, avoiding duplicate field names (in a case-insensitive manner).
A spatial index for QgsFeature objects.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
QSet< QgsFeatureId > QgsFeatureIds
QList< int > QgsAttributeList
QVector< QgsPointXY > QgsMultiPointXY
A collection of QgsPoints that share a common collection of attributes.