129    geometry.
set( 
nullptr );
 
 
  151  if ( !ring->isClosed() )
 
  165  if ( !targetFeatureIds.isEmpty() )
 
  188      addRingReturnCode = g.
addRing( 
static_cast< QgsCurve * 
>( ring->clone() ) );
 
  192      addRingReturnCode = g.
addRing( 
static_cast< QgsCurve * 
>( ring->reversed() ) );
 
  197      if ( modifiedFeatureIds )
 
  199        modifiedFeatureIds->insert( f.
id() );
 
  209  return addRingReturnCode;
 
  215  for ( QVector<QgsPointXY>::const_iterator it = ring.constBegin(); it != ring.constEnd(); ++it )
 
  219  return addRing( l, targetFeatureIds,  modifiedFeatureId );
 
 
  225  return addRing( ringLine, targetFeatureIds,  modifiedFeatureId );
 
 
  230  std::unique_ptr<QgsCurve> uniquePtrRing( ring );
 
  231  if ( modifiedFeatureId )
 
  235    *modifiedFeatureId = *modifiedFeatureIds->begin();
 
  238  return staticAddRing( mLayer, uniquePtrRing, targetFeatureIds, 
nullptr, 
true );
 
 
  244  std::unique_ptr<QgsCurve> uniquePtrRing( ring );
 
  245  return staticAddRing( mLayer, uniquePtrRing, targetFeatureIds, modifiedFeatureIds, 
false );
 
 
  253  for ( QVector<QgsPointXY>::const_iterator it = points.constBegin(); it != points.constEnd(); ++it )
 
  257  return addPart( l, featureId );
 
 
  266  bool firstPart = 
false;
 
 
  302  bool firstPart = 
false;
 
 
  359  for ( QVector<QgsPointXY>::const_iterator it = splitLine.constBegin(); it != splitLine.constEnd(); ++it )
 
 
  370  bool preserveCircular = 
false;
 
  371  return splitFeatures( &lineString, topologyTestPoints, preserveCircular, topologicalEditing );
 
 
  382  int numberOfSplitFeatures = 0;
 
  390  if ( !selectedIds.isEmpty() ) 
 
  407      else if ( bBox.
height() == 0.0 && bBox.
width() > 0 )
 
  415        double bufferDistance = 0.000001;
 
  417          bufferDistance = 0.00000001;
 
  439    QVector<QgsGeometry> newGeometries;
 
  443    splitFunctionReturn = featureGeom.
splitGeometry( curve, newGeometries, preserveCircular, topologicalEditing, featureTopologyTestPoints );
 
  444    topologyTestPoints.append( featureTopologyTestPoints );
 
  452      for ( 
int fieldIdx = 0; fieldIdx < fieldCount; ++fieldIdx )
 
  466              const double originalValue = feat.
attribute( fieldIdx ).toDouble();
 
  468              double originalSize = 0;
 
  470              switch ( originalGeom.
type() )
 
  478                  originalSize = originalGeom.
length();
 
  481                  originalSize = originalGeom.
area();
 
  486              switch ( featureGeom.
type() )
 
  494                  newSize = featureGeom.
length();
 
  497                  newSize = featureGeom.
area();
 
  501              attributeMap.insert( fieldIdx, originalSize > 0 ? ( originalValue * newSize / originalSize ) : originalValue );
 
  508      if ( !attributeMap.isEmpty() )
 
  514      for ( 
const QgsGeometry &geom : std::as_const( newGeometries ) )
 
  517        for ( 
int fieldIdx = 0; fieldIdx < fieldCount; ++fieldIdx )
 
  529              attributeMap.insert( fieldIdx, feat.
attribute( fieldIdx ) );
 
  536                attributeMap.insert( fieldIdx, feat.
attribute( fieldIdx ) );
 
  540                const double originalValue = feat.
attribute( fieldIdx ).toDouble();
 
  542                double originalSize = 0;
 
  544                switch ( originalGeom.
type() )
 
  552                    originalSize = originalGeom.
length();
 
  555                    originalSize = originalGeom.
