114     geometry.
set( 
nullptr );
 
  124   for ( QVector<QgsPointXY>::const_iterator it = ring.constBegin(); it != ring.constEnd(); ++it )
 
  128   return addRing( l, targetFeatureIds,  modifiedFeatureId );
 
  134   return addRing( ringLine, targetFeatureIds,  modifiedFeatureId );
 
  149   if ( !targetFeatureIds.isEmpty() )
 
  171     if ( addRingReturnCode == 0 )
 
  175         if ( modifiedFeatureId )
 
  176           *modifiedFeatureId = f.
id();
 
  184   return addRingReturnCode;
 
  190   for ( QVector<QgsPointXY>::const_iterator it = points.constBegin(); it != points.constEnd(); ++it )
 
  194   return addPart( l, featureId );
 
  200     return QgsGeometry::OperationResult::AddPartSelectedGeometryNotFound;
 
  203   bool firstPart = 
false;
 
  206     return QgsGeometry::OperationResult::AddPartSelectedGeometryNotFound; 
 
  238   bool firstPart = 
false;
 
  279   int errorCode = geometry.
translate( dx, dy );
 
  280   if ( errorCode == 0 )
 
  290   for ( QVector<QgsPointXY>::const_iterator it = splitLine.constBegin(); it != splitLine.constEnd(); ++it )
 
  301   bool preserveCircular = 
false;
 
  302   return splitFeatures( &lineString, topologyTestPoints, preserveCircular, topologicalEditing );
 
  313   int numberOfSplitFeatures = 0;
 
  321   if ( !selectedIds.isEmpty() ) 
 
  338       else if ( bBox.
height() == 0.0 && bBox.
width() > 0 )
 
  346         double bufferDistance = 0.000001;
 
  348           bufferDistance = 0.00000001;
 
  368     QVector<QgsGeometry> newGeometries;
 
  371     splitFunctionReturn = featureGeom.
splitGeometry( curve, newGeometries, preserveCircular, topologicalEditing, featureTopologyTestPoints );
 
  372     topologyTestPoints.append( featureTopologyTestPoints );
 
  373     if ( splitFunctionReturn == QgsGeometry::OperationResult::Success )
 
  380       for ( 
const QgsGeometry &geom : std::as_const( newGeometries ) )
 
  385       if ( topologicalEditing )
 
  387         QgsPointSequence::const_iterator topol_it = featureTopologyTestPoints.constBegin();
 
  388         for ( ; topol_it != featureTopologyTestPoints.constEnd(); ++topol_it )
 
  393       ++numberOfSplitFeatures;
 
  397       returnCode = splitFunctionReturn;
 
  401   if ( !featuresDataToAdd.isEmpty() )
 
  409   if ( numberOfSplitFeatures == 0 )
 
  411     returnCode = QgsGeometry::OperationResult::NothingHappened;
 
  420   for ( QVector<QgsPointXY>::const_iterator it = splitLine.constBegin(); it != splitLine.constEnd(); ++it )
 
  432   double xMin, yMin, xMax, yMax;
 
  436   int numberOfSplitParts = 0;
 
  446     if ( boundingBoxFromPointList( splitLine, xMin, yMin, xMax, yMax ) )
 
  455       return QgsGeometry::OperationResult::InvalidInputGeometryType;
 
  466       else if ( bBox.
height() == 0.0 && bBox.
width() > 0 )
 
  474         double bufferDistance = 0.000001;
 
  476           bufferDistance = 0.00000001;
 
  490     QVector<QgsGeometry> newGeometries;
 
  493     splitFunctionReturn = featureGeom.
splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints, 
false );
 
  495     if ( splitFunctionReturn == QgsGeometry::OperationResult::Success && !newGeometries.isEmpty() )
 
  500       for ( 
int i = 1; i < newGeometries.size(); ++i )
 
  509       if ( topologicalEditing )
 
  511         QgsPointSequence::const_iterator topol_it = topologyTestPoints.constBegin();
 
  512         for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
 
  517       ++numberOfSplitParts;
 
  519     else if ( splitFunctionReturn != QgsGeometry::OperationResult::Success && splitFunctionReturn != QgsGeometry::OperationResult::NothingHappened )
 
  521       returnCode = splitFunctionReturn;
 
  529     returnCode = QgsGeometry::OperationResult::NothingHappened;
 
  566   double segmentSearchEpsilon = mLayer->
crs().
isGeographic() ? 1e-12 : 1e-8;
 
  573     threshold = 0.0000001;
 
  586                            p.
