113 geometry.
set(
nullptr );
123 return addRing( ringLine, targetFeatureIds, modifiedFeatureId );
138 if ( !targetFeatureIds.isEmpty() )
159 addRingReturnCode = g.
addRing( static_cast< QgsCurve * >( ring->
clone() ) );
160 if ( addRingReturnCode == 0 )
164 if ( modifiedFeatureId )
165 *modifiedFeatureId = f.
id();
173 return addRingReturnCode;
179 for ( QList<QgsPointXY>::const_iterator it = points.constBegin(); it != points.constEnd(); ++it )
183 return addPart( l, featureId );
189 return QgsGeometry::OperationResult::AddPartSelectedGeometryNotFound;
192 bool firstPart =
false;
195 return QgsGeometry::OperationResult::AddPartSelectedGeometryNotFound;
227 bool firstPart =
false;
268 int errorCode = geometry.
translate( dx, dy );
269 if ( errorCode == 0 )
282 double xMin, yMin, xMax, yMax;
286 int numberOfSplitFeatures = 0;
291 if ( !selectedIds.isEmpty() )
297 if ( boundingBoxFromPointList( splitLine, xMin, yMin, xMax, yMax ) )
306 return QgsGeometry::OperationResult::InvalidInputGeometryType;
317 else if ( bBox.
height() == 0.0 && bBox.
width() > 0 )
325 double bufferDistance = 0.000001;
327 bufferDistance = 0.00000001;
345 QVector<QgsGeometry> newGeometries;
346 QVector<QgsPointXY> topologyTestPoints;
348 splitFunctionReturn = featureGeom.
splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
349 if ( splitFunctionReturn == QgsGeometry::OperationResult::Success )
355 for (
int i = 0; i < newGeometries.size(); ++i )
361 if ( topologicalEditing )
363 QVector<QgsPointXY>::const_iterator topol_it = topologyTestPoints.constBegin();
364 for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
369 ++numberOfSplitFeatures;
373 returnCode = splitFunctionReturn;
377 if ( numberOfSplitFeatures == 0 && !selectedIds.isEmpty() )
381 returnCode = QgsGeometry::OperationResult::NothingHappened;
392 double xMin, yMin, xMax, yMax;
396 int numberOfSplitParts = 0;
406 if ( boundingBoxFromPointList( splitLine, xMin, yMin, xMax, yMax ) )
415 return QgsGeometry::OperationResult::InvalidInputGeometryType;
426 else if ( bBox.
height() == 0.0 && bBox.
width() > 0 )
434 double bufferDistance = 0.000001;
436 bufferDistance = 0.00000001;
452 QVector<QgsGeometry> newGeometries;
453 QVector<QgsPointXY> topologyTestPoints;
455 splitFunctionReturn = featureGeom.
splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
456 if ( splitFunctionReturn == 0 )
459 if ( !newGeometries.isEmpty() )
462 for (
int i = 0; i < newGeometries.size(); ++i )
464 addPartRet = featureGeom.
addPart( newGeometries.at( i ) );
477 if ( topologicalEditing )
479 QVector<QgsPointXY>::const_iterator topol_it = topologyTestPoints.constBegin();
480 for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
485 ++numberOfSplitParts;
487 else if ( splitFunctionReturn != QgsGeometry::OperationResult::Success && splitFunctionReturn != QgsGeometry::OperationResult::NothingHappened )
489 returnCode = splitFunctionReturn;
497 returnCode = QgsGeometry::OperationResult::NothingHappened;
526 QgsPolylineXY::const_iterator line_it = line.constBegin();
527 for ( ; line_it != line.constEnd(); ++line_it )
540 for (
int i = 0; i < multiLine.size(); ++i )
542 QgsPolylineXY::const_iterator line_it = currentPolyline.constBegin();
543 for ( ; line_it != currentPolyline.constEnd(); ++line_it )
562 for (
int i = 0; i < polygon.size(); ++i )
564 currentRing = polygon.at( i );
565 QgsPolylineXY::const_iterator line_it = currentRing.constBegin();
566 for ( ; line_it != currentRing.constEnd(); ++line_it )
581 for (
int i = 0; i < multiPolygon.size(); ++i )
583 currentPolygon = multiPolygon.at( i );
584 for (
int j = 0; j < currentPolygon.size(); ++j )
586 currentRing = currentPolygon.at( j );
587 QgsPolylineXY::const_iterator line_it = currentRing.constBegin();
588 for ( ; line_it != currentRing.constEnd(); ++line_it )
615 double segmentSearchEpsilon = mLayer->
crs().
isGeographic() ? 1e-12 : 1e-8;
622 threshold = 0.0000001;
635 p.
x() + threshold, p.
y() + threshold );
636 double sqrSnappingTolerance = threshold * threshold;
640 .setFilterRect( searchRect )
642 .setNoAttributes() );
644 QMap<QgsFeatureId, QgsGeometry> features;
645 QMap<QgsFeatureId, int> segments;
652 if ( sqrDistSegmentSnap < sqrSnappingTolerance )
654 segments[f.
id()] = afterVertex;
659 if ( segments.isEmpty() )
662 for ( QMap<QgsFeatureId, int>::const_iterator it = segments.constBegin(); it != segments.constEnd(); ++it )
665 int segmentAfterVertex = it.value();
668 int atVertex, beforeVertex, afterVertex;
669 double sqrDistVertexSnap;
670 geom.
closestVertex( p, atVertex, beforeVertex, afterVertex, sqrDistVertexSnap );
672 if ( sqrDistVertexSnap < sqrSnappingTolerance )
675 if ( !mLayer->
insertVertex( p.
x(), p.
y(), fid, segmentAfterVertex ) )
677 QgsDebugMsg( QStringLiteral(
"failed to insert topo point" ) );
685 bool QgsVectorLayerEditUtils::boundingBoxFromPointList(
const QVector<QgsPointXY> &list,
double &xmin,
double &ymin,
double &xmax,
double &ymax )
const 692 xmin = std::numeric_limits<double>::max();
693 xmax = -std::numeric_limits<double>::max();
694 ymin = std::numeric_limits<double>::max();
695 ymax = -std::numeric_limits<double>::max();
697 for ( QVector<QgsPointXY>::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
699 if ( it->x() < xmin )
703 if ( it->x() > xmax )
707 if ( it->y() < ymin )
711 if ( it->y() > ymax )
Wrapper for iterator of features from vector data provider or vector layer.
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.
bool isEmpty() const
Returns true if the rectangle is empty.
double geometryPrecision() const
The precision in which geometries on this layer should be saved.
QSet< QgsFeatureId > QgsFeatureIds
OperationResult addPart(const QVector< QgsPointXY > &points, QgsWkbTypes::GeometryType geomType=QgsWkbTypes::UnknownGeometry)
Adds a new part to a the geometry.
bool isNull() const
Returns true if the geometry is null (ie, contains no underlying geometry accessible via 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.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
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)
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...
int selectedFeatureCount() const
Returns the number of features that are selected in this layer.
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 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.
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.
QVector< QgsPolygonXY > QgsMultiPolygonXY
A collection of QgsPolygons that share a common collection of attributes.
QgsMultiPolygonXY asMultiPolygon() const
Returns contents of the geometry as a multi polygon if wkbType is WKBMultiPolygon, otherwise an empty list.
QVector< QgsPolylineXY > QgsMultiPolylineXY
A collection of QgsPolylines that share a common collection of attributes.
The selected geometry cannot be found.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Type
The WKB type describes the number of dimensions a geometry has.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
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.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of 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.
QgsPolylineXY asPolyline() const
Returns the contents of the geometry as a polyline.
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)...
QgsMultiPolylineXY asMultiPolyline() const
Returns contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list.
Abstract base class for curved geometry type.
const QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
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.
static bool isSingleType(Type type)
Returns true if the WKB type is a single type.
QVector< QgsPoint > QgsPointSequence
QgsGeometryOptions * geometryOptions() const
Configuration and logic to apply automatically on any edit happening on this 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)...
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.
virtual bool doesStrictFeatureTypeCheck() const
Returns true if the provider is strict about the type of inserted features (e.g.
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.
QgsAttributeMap toMap() const
Returns a QgsAttributeMap of the attribute values.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
QgsFeatureIterator getSelectedFeatures(QgsFeatureRequest request=QgsFeatureRequest()) const
Returns an iterator of the selected features.
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.
OperationResult translate(double dx, double dy, double dz=0.0, double dm=0.0)
Translates this geometry by dx, dy, dz and dm.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Query the layer for features specified in request.
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
Edit failed due to invalid layer.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider.
bool nextFeature(QgsFeature &f)
void set(QgsAbstractGeometry *geometry)
Sets the underlying geometry store.
double width() const
Returns the width of the rectangle.
Represents a vector layer which manages a vector based data sets.
bool isGeographic() const
Returns whether the CRS is a geographic CRS (using lat/lon coordinates)
double xMinimum() const
Returns the x minimum value (left side of rectangle).
EditResult
Result of an edit operation.
QgsWkbTypes::Type wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
Unable to fetch requested feature.
void setXMinimum(double x)
Set the minimum x value.
QgsCoordinateReferenceSystem crs
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 ...
double height() const
Returns the height of the rectangle.
QgsVectorLayerEditUtils(QgsVectorLayer *layer)
QgsPolygonXY asPolygon() const
Returns the contents of the geometry as a polygon.