area();
 
  560                switch ( geom.type() )
 
  568                    newSize = geom.length();
 
  571                    newSize = geom.area();
 
  575                attributeMap.insert( fieldIdx, originalSize > 0 ? ( originalValue * newSize / originalSize ) : originalValue );
 
  589      if ( topologicalEditing )
 
  591        QgsPointSequence::const_iterator topol_it = featureTopologyTestPoints.constBegin();
 
  592        for ( ; topol_it != featureTopologyTestPoints.constEnd(); ++topol_it )
 
  597      ++numberOfSplitFeatures;
 
  601      returnCode = splitFunctionReturn;
 
  605  if ( !featuresDataToAdd.isEmpty() )
 
  613  if ( numberOfSplitFeatures == 0 )
 
 
  624  for ( QVector<QgsPointXY>::const_iterator it = splitLine.constBegin(); it != splitLine.constEnd(); ++it )
 
 
  636  double xMin, yMin, xMax, yMax;
 
  638  int numberOfSplitParts = 0;
 
  648    if ( boundingBoxFromPointList( splitLine, xMin, yMin, xMax, yMax ) )
 
  668      else if ( bBox.
height() == 0.0 && bBox.
width() > 0 )
 
  676        double bufferDistance = 0.000001;
 
  678          bufferDistance = 0.00000001;
 
  695    QVector<QgsGeometry> resultCollection;
 
  699      QVector<QgsGeometry> newGeometries;
 
  702      const Qgis::GeometryOperationResult splitFunctionReturn = part.splitGeometry( splitLine, newGeometries, topologicalEditing, partTopologyTestPoints, 
false );
 
  706        for ( 
int i = 0; i < newGeometries.size(); ++i )
 
  708          resultCollection.append( newGeometries.at( i ).asGeometryCollection() );
 
  711        topologyTestPoints.append( partTopologyTestPoints );
 
  713        ++numberOfSplitParts;
 
  721        resultCollection.append( part );
 
  725        return splitFunctionReturn;
 
  732    if ( topologicalEditing )
 
  734      QgsPointSequence::const_iterator topol_it = topologyTestPoints.constBegin();
 
  735      for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
 
 
  763  bool pointsAdded = 
false;
 
  775  return pointsAdded ? 0 : 2;
 
 
  783  double segmentSearchEpsilon = mLayer->
crs().
isGeographic() ? 1e-12 : 1e-8;
 
  790    threshold = 0.0000001;
 
  803                           p.
x() + threshold, p.
y() + threshold );
 
  804  double sqrSnappingTolerance = threshold * threshold;
 
  808                           .setFilterRect( searchRect )
 
  810                           .setNoAttributes() );
 
  812  QMap<QgsFeatureId, QgsGeometry> features;
 
  813  QMap<QgsFeatureId, int> segments;
 
  820    if ( sqrDistSegmentSnap < sqrSnappingTolerance )
 
  822      segments[f.
id()] = afterVertex;
 
  827  if ( segments.isEmpty() )
 
  830  bool pointsAdded = 
false;
 
  831  for ( QMap<QgsFeatureId, int>::const_iterator it = segments.constBegin(); it != segments.constEnd(); ++it )
 
  834    int segmentAfterVertex = it.value();
 
  837    int atVertex, beforeVertex, afterVertex;
 
  838    double sqrDistVertexSnap;
 
  839    geom.
closestVertex( p, atVertex, beforeVertex, afterVertex, sqrDistVertexSnap );
 
  841    if ( sqrDistVertexSnap < sqrSnappingTolerance )
 
  844    if ( !mLayer->
insertVertex( p, fid, segmentAfterVertex ) )
 
  846      QgsDebugError( QStringLiteral( 
"failed to insert topo point" ) );
 
  854  return pointsAdded ? 0 : 2;
 
 
  867  bool pointsAdded = 
