58 static bool sanitizeDifferenceResult(
QgsGeometry &geom )
82 if ( outputAttrs != OutputBA )
89 attrs.resize( outputAttrs == OutputA ? fieldsCountA : ( fieldsCountA + fieldsCountB ) );
91 if ( totalCount == 0 )
96 if ( outputAttrs == OutputBA )
112 if ( outputAttrs != OutputBA )
115 std::unique_ptr< QgsGeometryEngine > engine;
116 if ( !intersects.isEmpty() )
120 engine->prepareGeometry();
123 QVector<QgsGeometry> geometriesB;
135 if ( !geometriesB.isEmpty() )
141 if ( !sanitizeDifferenceResult( geom ) )
145 switch ( outputAttrs )
151 for (
int i = 0; i < fieldsCountA; ++i )
152 attrs[i] = attrsA[i];
155 for (
int i = 0; i < fieldsCountA; ++i )
156 attrs[i + fieldsCountB] = attrsA[i];
172 feedback->
setProgress( count / (
double ) totalCount * 100. );
180 int attrCount = fieldIndicesA.count() + fieldIndicesB.count();
189 if ( totalCount == 0 )
210 std::unique_ptr< QgsGeometryEngine > engine;
211 if ( !intersects.isEmpty() )
215 engine->prepareGeometry();
220 for (
int i = 0; i < fieldIndicesA.count(); ++i )
221 outAttributes[i] = attrsA[fieldIndicesA[i]];
231 if ( !engine->intersects( tmpGeom.constGet() ) )
235 if ( !sanitizeIntersectionResult( intGeom, geometryType ) )
239 for (
int i = 0; i < fieldIndicesB.count(); ++i )
240 outAttributes[fieldIndicesA.count() + i] = attrsB[fieldIndicesB[i]];
248 feedback->
setProgress( count / (
double ) totalCount * 100. );
256 if ( totalCount == 0 )
275 QSet<QgsFeatureId> fids;
282 fids.insert( f.
id() );
285 QHash<QgsFeatureId, QgsGeometry> geometries;
287 QHash<QgsFeatureId, QList<QgsFeatureId> > intersectingIds;
299 std::unique_ptr< QgsGeometryEngine > g1engine;
301 geometries.insert( fid1, g1 );
305 const QList<QgsFeatureId> ids = index.
intersects( bbox );
315 g1engine->prepareGeometry();
319 if ( !g1engine->intersects( g2.
constGet() ) )
323 if ( !sanitizeIntersectionResult( geomIntersection, geometryType ) )
331 while ( fids.contains( newFid ) )
333 fids.insert( newFid );
335 geometries.insert( newFid, geomIntersection );
337 fx.setGeometry( geomIntersection );
343 QList<QgsFeatureId> lst;
344 if ( intersectingIds.contains( fid1 ) )
345 lst << intersectingIds.value( fid1 );
348 if ( intersectingIds.contains( fid2 ) )
349 lst << intersectingIds.value( fid2 );
352 intersectingIds.insert( newFid, lst );
361 geometries.remove( fid1 );
363 if ( sanitizeDifferenceResult( g12 ) )
365 geometries.insert( fid1, g12 );
368 f1x.setGeometry( g12 );
379 f2old.setGeometry( g2 );
382 geometries.remove( fid2 );
384 if ( sanitizeDifferenceResult( g21 ) )
386 geometries.insert( fid2, g21 );
389 f2x.setGeometry( g21 );
399 feedback->
setProgress( count / (
double ) totalCount * 100. );
409 QHash<QgsFeatureId, QgsAttributes> attributesHash;
421 for (
auto i = geometries.constBegin(); i != geometries.constEnd(); ++i )
429 if ( intersectingIds.contains( i.key() ) )
431 const QList<QgsFeatureId> ids = intersectingIds.value( i.key() );
434 outFeature.setAttributes( attributesHash.value(
id ) );
440 outFeature.setAttributes( attributesHash.value( i.key() ) );
bool convertGeometryCollectionToSubclass(QgsWkbTypes::GeometryType geomType)
Converts geometry collection to a the desired geometry type subclass (multi-point, multi-linestring or multi-polygon).
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...
A rectangle specified with double values.
static Type multiType(Type type)
Returns the multi type for a WKB type.
Base class for providing feedback from a processing algorithm.
virtual QgsFields fields() const =0
Returns the fields associated with features in the source.
bool isNull() const
Returns true if the geometry is null (ie, contains no underlying geometry accessible via geometry() )...
QSet< QgsFeatureId > QgsFeatureIds
QgsWkbTypes::Type wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
virtual QgsWkbTypes::Type wkbType() const =0
Returns the geometry type for features returned by this source.
void setProgress(double progress)
Sets the current progress for the feedback object.
An interface for objects which accept features via addFeature(s) methods.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
A geometry is the spatial representation of a feature.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
bool insertFeature(const QgsFeature &feature)
Adds a feature to the index.
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.
bool intersects(const QgsRectangle &rectangle) const
Returns true if this geometry exactly intersects with a rectangle.
static GeometryType geometryType(Type type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
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 isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
virtual bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=nullptr)
Adds a single feature to the sink.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
virtual QgsCoordinateReferenceSystem sourceCrs() const =0
Returns the coordinate reference system for features in the source.
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.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
bool deleteFeature(const QgsFeature &feature)
Removes a feature from the index.
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
A spatial index for QgsFeature objects.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets feature IDs that should be fetched.
bool isCanceled() const
Tells whether the operation has been canceled already.
An interface for objects which provide features via a getFeatures method.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
QList< int > QgsAttributeList
bool nextFeature(QgsFeature &f)
Geometry is not required. It may still be returned if e.g. required for a filter condition.
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 unaryUnion(const QVector< QgsGeometry > &geometries)
Compute the unary union on a list of geometries.
QList< QgsFeatureId > intersects(const QgsRectangle &rectangle) const
Returns a list of features with a bounding box which intersects the specified rectangle.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const =0
Returns an iterator for the features in the source.
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
virtual long featureCount() const =0
Returns the number of features contained in the source, or -1 if the feature count is unknown...
QgsGeometry difference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other...