23 QString QgsLineIntersectionAlgorithm::name()
const 25 return QStringLiteral(
"lineintersections" );
28 QString QgsLineIntersectionAlgorithm::displayName()
const 30 return QObject::tr(
"Line intersections" );
33 QStringList QgsLineIntersectionAlgorithm::tags()
const 35 return QObject::tr(
"line,intersection" ).split(
',' );
38 QString QgsLineIntersectionAlgorithm::group()
const 40 return QObject::tr(
"Vector overlay" );
43 QString QgsLineIntersectionAlgorithm::groupId()
const 45 return QStringLiteral(
"vectoroverlay" );
48 void QgsLineIntersectionAlgorithm::initAlgorithm(
const QVariantMap & )
56 QStringLiteral(
"INPUT_FIELDS" ),
57 QObject::tr(
"Input fields to keep (leave empty to keep all fields)" ), QVariant(),
61 QStringLiteral(
"INTERSECT_FIELDS" ),
62 QObject::tr(
"Intersect fields to keep (leave empty to keep all fields)" ), QVariant(),
69 QString QgsLineIntersectionAlgorithm::shortHelpString()
const 71 return QObject::tr(
"This algorithm creates point features where the lines in the Intersect layer intersect the lines in the Input layer." );
74 QgsLineIntersectionAlgorithm *QgsLineIntersectionAlgorithm::createInstance()
const 76 return new QgsLineIntersectionAlgorithm();
81 std::unique_ptr< QgsFeatureSource > sourceA( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
85 std::unique_ptr< QgsFeatureSource > sourceB( parameterAsSource( parameters, QStringLiteral(
"INTERSECT" ), context ) );
89 const QStringList fieldsA = parameterAsFields( parameters, QStringLiteral(
"INPUT_FIELDS" ), context );
90 const QStringList fieldsB = parameterAsFields( parameters, QStringLiteral(
"INTERSECT_FIELDS" ), context );
95 if ( fieldsA.empty() )
97 outFieldsA = sourceA->fields();
98 for (
int i = 0; i < outFieldsA.
count(); ++i )
105 for (
const QString &field : fieldsA )
107 int index = sourceA->fields().
lookupField( field );
110 fieldsAIndices << index;
111 outFieldsA.
append( sourceA->fields().at( index ) );
119 if ( fieldsB.empty() )
121 outFieldsB = sourceB->fields();
122 for (
int i = 0; i < outFieldsB.
count(); ++i )
129 for (
const QString &field : fieldsB )
131 int index = sourceB->fields().
lookupField( field );
134 fieldsBIndices << index;
135 outFieldsB.
append( sourceB->fields().at( index ) );
143 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, outFields,
QgsWkbTypes::Point, sourceA->sourceCrs() ) );
150 double step = sourceA->featureCount() > 0 ? 100.0 / sourceA->featureCount() : 1;
166 if ( !lines.empty() )
170 engine->prepareGeometry();
186 if ( engine->intersects( tmpGeom.
constGet() ) )
191 for (
int a : qgis::as_const( fieldsAIndices ) )
193 outAttributes.append( inFeatureA.
attribute( a ) );
195 for (
int b : qgis::as_const( fieldsBIndices ) )
197 outAttributes.append( inFeatureB.
attribute( b ) );
206 if ( part.isMultipart() )
208 points = part.asMultiPoint();
212 points.append( part.asPoint() );
225 points.append( intersectGeom.
asPoint() );
228 for (
const QgsPointXY &j : qgis::as_const( points ) )
231 outFeature.setAttributes( outAttributes );
243 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries.
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...
QSet< QgsFeatureId > QgsFeatureIds
Base class for providing feedback from a processing algorithm.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
A vector layer or feature source field parameter for processing algorithms.
QgsWkbTypes::Type wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
A class to represent a 2D point.
void setProgress(double progress)
Sets the current progress for the feedback object.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
QVector< QgsPointXY > QgsMultiPointXY
A collection of QgsPoints that share a common collection of attributes.
QgsGeometry intersection(const QgsGeometry &geometry) const
Returns a geometry representing the points shared by this geometry and other.
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.
int count() const
Returns number of items.
A feature sink output for processing algorithms.
bool intersects(const QgsRectangle &rectangle) const
Returns true if this geometry exactly intersects with a rectangle.
QVector< QgsGeometry > asGeometryCollection() const
Returns contents of the geometry as a list of geometries.
static QgsFields combineFields(const QgsFields &fieldsA, const QgsFields &fieldsB)
Combines two field lists, avoiding duplicate field names (in a case-insensitive manner).
This class wraps a request for features to a vector layer (or directly its vector data provider)...
Custom exception class for processing related exceptions.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
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) ...
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
A spatial index for QgsFeature objects.
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets feature IDs that should be fetched.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
bool isCanceled() const
Tells whether the operation has been canceled already.
An input feature source (such as vector layers) parameter for processing algorithms.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
QgsMultiPointXY asMultiPoint() const
Returns the contents of the geometry as a multi-point.
QgsWkbTypes::GeometryType type
QList< int > QgsAttributeList
bool nextFeature(QgsFeature &f)
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
static Type flatType(Type type)
Returns the flat type for a WKB type.
Contains information about the context in which a processing algorithm is executed.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.