39 QVector< QgsCurvePolygon * > polygonList;
46 polygonList.append( curvePoly );
48 else if ( polySurface )
51 polygonList.reserve( polySurface->
numPatches() );
52 for (
int i = 0; i < polySurface->
numPatches(); ++i )
54 polygonList.append( polySurface->
patchN( i ) );
71 if ( !ring->isClosed() )
75 else if ( !ring->isRing() )
81 ringGeom->prepareGeometry();
84 QVector< QgsCurvePolygon * >::const_iterator polyIter = polygonList.constBegin();
85 for ( ; polyIter != polygonList.constEnd(); ++polyIter )
87 if ( ringGeom->within( *polyIter ) )
90 const int nInnerRings = ( *polyIter )->numInteriorRings();
91 for (
int i = 0; i < nInnerRings; ++i )
93 if ( !ringGeom->disjoint( ( *polyIter )->interiorRing( i ) ) )
101 ring->addZValue( 0 );
103 ring->addMValue( 0 );
105 ( *polyIter )->addInteriorRing( ring.release() );
142 if ( polygon->exteriorRing() && polygon->exteriorRing()->numPoints() == 4 )
144 auto triangle = std::make_unique<QgsTriangle>();
145 triangle->setExteriorRing( polygon->exteriorRing()->clone() );
146 if ( !triangle->isEmpty() )
148 tin->
addPatch( triangle.release() );
157 if ( curve->isClosed() && curve->numPoints() == 4 )
159 auto triangle = std::make_unique<QgsTriangle>();
160 triangle->setExteriorRing( curve->clone() );
161 if ( !triangle->isEmpty() )
163 tin->
addPatch( triangle.release() );
184 polySurface->
addPatch( polygon->clone() );
190 std::unique_ptr<QgsPolygon> polygon( curvePolygon->toPolygon() );
191 polySurface->
addPatch( polygon.release() );
197 if ( curve->isClosed() && curve->numPoints() >= 4 )
199 auto polygon = std::make_unique<QgsPolygon>();
200 polygon->setExteriorRing( curve->clone() );
201 polySurface->
addPatch( polygon.release() );
211 if ( !geomCollection )
224 std::unique_ptr<QgsCurvePolygon> poly;
227 poly = std::make_unique< QgsPolygon >();
231 poly = std::make_unique< QgsCurvePolygon >();
234 added = geomCollection->
addGeometry( poly.release() );
245 std::unique_ptr< QgsCurvePolygon > polygon( curvePolygon->toPolygon() );
246 part = std::move( polygon );
252 added = geomCollection->
addGeometry( part.release() );
258 std::unique_ptr<QgsGeometryCollection> parts(
static_cast<QgsGeometryCollection *
>( part.release() ) );
262 for ( i = 0; i < parts->numGeometries(); i++ )
264 if ( !geomCollection->
addGeometry( parts->geometryN( i )->clone() ) )
268 added = i == parts->numGeometries();
291 for ( i = 0; i < parts->numGeometries(); i++ )
293 if ( !geomCollection->
addGeometry( parts->geometryN( i )->clone() ) )
297 added = i == parts->numGeometries();
312 std::unique_ptr< QgsCurve > line( curve->segmentize() );
313 part = std::move( line );
315 added = geomCollection->
addGeometry( qgis::down_cast<QgsCurve *>( part.release() ) );
319 added = geomCollection->
addGeometry( part.release() );
325 added = geomCollection->
addGeometry( part.release() );
332 if ( !geom || partNum < 0 )
346 g =
c->geometryN( partNum );
348 else if ( partNum > 0 )
376 return c->removeGeometry( partNum );
380 const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
381 bool &haveInvalidGeometry,
382 const QHash<
QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures
386 haveInvalidGeometry =
false;
401 if ( avoidIntersectionsLayers.isEmpty() )
404 QVector< QgsGeometry > nearGeometries;
410 const QHash<QgsVectorLayer *, QSet<qint64> >::const_iterator ignoreIt = ignoreFeatures.constFind( currentLayer );
411 if ( ignoreIt != ignoreFeatures.constEnd() )
412 ignoreIds = ignoreIt.value();
420 if ( ignoreIds.contains( f.
id() ) )
427 haveInvalidGeometry =
true;
433 if ( nearGeometries.isEmpty() )
438 const std::unique_ptr< QgsAbstractGeometry > combinedGeometries( geomEngine->combine( nearGeometries ) );
439 if ( !combinedGeometries )
444 std::unique_ptr< QgsAbstractGeometry > diffGeom( geomEngine->difference( combinedGeometries.get() ) );
445 if ( !diffGeom || geomEngine->isEqual( diffGeom.get() ) )
GeometryOperationResult
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.
@ AddRingNotInExistingFeature
The input ring doesn't have any existing ring to fit into.
@ AddRingCrossesExistingRings
The input ring crosses existing rings (it is not disjoint).
@ AddPartNotMultiGeometry
The source geometry is not multi.
@ AddRingNotClosed
The input ring is not closed.
@ InvalidBaseGeometry
The base geometry on which the operation is done is invalid or empty.
@ AddRingNotValid
The input ring is not valid.
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
WkbType
The WKB type describes the number of dimensions a geometry has.
@ MultiPolygon
MultiPolygon.
@ MultiLineString
MultiLineString.
@ CurvePolygon
CurvePolygon.
@ PolyhedralSurface
PolyhedralSurface.
@ MultiSurface
MultiSurface.
Abstract base class for all geometries.
virtual QgsRectangle boundingBox() const
Returns the minimal bounding box for the geometry.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
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
Returns true if the curve is closed.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
Wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(Qgis::FeatureRequestFlags flags)
Sets flags that affect how features will be fetched.
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.
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.
int numGeometries() const
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.
static Qgis::GeometryOperationResult addRing(QgsAbstractGeometry *geometry, std::unique_ptr< QgsCurve > ring)
Add an interior ring to a geometry.
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 bool deleteRing(QgsAbstractGeometry *geom, int ringNum, int partNum=0)
Deletes a ring from a geometry.
static Qgis::GeometryOperationResult addPart(QgsAbstractGeometry *geometry, std::unique_ptr< QgsAbstractGeometry > part)
Add a part to multi type geometry.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool isGeosValid(Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const
Checks validity of the geometry using GEOS.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry, double precision=0.0, Qgis::GeosCreationFlags flags=Qgis::GeosCreationFlag::SkipEmptyInteriorRings)
Creates and returns a new geometry engine representing the specified geometry using precision on a gr...
Polyhedral surface geometry type.
int numPatches() const
Returns the number of patches contained with the polyhedral surface.
virtual void addPatch(QgsPolygon *patch)
Adds a patch to the geometry, transferring ownership to the polyhedral surface.
const QgsPolygon * patchN(int i) const
Retrieves a patch from the polyhedral surface.
Triangulated surface geometry type.
void addPatch(QgsPolygon *patch) override
Adds a patch to the geometry, transferring ownership to the polyhedral surface.
Represents a vector layer which manages a vector based dataset.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
static Q_INVOKABLE bool isSingleType(Qgis::WkbType type)
Returns true if the WKB type is a single type.
static Q_INVOKABLE bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static Q_INVOKABLE bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
static Q_INVOKABLE bool isMultiType(Qgis::WkbType type)
Returns true if the WKB type is a multi type.
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
T qgsgeometry_cast(QgsAbstractGeometry *geom)
QSet< QgsFeatureId > QgsFeatureIds