false;
 
  869  QgsPointSequence::const_iterator it = ps.constBegin();
 
  870  while ( it != ps.constEnd() )
 
  879  return pointsAdded ? 0 : 2;
 
 
  889  errorMessage.clear();
 
  891  if ( mergeFeatureIds.isEmpty() )
 
  893    errorMessage = QObject::tr( 
"List of features to merge is empty" );
 
  898  for ( 
int i = 0; i < mergeAttributes.count(); ++i )
 
  900    QVariant val = mergeAttributes.at( i );
 
  907    QString errorMessageConvertCompatible;
 
  910      if ( errorMessage.isEmpty() )
 
  911        errorMessage = QObject::tr( 
"Could not store value '%1' in field of type %2: %3" ).arg( mergeAttributes.at( i ).toString(), mLayer->
fields().
at( i ).
typeName(), errorMessageConvertCompatible );
 
  913    newAttributes[ i ] = val;
 
  919  QgsFeatureIds::const_iterator feature_it = mergeFeatureIds.constBegin();
 
  920  for ( ; feature_it != mergeFeatureIds.constEnd(); ++feature_it )
 
  922    if ( *feature_it != targetFeatureId )
 
 
  946bool QgsVectorLayerEditUtils::boundingBoxFromPointList( 
const QgsPointSequence &list, 
double &xmin, 
double &ymin, 
double &xmax, 
double &ymax )
 const 
  953  xmin = std::numeric_limits<double>::max();
 
  954  xmax = -std::numeric_limits<double>::max();
 
  955  ymin = std::numeric_limits<double>::max();
 
  956  ymax = -std::numeric_limits<double>::max();
 
  958  for ( QgsPointSequence::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
 
  960    if ( it->x() < xmin )
 
  964    if ( it->x() > xmax )
 
  968    if ( it->y() < ymin )
 
  972    if ( it->y() > ymax )
 
GeometryOperationResult
Success or failure of a geometry operation.
@ AddPartSelectedGeometryNotFound
The selected geometry cannot be found.
@ 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.
@ AddRingNotClosed
The input ring is not closed.
@ NothingHappened
Nothing happened, without any error.
@ InvalidBaseGeometry
The base geometry on which the operation is done is invalid or empty.
@ LayerNotEditable
Cannot edit layer.
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
@ GeometryRatio
New values are computed by the ratio of their area/length compared to the area/length of the original...
@ UnsetField
Clears the field value so that the data provider backend will populate using any backend triggers or ...
@ DefaultValue
Use default field value.
@ Duplicate
Duplicate original value.
VectorEditResult
Flags which control feature selection behavior.
@ EmptyGeometry
Edit operation resulted in an empty geometry.
@ Success
Edit operation was successful.
@ FetchFeatureFailed
Unable to fetch requested feature.
@ EditFailed
Edit operation failed.
@ InvalidLayer
Edit failed due to invalid layer.
The vertex_iterator class provides STL-style iterator for vertices.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
bool isMeasure() const
Returns true if the geometry contains m values.
virtual QgsRectangle boundingBox() const
Returns the minimal bounding box for the geometry.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
Qgis::DistanceUnit mapUnits
Abstract base class for curved geometry type.
Qgis::AngularDirection orientation() const
Returns the curve's orientation, e.g.
virtual QgsCurve * reversed() const =0
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
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.
This class wraps a request for features to a vector layer (or directly its vector data provider).
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.
QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
Encapsulate a field in an attribute table or data source.
QString typeName() const
Gets the field type.
bool convertCompatible(QVariant &v, QString *errorMessage=nullptr) const
Converts the provided variant to a compatible format.
Qgis::FieldDomainSplitPolicy splitPolicy() const
Returns the field's split policy, which indicates how field values should be handled during a split o...
@ OriginProvider
Field comes from the underlying data provider of the vector layer (originIndex = index in provider's ...
int count() const
Returns number of items.
FieldOrigin fieldOrigin(int fieldIdx) const
Returns the field's origin (value from an enumeration).
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
int fieldOriginIndex(int fieldIdx) const
Returns the field's origin index (its meaning is specific to each type of origin).
double geometryPrecision() const
The precision in which geometries on this layer should be saved.
A geometry is the spatial representation of a feature.
bool deleteVertex(int atVertex)
Deletes the vertex at the given position number and item (first number is index 0)
double length() const
Returns the planar, 2-dimensional length of geometry.
static QgsGeometry collectGeometry(const QVector< QgsGeometry > &geometries)
Creates a new multipart geometry from a list of QgsGeometry objects.
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 ...
QVector< QgsGeometry > asGeometryCollection() const
Returns contents of the geometry as a list of geometries.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
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.
Qgis::GeometryOperationResult addRing(const QVector< QgsPointXY > &ring)
Adds a new ring to this geometry.
double area() const
Returns the planar, 2-dimensional area of the geometry.
Qgis::AngularDirection polygonOrientation() const
Returns the orientation of the polygon.
Qgis::GeometryOperationResult addPart(const QVector< QgsPointXY > &points, Qgis::GeometryType geomType=Qgis::GeometryType::Unknown)
Adds a new part to a the geometry.
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.
Qgis::GeometryOperationResult translate(double dx, double dy, double dz=0.0, double dm=0.0)
Translates this geometry by dx, dy, dz and dm.
Q_DECL_DEPRECATED Qgis::GeometryOperationResult 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 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
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
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 xMinimum() const
Returns the x minimum value (left side of rectangle).
void setYMinimum(double y)
Set the minimum y value.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
void setXMinimum(double x)
Set the minimum x value.
double width() const
Returns the width of the rectangle.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
void setYMaximum(double y)
Set the maximum y value.
void setXMaximum(double x)
Set the maximum x value.
bool isEmpty() const
Returns true if the rectangle has no area.
double height() const
Returns the height of the rectangle.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
static const QgsSettingsEntryDouble * settingsDigitizingDefaultMValue
Settings entry digitizing default m value.
static const QgsSettingsEntryDouble * settingsDigitizingDefaultZValue
Settings entry digitizing default z value.
Represents a default, "not-specified" value for a feature attribute.
virtual bool doesStrictFeatureTypeCheck() const
Returns true if the provider is strict about the type of inserted features (e.g.
virtual QString defaultValueClause(int fieldIndex) const
Returns any default value clauses which are present at the provider for a specified field index.
int translateFeature(QgsFeatureId featureId, double dx, double dy)
Translates feature by dx, dy.
bool mergeFeatures(const QgsFeatureId &targetFeatureId, const QgsFeatureIds &mergeFeatureIds, const QgsAttributes &mergeAttributes, const QgsGeometry &unionGeometry, QString &errorMessage)
Merge features into a single one.
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)...
Q_DECL_DEPRECATED Qgis::GeometryOperationResult addPart(const QVector< QgsPointXY > &ring, QgsFeatureId featureId)
Adds a new part polygon to a multipart feature.
Qgis::VectorEditResult deleteVertex(QgsFeatureId featureId, int vertex)
Deletes a vertex from a feature.
Qgis::GeometryOperationResult addRingV2(QgsCurve *ring, const QgsFeatureIds &targetFeatureIds=QgsFeatureIds(), QgsFeatureIds *modifiedFeatureIds=nullptr)
Adds a ring to polygon/multipolygon features.
int addTopologicalPoints(const QgsGeometry &geom)
Adds topological points for every vertex of the geometry.
Q_DECL_DEPRECATED Qgis::GeometryOperationResult splitParts(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits parts cut by the given line.
Q_DECL_DEPRECATED Qgis::GeometryOperationResult 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 Qgis::GeometryOperationResult addRing(const QVector< QgsPointXY > &ring, const QgsFeatureIds &targetFeatureIds=QgsFeatureIds(), QgsFeatureId *modifiedFeatureId=nullptr)
Adds a ring to polygon/multipolygon features.
Encapsulate geometry and attributes for new features, to be passed to createFeatures.
QList< QgsVectorLayerUtils::QgsFeatureData > QgsFeaturesDataList
Alias for list of QgsFeatureData.
static QgsFeature createFeature(const QgsVectorLayer *layer, const QgsGeometry &geometry=QgsGeometry(), const QgsAttributeMap &attributes=QgsAttributeMap(), QgsExpressionContext *context=nullptr)
Creates a new feature ready for insertion into a layer.
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.
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
bool deleteFeature(QgsFeatureId fid, DeleteContext *context=nullptr)
Deletes a feature from the layer (but does not commit it).
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.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
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.
void endEditCommand()
Finish edit command and add it to undo/redo stack.
Q_INVOKABLE const QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
bool changeAttributeValues(QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues=QgsAttributeMap(), bool skipDefaultValues=false)
Changes attributes' values for a feature (but does not immediately commit the changes).
QgsGeometryOptions * geometryOptions() const
Configuration and logic to apply automatically on any edit happening on this layer.
Q_INVOKABLE Qgis::WkbType wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Q_INVOKABLE QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on.
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 addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) FINAL
Adds a single feature to the sink.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
void beginEditCommand(const QString &text)
Create edit command for undo/redo operations.
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 hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
static bool isSingleType(Qgis::WkbType type)
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
#define QgsDebugError(str)