36 QVector< QgsCurvePolygon * > polygonList;
37 QgsCurvePolygon *curvePoly = qgsgeometry_cast< QgsCurvePolygon * >( geom );
41 polygonList.append( curvePoly );
48 polygonList.append( qgsgeometry_cast< QgsCurvePolygon * >( multiGeom->
geometryN( i ) ) );
53 return QgsGeometry::OperationResult::InvalidInputGeometryType;
57 if ( !ring->isClosed() )
59 return QgsGeometry::OperationResult::AddRingNotClosed;
61 else if ( !ring->isRing() )
63 return QgsGeometry::OperationResult::AddRingNotValid;
67 ringGeom->prepareGeometry();
70 QVector< QgsCurvePolygon * >::const_iterator polyIter = polygonList.constBegin();
71 for ( ; polyIter != polygonList.constEnd(); ++polyIter )
73 if ( ringGeom->within( *polyIter ) )
76 int nInnerRings = ( *polyIter )->numInteriorRings();
77 for (
int i = 0; i < nInnerRings; ++i )
79 if ( !ringGeom->disjoint( ( *polyIter )->interiorRing( i ) ) )
81 return QgsGeometry::OperationResult::AddRingCrossesExistingRings;
91 ( *polyIter )->addInteriorRing( ring.release() );
92 return QgsGeometry::OperationResult::Success;
95 return QgsGeometry::OperationResult::AddRingNotInExistingFeature;
102 return QgsGeometry::OperationResult::InvalidBaseGeometry;
107 return QgsGeometry::OperationResult::InvalidInputGeometryType;
112 if ( !geomCollection )
114 return QgsGeometry::OperationResult::AddPartNotMultiGeometry;
121 QgsCurve *curve = qgsgeometry_cast<QgsCurve *>( part.get() );
125 std::unique_ptr<QgsCurvePolygon> poly;
128 poly = std::make_unique< QgsPolygon >();
132 poly = std::make_unique< QgsCurvePolygon >();
137 poly->setExteriorRing( curve );
138 added = geomCollection->
addGeometry( poly.release() );
144 added = geomCollection->
addGeometry( part.release() );
149 std::unique_ptr<QgsGeometryCollection> parts(
static_cast<QgsGeometryCollection *
>( part.release() ) );
153 for ( i = 0; i < parts->numGeometries() && geomCollection->
addGeometry( parts->geometryN( i )->clone() ); i++ )
156 added = i == parts->numGeometries();
161 return QgsGeometry::OperationResult::InvalidInputGeometryType;
166 return QgsGeometry::OperationResult::InvalidInputGeometryType;
171 added = geomCollection->
addGeometry( part.release() );
178 if ( !geom || partNum < 0 )
192 g =
c->geometryN( partNum );
194 else if ( partNum > 0 )
222 return c->removeGeometry( partNum );
226 const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
227 bool &haveInvalidGeometry,
228 const QHash<
QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures
232 haveInvalidGeometry =
false;
247 if ( avoidIntersectionsLayers.isEmpty() )
250 QVector< QgsGeometry > nearGeometries;
256 QHash<QgsVectorLayer *, QSet<qint64> >::const_iterator ignoreIt = ignoreFeatures.constFind( currentLayer );
257 if ( ignoreIt != ignoreFeatures.constEnd() )
258 ignoreIds = ignoreIt.value();
266 if ( ignoreIds.contains( f.
id() ) )
273 haveInvalidGeometry =
true;
279 if ( nearGeometries.isEmpty() )
284 std::unique_ptr< QgsAbstractGeometry > combinedGeometries( geomEngine->combine( nearGeometries ) );
285 if ( !combinedGeometries )
290 std::unique_ptr< QgsAbstractGeometry > diffGeom( geomEngine->difference( combinedGeometries.get() ) );
Abstract base class for all geometries.
virtual QgsRectangle boundingBox() const =0
Returns the minimal bounding box for the geometry.
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
Curve polygon geometry type.
bool removeInteriorRing(int ringIndex)
Removes an interior ring from the polygon.
Abstract base class for curved geometry type.
virtual int numPoints() const =0
Returns the number of points in the curve.
virtual bool isClosed() const SIP_HOLDGIL
Returns true if the curve is closed.
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 & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
int numGeometries() const SIP_HOLDGIL
Returns the number of geometries within the collection.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
virtual bool removeGeometry(int nr)
Removes a geometry from the collection.
virtual bool addGeometry(QgsAbstractGeometry *g)
Adds a geometry and takes ownership. Returns true in case of success.
static std::unique_ptr< QgsAbstractGeometry > avoidIntersections(const QgsAbstractGeometry &geom, const QList< QgsVectorLayer * > &avoidIntersectionsLayers, bool &haveInvalidGeometry, const QHash< QgsVectorLayer *, QSet< QgsFeatureId > > &ignoreFeatures=(QHash< QgsVectorLayer *, QSet< QgsFeatureId > >()))
Alters a geometry so that it avoids intersections with features from all open vector layers.
static bool deletePart(QgsAbstractGeometry *geom, int partNum)
Deletes a part from a geometry.
static QgsGeometry::OperationResult addRing(QgsAbstractGeometry *geometry, std::unique_ptr< QgsCurve > ring)
Add an interior ring to a geometry.
static QgsGeometry::OperationResult addPart(QgsAbstractGeometry *geometry, std::unique_ptr< QgsAbstractGeometry > part)
Add a part to multi type geometry.
static bool deleteRing(QgsAbstractGeometry *geom, int ringNum, int partNum=0)
Deletes a ring from a geometry.
bool isGeosValid(QgsGeometry::ValidityFlags flags=QgsGeometry::ValidityFlags()) const
Checks validity of the geometry using GEOS.
OperationResult
Success or failure of a geometry operation.
@ InvalidInputGeometryType
The input geometry (ring, part, split line, etc.) has not the correct geometry type.
@ Success
Operation succeeded.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine representing the specified geometry.
Represents a vector layer which manages a vector based data sets.
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...
static bool hasM(Type type) SIP_HOLDGIL
Tests whether a WKB type contains m values.
Type
The WKB type describes the number of dimensions a geometry has.
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
static bool hasZ(Type type) SIP_HOLDGIL
Tests whether a WKB type contains the z-dimension.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
QSet< QgsFeatureId > QgsFeatureIds