25using namespace Qt::StringLiterals;
29QString QgsLineIntersectionAlgorithm::name()
const
31 return u
"lineintersections"_s;
34QString QgsLineIntersectionAlgorithm::displayName()
const
36 return QObject::tr(
"Line intersections" );
39QStringList QgsLineIntersectionAlgorithm::tags()
const
41 return QObject::tr(
"line,intersection" ).split(
',' );
44QString QgsLineIntersectionAlgorithm::group()
const
46 return QObject::tr(
"Vector overlay" );
49QString QgsLineIntersectionAlgorithm::groupId()
const
51 return u
"vectoroverlay"_s;
54void QgsLineIntersectionAlgorithm::initAlgorithm(
const QVariantMap & )
61 QObject::tr(
"Input fields to keep (leave empty to keep all fields)" ), QVariant(),
66 u
"INTERSECT_FIELDS"_s,
67 QObject::tr(
"Intersect fields to keep (leave empty to keep all fields)" ), QVariant(),
72 auto prefix = std::make_unique<QgsProcessingParameterString>( u
"INTERSECT_FIELDS_PREFIX"_s, QObject::tr(
"Intersect fields prefix" ), QString(),
false,
true );
74 addParameter( prefix.release() );
79QString QgsLineIntersectionAlgorithm::shortHelpString()
const
81 return QObject::tr(
"This algorithm creates point features where the lines in the Intersect layer intersect the lines in the Input layer." );
84QString QgsLineIntersectionAlgorithm::shortDescription()
const
86 return QObject::tr(
"Creates point features at the intersection of lines from two different layers." );
94QgsLineIntersectionAlgorithm *QgsLineIntersectionAlgorithm::createInstance()
const
96 return new QgsLineIntersectionAlgorithm();
101 std::unique_ptr<QgsFeatureSource> sourceA( parameterAsSource( parameters, u
"INPUT"_s, context ) );
105 std::unique_ptr<QgsFeatureSource> sourceB( parameterAsSource( parameters, u
"INTERSECT"_s, context ) );
109 const QStringList fieldsA = parameterAsStrings( parameters, u
"INPUT_FIELDS"_s, context );
110 const QStringList fieldsB = parameterAsStrings( parameters, u
"INTERSECT_FIELDS"_s, context );
115 QString intersectFieldsPrefix = parameterAsString( parameters, u
"INTERSECT_FIELDS_PREFIX"_s, context );
119 intersectFieldsPrefix
130 double step = sourceA->featureCount() > 0 ? 100.0 / sourceA->featureCount() : 1;
146 if ( !lines.empty() )
150 engine->prepareGeometry();
166 if ( engine->intersects( tmpGeom.
constGet() ) )
171 for (
int a : std::as_const( fieldIndicesA ) )
173 outAttributes.append( inFeatureA.
attribute( a ) );
175 for (
int b : std::as_const( fieldIndicesB ) )
177 outAttributes.append( inFeatureB.
attribute( b ) );
186 if ( part.isMultipart() )
188 points = part.asMultiPoint();
192 points.append( part.asPoint() );
205 points.append( intersectGeom.
asPoint() );
208 for (
const QgsPointXY &j : std::as_const( points ) )
225 outputs.insert( u
"OUTPUT"_s, 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.
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.
Qgis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.).
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry, double precision=0.0, Qgis::GeosCreationFlags flags=Qgis::GeosCreationFlag::SkipEmptyInteriorRings)
Creates and returns a new geometry engine representing the specified geometry using precision on a gr...
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.