x() + threshold, p.
y() + threshold );
 
  587   double sqrSnappingTolerance = threshold * threshold;
 
  591                            .setFilterRect( searchRect )
 
  593                            .setNoAttributes() );
 
  595   QMap<QgsFeatureId, QgsGeometry> features;
 
  596   QMap<QgsFeatureId, int> segments;
 
  603     if ( sqrDistSegmentSnap < sqrSnappingTolerance )
 
  605       segments[f.
id()] = afterVertex;
 
  610   if ( segments.isEmpty() )
 
  613   bool pointsAdded = 
false;
 
  614   for ( QMap<QgsFeatureId, int>::const_iterator it = segments.constBegin(); it != segments.constEnd(); ++it )
 
  617     int segmentAfterVertex = it.value();
 
  620     int atVertex, beforeVertex, afterVertex;
 
  621     double sqrDistVertexSnap;
 
  622     geom.
closestVertex( p, atVertex, beforeVertex, afterVertex, sqrDistVertexSnap );
 
  624     if ( sqrDistVertexSnap < sqrSnappingTolerance )
 
  627     if ( !mLayer->
insertVertex( p, fid, segmentAfterVertex ) )
 
  629       QgsDebugMsg( QStringLiteral( 
"failed to insert topo point" ) );
 
  637   return pointsAdded ? 0 : 2;
 
  650   bool pointsAdded = 
