90 if ( outputAttrs != OutputBA )
99 attrs.resize( outputAttrs == OutputA ? fieldsCountA : ( fieldsCountA + fieldsCountB ) );
101 if ( totalCount == 0 )
107 if ( outputAttrs == OutputBA )
123 if ( outputAttrs != OutputBA )
126 std::unique_ptr< QgsGeometryEngine > engine;
127 if ( !intersects.isEmpty() )
131 engine->prepareGeometry();
134 QVector<QgsGeometry> geometriesB;
146 if ( !geometriesB.isEmpty() )
161 if ( !sanitizeDifferenceResult( geom, geometryType ) )
165 switch ( outputAttrs )
171 for (
int i = 0; i < fieldsCountA; ++i )
172 attrs[i] = attrsA[i];
175 for (
int i = 0; i < fieldsCountA; ++i )
176 attrs[i + fieldsCountB] = attrsA[i];
192 feedback->
setProgress( count /
static_cast< double >( totalCount ) * 100. );
200 int attrCount = fieldIndicesA.count() + fieldIndicesB.count();
211 if ( totalCount == 0 )
232 std::unique_ptr< QgsGeometryEngine > engine;
233 if ( !intersects.isEmpty() )
237 engine->prepareGeometry();
242 for (
int i = 0; i < fieldIndicesA.count(); ++i )
243 outAttributes[i] = attrsA[fieldIndicesA[i]];
253 if ( !engine->intersects( tmpGeom.constGet() ) )
257 if ( !sanitizeIntersectionResult( intGeom, geometryType ) )
261 for (
int i = 0; i < fieldIndicesB.count(); ++i )
262 outAttributes[fieldIndicesA.count() + i] = attrsB[fieldIndicesB[i]];
270 feedback->
setProgress( count /
static_cast<double >( totalCount ) * 100. );
278 if ( totalCount == 0 )
297 QSet<QgsFeatureId> fids;
304 fids.insert( f.
id() );
307 QHash<QgsFeatureId, QgsGeometry> geometries;
309 QHash<QgsFeatureId, QList<QgsFeatureId> > intersectingIds;
321 std::unique_ptr< QgsGeometryEngine > g1engine;
323 geometries.insert( fid1, g1 );
327 const QList<QgsFeatureId> ids = index.
intersects( bbox );
337 g1engine->prepareGeometry();
341 if ( !g1engine->intersects( g2.
constGet() ) )
345 if ( !sanitizeIntersectionResult( geomIntersection, geometryType ) )
353 while ( fids.contains( newFid ) )
355 fids.insert( newFid );
357 geometries.insert( newFid, geomIntersection );
359 fx.setGeometry( geomIntersection );
365 QList<QgsFeatureId> lst;
366 if ( intersectingIds.contains( fid1 ) )
367 lst << intersectingIds.value( fid1 );
370 if ( intersectingIds.contains( fid2 ) )
371 lst << intersectingIds.value( fid2 );
374 intersectingIds.insert( newFid, lst );
383 geometries.remove( fid1 );
385 if ( sanitizeDifferenceResult( g12, geometryType ) )
387 geometries.insert( fid1, g12 );
390 f1x.setGeometry( g12 );
401 f2old.setGeometry( g2 );
404 geometries.remove( fid2 );
406 if ( sanitizeDifferenceResult( g21, geometryType ) )
408 geometries.insert( fid2, g21 );
411 f2x.setGeometry( g21 );
421 feedback->
setProgress( count /
static_cast< double >( totalCount ) * 100. );
433 QHash<QgsFeatureId, QgsAttributes> attributesHash;
445 for (
auto i = geometries.constBegin(); i != geometries.constEnd(); ++i )
451 outFeature.setGeometry( i.value() );
453 if ( intersectingIds.contains( i.key() ) )
455 const QList<QgsFeatureId> ids = intersectingIds.value( i.key() );
458 outFeature.setAttributes( attributesHash.value(
id ) );
464 outFeature.setAttributes( attributesHash.value( i.key() ) );
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets feature IDs that should be fetched.
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will 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.
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
QgsFeatureRequest & setInvalidGeometryCheck(InvalidGeometryCheck check)
Sets invalid geometry checking behavior.
An interface for objects which accept features via addFeature(s) methods.
virtual bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())
Adds a single feature to the sink.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
An interface for objects which provide features via a getFeatures method.
virtual QgsFields fields() const =0
Returns the fields associated with features in the source.
virtual QgsCoordinateReferenceSystem sourceCrs() const =0
Returns the coordinate reference system for features in the source.
virtual QgsWkbTypes::Type wkbType() const =0
Returns the geometry type for features returned by this source.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const =0
Returns an iterator for the features in the source.
virtual long long featureCount() const =0
Returns the number of features contained in the source, or -1 if the feature count is unknown.
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.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
int count() const
Returns number of items.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
QgsGeometry difference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other.
static QgsGeometry unaryUnion(const QVector< QgsGeometry > &geometries)
Compute the unary union on a list of geometries.
QgsGeometry intersection(const QgsGeometry &geometry) const
Returns a geometry representing the points shared by this geometry and other.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine representing the specified geometry.
QString lastError() const SIP_HOLDGIL
Returns an error string referring to the last error encountered either when this geometry was created...
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
bool convertGeometryCollectionToSubclass(QgsWkbTypes::GeometryType geomType)
Converts geometry collection to a the desired geometry type subclass (multi-point,...
Contains information about the context in which a processing algorithm is executed.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
QgsFeatureRequest::InvalidGeometryCheck invalidGeometryCheck() const
Returns the behavior used for checking invalid geometries in input layers.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
A rectangle specified with double values.
A spatial index for QgsFeature objects.
QList< QgsFeatureId > intersects(const QgsRectangle &rectangle) const
Returns a list of features with a bounding box which intersects the specified rectangle.
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) override
Adds a feature to the index.
bool deleteFeature(const QgsFeature &feature)
Removes a feature from the index.
static GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
static Type multiType(Type type) SIP_HOLDGIL
Returns the multi type for a WKB type.
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features