112 geometry.
set(
nullptr );
122 return addRing( ringLine, targetFeatureIds, modifiedFeatureId );
137 if ( !targetFeatureIds.isEmpty() )
158 addRingReturnCode = g.
addRing( static_cast< QgsCurve * >( ring->
clone() ) );
159 if ( addRingReturnCode == 0 )
163 if ( modifiedFeatureId )
164 *modifiedFeatureId = f.
id();
172 return addRingReturnCode;
178 for ( QList<QgsPointXY>::const_iterator it = points.constBegin(); it != points.constEnd(); ++it )
182 return addPart( l, featureId );
188 return QgsGeometry::OperationResult::AddPartSelectedGeometryNotFound;
191 bool firstPart =
false;
194 return QgsGeometry::OperationResult::AddPartSelectedGeometryNotFound;
226 bool firstPart =
false;
267 int errorCode = geometry.
translate( dx, dy );
268 if ( errorCode == 0 )
281 double xMin, yMin, xMax, yMax;
285 int numberOfSplitFeatures = 0;
290 if ( !selectedIds.isEmpty() )
296 if ( boundingBoxFromPointList( splitLine, xMin, yMin, xMax, yMax ) )
305 return QgsGeometry::OperationResult::InvalidInputGeometryType;
316 else if ( bBox.
height() == 0.0 && bBox.
width() > 0 )
324 double bufferDistance = 0.000001;
326 bufferDistance = 0.00000001;
344 QVector<QgsGeometry> newGeometries;
345 QVector<QgsPointXY> topologyTestPoints;
347 splitFunctionReturn = featureGeom.
splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
348 if ( splitFunctionReturn == QgsGeometry::OperationResult::Success )
354 for (
int i = 0; i < newGeometries.size(); ++i )
360 if ( topologicalEditing )
362 QVector<QgsPointXY>::const_iterator topol_it = topologyTestPoints.constBegin();
363 for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
368 ++numberOfSplitFeatures;
372 returnCode = splitFunctionReturn;
376 if ( numberOfSplitFeatures == 0 && !selectedIds.isEmpty() )
380 returnCode = QgsGeometry::OperationResult::NothingHappened;
391 double xMin, yMin, xMax, yMax;
395 int numberOfSplitParts = 0;
405 if ( boundingBoxFromPointList( splitLine, xMin, yMin, xMax, yMax ) )
414 return QgsGeometry::OperationResult::InvalidInputGeometryType;
425 else if ( bBox.
height() == 0.0 && bBox.
width() > 0 )
433 double bufferDistance = 0.000001;
435 bufferDistance = 0.00000001;
451 QVector<QgsGeometry> newGeometries;
452 QVector<QgsPointXY> topologyTestPoints;
454 splitFunctionReturn = featureGeom.
splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
455 if ( splitFunctionReturn == 0 )
458 if ( !newGeometries.isEmpty() )
461 for (
int i = 0; i < newGeometries.size(); ++i )
463 addPartRet = featureGeom.
addPart( newGeometries.at( i ) );
476 if ( topologicalEditing )
478 QVector<QgsPointXY>::const_iterator topol_it = topologyTestPoints.constBegin();
479 for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
484 ++numberOfSplitParts;
486 else if ( splitFunctionReturn != QgsGeometry::OperationResult::Success && splitFunctionReturn != QgsGeometry::OperationResult::NothingHappened )
488 returnCode = splitFunctionReturn;
496 returnCode = QgsGeometry::OperationResult::NothingHappened;
525 QgsPolylineXY::const_iterator line_it = line.constBegin();
526 for ( ; line_it != line.constEnd(); ++line_it )
539 for (
int i = 0; i < multiLine.size(); ++i )
541 QgsPolylineXY::const_iterator line_it = currentPolyline.constBegin();
542 for ( ; line_it != currentPolyline.constEnd(); ++line_it )
561 for (
int i = 0; i < polygon.size(); ++i )
563 currentRing = polygon.at( i );
564 QgsPolylineXY::const_iterator line_it = currentRing.constBegin();
565 for ( ; line_it != currentRing.constEnd(); ++line_it )
580 for (
int i = 0; i < multiPolygon.size(); ++i )
582 currentPolygon = multiPolygon.at( i );
583 for (
int j = 0; j < currentPolygon.size(); ++j )
585 currentRing = currentPolygon.at( j );
586 QgsPolylineXY::const_iterator line_it = currentRing.constBegin();
587 for ( ; line_it != currentRing.constEnd(); ++line_it )
614 double segmentSearchEpsilon = mLayer->
crs().
isGeographic() ? 1e-12 : 1e-8;
617 double threshold = 0.0000001;
628 p.
x() + threshold, p.
y() + threshold );
629 double sqrSnappingTolerance = threshold * threshold;
633 .setFilterRect( searchRect )
635 .setNoAttributes() );
637 QMap<QgsFeatureId, QgsGeometry> features;
638 QMap<QgsFeatureId, int> segments;
645 if ( sqrDistSegmentSnap < sqrSnappingTolerance )
647 segments[f.
id()] = afterVertex;
652 if ( segments.isEmpty() )
655 for ( QMap<QgsFeatureId, int>::const_iterator it = segments.constBegin(); it != segments.constEnd(); ++it )
658 int segmentAfterVertex = it.value();
661 int atVertex, beforeVertex, afterVertex;
662 double sqrDistVertexSnap;
663 geom.
closestVertex( p, atVertex, beforeVertex, afterVertex, sqrDistVertexSnap );
665 if ( sqrDistVertexSnap < sqrSnappingTolerance )
668 if ( !mLayer->
insertVertex( p.
x(), p.
y(), fid, segmentAfterVertex ) )
670 QgsDebugMsg( QStringLiteral(
"failed to insert topo point" ) );
678 bool QgsVectorLayerEditUtils::boundingBoxFromPointList(
const QVector<QgsPointXY> &list,
double &xmin,
double &ymin,
double &xmax,
double &ymax )
const 685 xmin = std::numeric_limits<double>::max();
686 xmax = -std::numeric_limits<double>::max();
687 ymin = std::numeric_limits<double>::max();
688 ymax = -std::numeric_limits<double>::max();
690 for ( QVector<QgsPointXY>::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
692 if ( it->x() < xmin )
696 if ( it->x() > xmax )
700 if ( it->y() < ymin )
704 if ( it->y() > ymax )
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.
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.
static bool isMultiType(Type type)
Returns true if the WKB type is a multi type.
Nothing happened, without any error.
QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
QgsWkbTypes::Type wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
A class to represent a 2D point.
int selectedFeatureCount() const
Returns the number of features that are selected in this layer.
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item...
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)
Insert 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.
QVector< QgsPolygonXY > QgsMultiPolygonXY
A collection of QgsPolygons that share a common collection of attributes.
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 ...
QVector< QgsPolylineXY > QgsMultiPolylineXY
A collection of QgsPolylines that share a common collection of attributes.
QgsMultiPolylineXY asMultiPolyline() const
Returns the contents of the geometry as a multi-linestring.
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.
Type
The WKB type describes the number of dimensions a geometry has.
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.
QgsPolygonXY asPolygon() const
Returns the contents of the geometry as a polygon.
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.
QgsGeometry::OperationResult splitFeatures(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits features cut by the given line.
static GeometryType geometryType(Type type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
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.
Point geometry type, with support for z-dimension and m-values.
QgsGeometry::OperationResult addPart(const QList< QgsPointXY > &ring, QgsFeatureId featureId)
Adds a new part polygon to a multipart feature.
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.
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
The base geometry on which the operation is done is invalid or empty.
QgsGeometry::OperationResult addRing(const QVector< QgsPointXY > &ring, const QgsFeatureIds &targetFeatureIds=QgsFeatureIds(), QgsFeatureId *modifiedFeatureId=nullptr)
Adds a ring to polygon/multipolygon features.
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
Query the layer for features specified in request.
QgsPolylineXY asPolyline() const
Returns the contents of the geometry as a polyline.
Edit failed due to invalid layer.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be null.
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.
EditResult
Result of an edit operation.
QgsMultiPolygonXY asMultiPolygon() const
Returns the contents of the geometry as a multi-polygon.
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)