false;
 
  652   QgsPointSequence::const_iterator it = ps.constBegin();
 
  653   while ( it != ps.constEnd() )
 
  662   return pointsAdded ? 0 : 2;
 
  671 bool QgsVectorLayerEditUtils::boundingBoxFromPointList( 
const QgsPointSequence &list, 
double &xmin, 
double &ymin, 
double &xmax, 
double &ymax )
 const 
  678   xmin = std::numeric_limits<double>::max();
 
  679   xmax = -std::numeric_limits<double>::max();
 
  680   ymin = std::numeric_limits<double>::max();
 
  681   ymax = -std::numeric_limits<double>::max();
 
  683   for ( QgsPointSequence::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
 
  685     if ( it->x() < xmin )
 
  689     if ( it->x() > xmax )
 
  693     if ( it->y() < ymin )
 
  697     if ( it->y() > ymax )
 
The vertex_iterator class provides STL-style iterator for vertices.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
CORE_EXPORT QgsAttributeMap toMap() const
Returns a QgsAttributeMap of the attribute values.
Q_GADGET QgsUnitTypes::DistanceUnit mapUnits
Abstract base class for curved geometry type.
QgsRectangle boundingBox() const override
Returns the minimal bounding box for the geometry.
QgsCurve * clone() const override=0
Clones the geometry by performing a deep copy.
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).
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
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.
double geometryPrecision() const
The precision in which geometries on this layer should be saved.
A geometry is the spatial representation of a feature.
OperationResult addPart(const QVector< QgsPointXY > &points, QgsWkbTypes::GeometryType geomType=QgsWkbTypes::UnknownGeometry)
Adds a new part to a the geometry.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool deleteVertex(int atVertex)
Deletes the vertex at the given position number and item (first number is index 0)
OperationResult translate(double dx, double dy, double dz=0.0, double dm=0.0)
Translates this geometry by dx, dy, dz and dm.
QgsPointXY closestVertex(const QgsPointXY &point, int &closestVertexIndex, int &previousVertexIndex, int &nextVertexIndex, double &sqrDist) const
Returns the vertex closest to the given point, the corresponding vertex index, squared distance snap ...
OperationResult addRing(const QVector< QgsPointXY > &ring)
Adds a new ring to this geometry.
Q_DECL_DEPRECATED OperationResult splitGeometry(const QVector< QgsPointXY > &splitLine, QVector< QgsGeometry > &newGeometries, bool topological, QVector< QgsPointXY > &topologyTestPoints, bool splitFeature=true)
Splits this geometry according to a given line.
bool insertVertex(double x, double y, int beforeVertex)
Insert a new vertex before the given vertex index, ring and item (first number is index 0) If the req...
bool convertToSingleType()
Converts multi type geometry into single type geometry e.g.
OperationResult
Success or failure of a geometry operation.
@ InvalidBaseGeometry
The base geometry on which the operation is done is invalid or empty.
@ AddRingNotInExistingFeature
The input ring doesn't have any existing ring to fit into.
@ AddPartSelectedGeometryNotFound
The selected geometry cannot be found.
@ Success
Operation succeeded.
@ NothingHappened
Nothing happened, without any error.
void set(QgsAbstractGeometry *geometry)
Sets the underlying geometry store.
QgsAbstractGeometry::vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
bool moveVertex(double x, double y, int atVertex)
Moves the vertex at the given position number and item (first number is index 0) to the given coordin...
double closestSegmentWithContext(const QgsPointXY &point, QgsPointXY &minDistPoint, int &nextVertexIndex, int *leftOrRightOfSegment=nullptr, double epsilon=DEFAULT_SEGMENT_EPSILON) const
Searches for the closest segment of geometry to the given point.
QgsAbstractGeometry::vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
Line string geometry type, with support for z-dimension and m-values.
QgsCoordinateReferenceSystem crs
A class to represent a 2D point.
Point geometry type, with support for z-dimension and m-values.
A rectangle specified with double values.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
void setYMinimum(double y) SIP_HOLDGIL
Set the minimum y value.
void setXMaximum(double x) SIP_HOLDGIL
Set the maximum x value.
void setXMinimum(double x) SIP_HOLDGIL
Set the minimum x value.
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
void setYMaximum(double y) SIP_HOLDGIL
Set the maximum y value.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
bool isEmpty() const
Returns true if the rectangle is empty.
@ DistanceFeet
Imperial feet.
virtual bool doesStrictFeatureTypeCheck() const
Returns true if the provider is strict about the type of inserted features (e.g.
Q_DECL_DEPRECATED QgsGeometry::OperationResult addRing(const QVector< QgsPointXY > &ring, const QgsFeatureIds &targetFeatureIds=QgsFeatureIds(), QgsFeatureId *modifiedFeatureId=nullptr)
Adds a ring to polygon/multipolygon features.
int translateFeature(QgsFeatureId featureId, double dx, double dy)
Translates feature by dx, dy.
QgsVectorLayerEditUtils(QgsVectorLayer *layer)
bool insertVertex(double x, double y, QgsFeatureId atFeatureId, int beforeVertex)
Insert a new vertex before the given vertex number, in the given ring, item (first number is index 0)...
QgsVectorLayer::EditResult deleteVertex(QgsFeatureId featureId, int vertex)
Deletes a vertex from a feature.
Q_DECL_DEPRECATED QgsGeometry::OperationResult addPart(const QVector< QgsPointXY > &ring, QgsFeatureId featureId)
Adds a new part polygon to a multipart feature.
int addTopologicalPoints(const QgsGeometry &geom)
Adds topological points for every vertex of the geometry.
Q_DECL_DEPRECATED QgsGeometry::OperationResult splitFeatures(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits features cut by the given line.
bool moveVertex(double x, double y, QgsFeatureId atFeatureId, int atVertex)
Moves the vertex at the given position number, ring and item (first number is index 0),...
Q_DECL_DEPRECATED QgsGeometry::OperationResult splitParts(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits parts cut by the given line.
Encapsulate geometry and attributes for new features, to be passed to createFeatures.
QList< QgsVectorLayerUtils::QgsFeatureData > QgsFeaturesDataList
Alias for list of QgsFeatureData.
static QgsFeatureList createFeatures(const QgsVectorLayer *layer, const QgsFeaturesDataList &featuresData, QgsExpressionContext *context=nullptr)
Creates a set of new features ready for insertion into a layer.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
bool insertVertex(double x, double y, QgsFeatureId atFeatureId, int beforeVertex)
Inserts a new vertex before the given vertex number, in the given ring, item (first number is index 0...
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) FINAL
Adds a list of features to the sink.
int selectedFeatureCount() const
Returns the number of features that are selected in this layer.
Q_INVOKABLE const QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
EditResult
Result of an edit operation.
@ Success
Edit operation was successful.
@ InvalidLayer
Edit failed due to invalid layer.
@ EditFailed
Edit operation failed.
@ FetchFeatureFailed
Unable to fetch requested feature.
@ EmptyGeometry
Edit operation resulted in an empty geometry.
QgsGeometryOptions * geometryOptions() const
Configuration and logic to apply automatically on any edit happening on this layer.
QgsFeatureIterator getSelectedFeatures(QgsFeatureRequest request=QgsFeatureRequest()) const
Returns an iterator of the selected features.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
bool changeGeometry(QgsFeatureId fid, QgsGeometry &geometry, bool skipDefaultValue=false)
Changes a feature's geometry within the layer's edit buffer (but does not immediately commit the chan...
static bool isSingleType(Type type) SIP_HOLDGIL
Returns true if the WKB type is a single type.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QVector< QgsPoint > QgsPointSequence
QMap< int, QVariant > QgsAttributeMap
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features