QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
57 static bool sanitizeDifferenceResult(
QgsGeometry &geom )
81 if ( outputAttrs != OutputBA )
88 attrs.resize( outputAttrs == OutputA ? fieldsCountA : ( fieldsCountA + fieldsCountB ) );
90 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() )
150 if ( !sanitizeDifferenceResult( geom ) )
154 switch ( outputAttrs )
160 for (
int i = 0; i < fieldsCountA; ++i )
161 attrs[i] = attrsA[i];
164 for (
int i = 0; i < fieldsCountA; ++i )
165 attrs[i + fieldsCountB] = attrsA[i];
181 feedback->
setProgress( count / (
double ) totalCount * 100. );
189 int attrCount = fieldIndicesA.count() + fieldIndicesB.count();
198 if ( totalCount == 0 )
219 std::unique_ptr< QgsGeometryEngine > engine;
220 if ( !intersects.isEmpty() )
224 engine->prepareGeometry();
229 for (
int i = 0; i < fieldIndicesA.count(); ++i )
230 outAttributes[i] = attrsA[fieldIndicesA[i]];
240 if ( !engine->intersects( tmpGeom.constGet() ) )
244 if ( !sanitizeIntersectionResult( intGeom, geometryType ) )
248 for (
int i = 0; i < fieldIndicesB.count(); ++i )
249 outAttributes[fieldIndicesA.count() + i] = attrsB[fieldIndicesB[i]];
257 feedback->
setProgress( count / (
double ) totalCount * 100. );
265 if ( totalCount == 0 )
284 QSet<QgsFeatureId> fids;
291 fids.insert( f.
id() );
294 QHash<QgsFeatureId, QgsGeometry> geometries;
296 QHash<QgsFeatureId, QList<QgsFeatureId> > intersectingIds;
308 std::unique_ptr< QgsGeometryEngine > g1engine;
310 geometries.insert( fid1, g1 );
314 const QList<QgsFeatureId> ids = index.
intersects( bbox );
324 g1engine->prepareGeometry();
328 if ( !g1engine->intersects( g2.
constGet() ) )
332 if ( !sanitizeIntersectionResult( geomIntersection, geometryType ) )
340 while ( fids.contains( newFid ) )
342 fids.insert( newFid );
344 geometries.insert( newFid, geomIntersection );
346 fx.setGeometry( geomIntersection );
352 QList<QgsFeatureId> lst;
353 if ( intersectingIds.contains( fid1 ) )
354 lst << intersectingIds.value( fid1 );
357 if ( intersectingIds.contains( fid2 ) )
358 lst << intersectingIds.value( fid2 );
361 intersectingIds.insert( newFid, lst );
370 geometries.remove( fid1 );
372 if ( sanitizeDifferenceResult( g12 ) )
374 geometries.insert( fid1, g12 );
377 f1x.setGeometry( g12 );
388 f2old.setGeometry( g2 );
391 geometries.remove( fid2 );
393 if ( sanitizeDifferenceResult( g21 ) )
395 geometries.insert( fid2, g21 );
398 f2x.setGeometry( g21 );
408 feedback->
setProgress( count / (
double ) totalCount * 100. );
418 QHash<QgsFeatureId, QgsAttributes> attributesHash;
430 for (
auto i = geometries.constBegin(); i != geometries.constEnd(); ++i )
436 outFeature.setGeometry( i.value() );
438 if ( intersectingIds.contains( i.key() ) )
440 const QList<QgsFeatureId> ids = intersectingIds.value( i.key() );
443 outFeature.setAttributes( attributesHash.value(
id ) );
449 outFeature.setAttributes( attributesHash.value( i.key() ) );
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
static Type multiType(Type type)
Returns the multi type for a WKB type.
void setProgress(double progress)
Sets the current progress for the feedback object.
bool deleteFeature(const QgsFeature &feature)
Removes a feature from the index.
virtual QgsCoordinateReferenceSystem sourceCrs() const =0
Returns the coordinate reference system for features in the source.
QgsFeatureRequest & setInvalidGeometryCheck(InvalidGeometryCheck check)
Sets invalid geometry checking behavior.
bool convertGeometryCollectionToSubclass(QgsWkbTypes::GeometryType geomType)
Converts geometry collection to a the desired geometry type subclass (multi-point,...
virtual bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())
Adds a single feature to the sink.
int count() const
Returns number of items.
QgsWkbTypes::Type wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsGeometry intersection(const QgsGeometry &geometry) const
Returns a geometry representing the points shared by this geometry and other.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
QgsFeatureRequest::InvalidGeometryCheck invalidGeometryCheck() const
Returns the behavior used for checking invalid geometries in input layers.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const =0
Returns an iterator for the features in the source.
static GeometryType geometryType(Type type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets feature IDs that should be fetched.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
QSet< QgsFeatureId > QgsFeatureIds
virtual QgsFields fields() const =0
Returns the fields associated with features in the source.
virtual long featureCount() const =0
Returns the number of features contained in the source, or -1 if the feature count is unknown.
bool isCanceled() const
Tells whether the operation has been canceled already.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
bool nextFeature(QgsFeature &f)
virtual QgsWkbTypes::Type wkbType() const =0
Returns the geometry type for features returned by this source.
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
QList< QgsFeatureId > intersects(const QgsRectangle &rectangle) const
Returns a list of features with a bounding box which intersects the specified rectangle.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) override
Adds a feature to the index.
QgsGeometry difference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other.
static Type flatType(Type type)
Returns the flat type for a WKB type.
static QgsGeometry unaryUnion(const QVector< QgsGeometry > &geometries)
Compute the unary union on a list of geometries.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...