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() )
170 addRingReturnCode = g.
addRing( static_cast< QgsCurve * >( ring->
clone() ) );
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 )
302 double xMin, yMin, xMax, yMax;
306 int numberOfSplitFeatures = 0;
311 if ( !selectedIds.isEmpty() )
317 if ( boundingBoxFromPointList( splitLine, xMin, yMin, xMax, yMax ) )
326 return QgsGeometry::OperationResult::InvalidInputGeometryType;
337 else if ( bBox.
height() == 0.0 && bBox.
width() > 0 )
345 double bufferDistance = 0.000001;
347 bufferDistance = 0.00000001;
365 QVector<QgsGeometry> newGeometries;
368 splitFunctionReturn = featureGeom.
splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
369 if ( splitFunctionReturn == QgsGeometry::OperationResult::Success )
376 for (
const QgsGeometry &geom : qgis::as_const( newGeometries ) )
382 if ( topologicalEditing )
384 QgsPointSequence::const_iterator topol_it = topologyTestPoints.constBegin();
385 for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
390 ++numberOfSplitFeatures;
394 returnCode = splitFunctionReturn;
398 if ( numberOfSplitFeatures == 0 && !selectedIds.isEmpty() )
402 returnCode = QgsGeometry::OperationResult::NothingHappened;
411 for ( QVector<QgsPointXY>::const_iterator it = splitLine.constBegin(); it != splitLine.constEnd(); ++it )
423 double xMin, yMin, xMax, yMax;
427 int numberOfSplitParts = 0;
437 if ( boundingBoxFromPointList( splitLine, xMin, yMin, xMax, yMax ) )
446 return QgsGeometry::OperationResult::InvalidInputGeometryType;
457 else if ( bBox.
height() == 0.0 && bBox.
width() > 0 )
465 double bufferDistance = 0.000001;
467 bufferDistance = 0.00000001;
483 QVector<QgsGeometry> newGeometries;
486 splitFunctionReturn = featureGeom.
splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
487 if ( splitFunctionReturn == 0 )
490 if ( !newGeometries.isEmpty() )
493 for (
int i = 0; i < newGeometries.size(); ++i )
495 addPartRet = featureGeom.
addPart( newGeometries.at( i ) );
508 if ( topologicalEditing )
510 QgsPointSequence::const_iterator topol_it = topologyTestPoints.constBegin();
511 for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
516 ++numberOfSplitParts;
518 else if ( splitFunctionReturn != QgsGeometry::OperationResult::Success && splitFunctionReturn != QgsGeometry::OperationResult::NothingHappened )
520 returnCode = splitFunctionReturn;
528 returnCode = QgsGeometry::OperationResult::NothingHappened;
565 double segmentSearchEpsilon = mLayer->
crs().
isGeographic() ? 1e-12 : 1e-8;
572 threshold = 0.0000001;
585 p.
x() + threshold, p.
y() + threshold );
586 double sqrSnappingTolerance = threshold * threshold;
590 .setFilterRect( searchRect )
592 .setNoAttributes() );
594 QMap<QgsFeatureId, QgsGeometry> features;
595 QMap<QgsFeatureId, int> segments;
602 if ( sqrDistSegmentSnap < sqrSnappingTolerance )
604 segments[f.
id()] = afterVertex;
609 if ( segments.isEmpty() )
612 for ( QMap<QgsFeatureId, int>::const_iterator it = segments.constBegin(); it != segments.constEnd(); ++it )
615 int segmentAfterVertex = it.value();
618 int atVertex, beforeVertex, afterVertex;
619 double sqrDistVertexSnap;
620 geom.
closestVertex( p, atVertex, beforeVertex, afterVertex, sqrDistVertexSnap );
622 if ( sqrDistVertexSnap < sqrSnappingTolerance )
625 if ( !mLayer->
insertVertex( p, fid, segmentAfterVertex ) )
627 QgsDebugMsg( QStringLiteral(
"failed to insert topo point" ) );
640 bool QgsVectorLayerEditUtils::boundingBoxFromPointList(
const QgsPointSequence &list,
double &xmin,
double &ymin,
double &xmax,
double &ymax )
const 647 xmin = std::numeric_limits<double>::max();
648 xmax = -std::numeric_limits<double>::max();
649 ymin = std::numeric_limits<double>::max();
650 ymax = -std::numeric_limits<double>::max();
652 for ( QgsPointSequence::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
654 if ( it->x() < xmin )
658 if ( it->x() > xmax )
662 if ( it->y() < ymin )
666 if ( it->y() > ymax )
QgsGeometryOptions * geometryOptions() const
Configuration and logic to apply automatically on any edit happening on this layer.
Wrapper for iterator of features from vector data provider or vector layer.
double closestSegmentWithContext(const QgsPointXY &point, QgsPointXY &minDistPoint, int &afterVertex, int *leftOf=nullptr, double epsilon=DEFAULT_SEGMENT_EPSILON) const
Searches for the closest segment of geometry to the given point.
A rectangle specified with double values.
Q_DECL_DEPRECATED QgsGeometry::OperationResult splitParts(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits parts cut by the given line.
The input ring doesn't have any existing ring to fit into.
QSet< QgsFeatureId > QgsFeatureIds
OperationResult addPart(const QVector< QgsPointXY > &points, QgsWkbTypes::GeometryType geomType=QgsWkbTypes::UnknownGeometry)
Adds a new part to a the geometry.
void setXMaximum(double x)
Set the maximum x value.
Use exact geometry intersection (slower) instead of bounding boxes.
Nothing happened, without any error.
QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
A class to represent a 2D point.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
int selectedFeatureCount() const
Returns the number of features that are selected in this layer.
double geometryPrecision() const
The precision in which geometries on this layer should be saved.
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...
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
A geometry is the spatial representation of a feature.
QgsUnitTypes::DistanceUnit mapUnits
OperationResult addRing(const QVector< QgsPointXY > &ring)
Adds a new ring to this geometry.
Edit operation resulted in an empty geometry.
int addTopologicalPoints(const QgsGeometry &geom)
Adds topological points for every vertex of the geometry.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
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 hasGeometry() const
Returns true if the feature has an associated geometry.
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...
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
OperationResult
Success or failure of a geometry operation.
QgsPointXY closestVertex(const QgsPointXY &point, int &atVertex, int &beforeVertex, int &afterVertex, double &sqrDist) const
Returns the vertex closest to the given point, the corresponding vertex index, squared distance snap ...
virtual bool doesStrictFeatureTypeCheck() const
Returns true if the provider is strict about the type of inserted features (e.g.
The selected geometry cannot be found.
const QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
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...
bool convertToSingleType()
Converts multi type geometry into single type geometry e.g.
bool isEmpty() const
Returns true if the rectangle is empty.
QgsFeatureIterator getSelectedFeatures(QgsFeatureRequest request=QgsFeatureRequest()) const
Returns an iterator of the selected features.
double width() const
Returns the width of the rectangle.
void setYMinimum(double y)
Set the minimum y value.
bool deleteVertex(int atVertex)
Deletes the vertex at the given position number and item (first number is index 0) ...
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.
Q_DECL_DEPRECATED QgsGeometry::OperationResult addPart(const QVector< QgsPointXY > &ring, QgsFeatureId featureId)
Adds a new part polygon to a multipart feature.
Q_DECL_DEPRECATED QgsGeometry::OperationResult splitFeatures(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits features cut by the given line.
QMap< int, QVariant > QgsAttributeMap
int translateFeature(QgsFeatureId featureId, double dx, double dy)
Translates feature by dx, dy.
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)...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QgsAttributeMap toMap() const
Returns a QgsAttributeMap of the attribute values.
Abstract base class for curved geometry type.
The vertex_iterator class provides STL-style iterator for vertices.
Point geometry type, with support for z-dimension and m-values.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
static bool isSingleType(Type type)
Returns true if the WKB type is a single type.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
QVector< QgsPoint > QgsPointSequence
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)...
QgsRectangle boundingBox() const override
Returns the minimal bounding box for the geometry.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
The base geometry on which the operation is done is invalid or empty.
Q_DECL_DEPRECATED QgsGeometry::OperationResult addRing(const QVector< QgsPointXY > &ring, const QgsFeatureIds &targetFeatureIds=QgsFeatureIds(), QgsFeatureId *modifiedFeatureId=nullptr)
Adds a ring to polygon/multipolygon features.
Q_DECL_DEPRECATED OperationResult splitGeometry(const QVector< QgsPointXY > &splitLine, QVector< QgsGeometry > &newGeometries, bool topological, QVector< QgsPointXY > &topologyTestPoints)
Splits this geometry according to a given line.
QgsCurve * clone() const override=0
Clones the geometry by performing a deep copy.
void setYMaximum(double y)
Set the maximum y value.
Edit operation was successful.
Line string geometry type, with support for z-dimension and m-values.
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=nullptr) FINAL
Adds a single feature to the sink.
QgsVectorLayer::EditResult deleteVertex(QgsFeatureId featureId, int vertex)
Deletes a vertex from a feature.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
OperationResult translate(double dx, double dy, double dz=0.0, double dm=0.0)
Translates this geometry by dx, dy, dz and dm.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
Edit failed due to invalid layer.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
bool nextFeature(QgsFeature &f)
void set(QgsAbstractGeometry *geometry)
Sets the underlying geometry store.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
Represents a vector layer which manages a vector based data sets.
QgsAbstractGeometry::vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry...
EditResult
Result of an edit operation.
QgsAbstractGeometry::vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
Unable to fetch requested feature.
void setXMinimum(double x)
Set the minimum x value.
QgsCoordinateReferenceSystem crs
double height() const
Returns the height of the rectangle.
QgsVectorLayerEditUtils(QgsVectorLayer *layer)