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 )
356 for (
const QgsGeometry &geom : qgis::as_const( newGeometries ) )
362 if ( topologicalEditing )
364 QVector<QgsPointXY>::const_iterator topol_it = topologyTestPoints.constBegin();
365 for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
370 ++numberOfSplitFeatures;
374 returnCode = splitFunctionReturn;
378 if ( numberOfSplitFeatures == 0 && !selectedIds.isEmpty() )
382 returnCode = QgsGeometry::OperationResult::NothingHappened;
393 double xMin, yMin, xMax, yMax;
397 int numberOfSplitParts = 0;
407 if ( boundingBoxFromPointList( splitLine, xMin, yMin, xMax, yMax ) )
416 return QgsGeometry::OperationResult::InvalidInputGeometryType;
427 else if ( bBox.
height() == 0.0 && bBox.
width() > 0 )
435 double bufferDistance = 0.000001;
437 bufferDistance = 0.00000001;
453 QVector<QgsGeometry> newGeometries;
454 QVector<QgsPointXY> topologyTestPoints;
456 splitFunctionReturn = featureGeom.
splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
457 if ( splitFunctionReturn == 0 )
460 if ( !newGeometries.isEmpty() )
463 for (
int i = 0; i < newGeometries.size(); ++i )
465 addPartRet = featureGeom.
addPart( newGeometries.at( i ) );
478 if ( topologicalEditing )
480 QVector<QgsPointXY>::const_iterator topol_it = topologyTestPoints.constBegin();
481 for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
486 ++numberOfSplitParts;
488 else if ( splitFunctionReturn != QgsGeometry::OperationResult::Success && splitFunctionReturn != QgsGeometry::OperationResult::NothingHappened )
490 returnCode = splitFunctionReturn;
498 returnCode = QgsGeometry::OperationResult::NothingHappened;
527 QgsPolylineXY::const_iterator line_it = line.constBegin();
528 for ( ; line_it != line.constEnd(); ++line_it )
541 for (
int i = 0; i < multiLine.size(); ++i )
543 QgsPolylineXY::const_iterator line_it = currentPolyline.constBegin();
544 for ( ; line_it != currentPolyline.constEnd(); ++line_it )
563 for (
int i = 0; i < polygon.size(); ++i )
565 currentRing = polygon.at( i );
566 QgsPolylineXY::const_iterator line_it = currentRing.constBegin();
567 for ( ; line_it != currentRing.constEnd(); ++line_it )
582 for (
int i = 0; i < multiPolygon.size(); ++i )
584 currentPolygon = multiPolygon.at( i );
585 for (
int j = 0; j < currentPolygon.size(); ++j )
587 currentRing = currentPolygon.at( j );
588 QgsPolylineXY::const_iterator line_it = currentRing.constBegin();
589 for ( ; line_it != currentRing.constEnd(); ++line_it )
616 double segmentSearchEpsilon = mLayer->
crs().
isGeographic() ? 1e-12 : 1e-8;
623 threshold = 0.0000001;
636 p.
x() + threshold, p.
y() + threshold );
637 double sqrSnappingTolerance = threshold * threshold;
641 .setFilterRect( searchRect )
643 .setNoAttributes() );
645 QMap<QgsFeatureId, QgsGeometry> features;
646 QMap<QgsFeatureId, int> segments;
653 if ( sqrDistSegmentSnap < sqrSnappingTolerance )
655 segments[f.
id()] = afterVertex;
660 if ( segments.isEmpty() )
663 for ( QMap<QgsFeatureId, int>::const_iterator it = segments.constBegin(); it != segments.constEnd(); ++it )
666 int segmentAfterVertex = it.value();
669 int atVertex, beforeVertex, afterVertex;
670 double sqrDistVertexSnap;
671 geom.
closestVertex( p, atVertex, beforeVertex, afterVertex, sqrDistVertexSnap );
673 if ( sqrDistVertexSnap < sqrSnappingTolerance )
676 if ( !mLayer->
insertVertex( p.
x(), p.
y(), fid, segmentAfterVertex ) )
678 QgsDebugMsg( QStringLiteral(
"failed to insert topo point" ) );
686 bool QgsVectorLayerEditUtils::boundingBoxFromPointList(
const QVector<QgsPointXY> &list,
double &xmin,
double &ymin,
double &xmax,
double &ymax )
const 693 xmin = std::numeric_limits<double>::max();
694 xmax = -std::numeric_limits<double>::max();
695 ymin = std::numeric_limits<double>::max();
696 ymax = -std::numeric_limits<double>::max();
698 for ( QVector<QgsPointXY>::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
700 if ( it->x() < xmin )
704 if ( it->x() > xmax )
708 if ( it->y() < ymin )
712 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.
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.
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.
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)
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.
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.
QMap< int, QVariant > QgsAttributeMap
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
Queries 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 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.
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)