QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
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() )
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;
481 QVector<QgsGeometry> newGeometries;
484 splitFunctionReturn = featureGeom.
splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints,
false );
486 if ( splitFunctionReturn == QgsGeometry::OperationResult::Success && !newGeometries.isEmpty() )
491 for (
int i = 1; i < newGeometries.size(); ++i )
500 if ( topologicalEditing )
502 QgsPointSequence::const_iterator topol_it = topologyTestPoints.constBegin();
503 for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
508 ++numberOfSplitParts;
510 else if ( splitFunctionReturn != QgsGeometry::OperationResult::Success && splitFunctionReturn != QgsGeometry::OperationResult::NothingHappened )
512 returnCode = splitFunctionReturn;
520 returnCode = QgsGeometry::OperationResult::NothingHappened;
557 double segmentSearchEpsilon = mLayer->
crs().
isGeographic() ? 1e-12 : 1e-8;
564 threshold = 0.0000001;
577 p.
x() + threshold, p.
y() + threshold );
578 double sqrSnappingTolerance = threshold * threshold;
582 .setFilterRect( searchRect )
584 .setNoAttributes() );
586 QMap<QgsFeatureId, QgsGeometry> features;
587 QMap<QgsFeatureId, int> segments;
594 if ( sqrDistSegmentSnap < sqrSnappingTolerance )
596 segments[f.
id()] = afterVertex;
601 if ( segments.isEmpty() )
604 for ( QMap<QgsFeatureId, int>::const_iterator it = segments.constBegin(); it != segments.constEnd(); ++it )
607 int segmentAfterVertex = it.value();
610 int atVertex, beforeVertex, afterVertex;
611 double sqrDistVertexSnap;
612 geom.
closestVertex( p, atVertex, beforeVertex, afterVertex, sqrDistVertexSnap );
614 if ( sqrDistVertexSnap < sqrSnappingTolerance )
617 if ( !mLayer->
insertVertex( p, fid, segmentAfterVertex ) )
619 QgsDebugMsg( QStringLiteral(
"failed to insert topo point" ) );
632 bool QgsVectorLayerEditUtils::boundingBoxFromPointList(
const QgsPointSequence &list,
double &xmin,
double &ymin,
double &xmax,
double &ymax )
const
639 xmin = std::numeric_limits<double>::max();
640 xmax = -std::numeric_limits<double>::max();
641 ymin = std::numeric_limits<double>::max();
642 ymax = -std::numeric_limits<double>::max();
644 for ( QgsPointSequence::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
646 if ( it->x() < xmin )
650 if ( it->x() > xmax )
654 if ( it->y() < ymin )
658 if ( it->y() > ymax )
Abstract base class for curved geometry type.
@ Success
Operation succeeded.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
QgsCoordinateReferenceSystem crs
double geometryPrecision() const
The precision in which geometries on this layer should be saved.
OperationResult addPart(const QVector< QgsPointXY > &points, QgsWkbTypes::GeometryType geomType=QgsWkbTypes::UnknownGeometry)
Adds a new part to a the geometry.
Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
Q_DECL_DEPRECATED QgsGeometry::OperationResult splitParts(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits parts cut by the given line.
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
Point geometry type, with support for z-dimension and m-values.
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...
void setXMinimum(double x)
Set the minimum x value.
@ NothingHappened
Nothing happened, without any error.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
QgsGeometryOptions * geometryOptions() const
Configuration and logic to apply automatically on any edit happening on this layer.
OperationResult addRing(const QVector< QgsPointXY > &ring)
Adds a new ring to this geometry.
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
virtual bool doesStrictFeatureTypeCheck() const
Returns true if the provider is strict about the type of inserted features (e.g.
OperationResult
Success or failure of a geometry operation.
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...
Line string geometry type, with support for z-dimension and m-values.
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 ...
int addTopologicalPoints(const QgsGeometry &geom)
Adds topological points for every vertex of the geometry.
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...
@ AddPartSelectedGeometryNotFound
The selected geometry cannot be found.
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...
@ EmptyGeometry
Edit operation resulted in an empty geometry.
@ EditFailed
Edit operation failed.
Q_DECL_DEPRECATED QgsGeometry::OperationResult addPart(const QVector< QgsPointXY > &ring, QgsFeatureId featureId)
Adds a new part polygon to a multipart feature.
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),...
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
bool convertToSingleType()
Converts multi type geometry into single type geometry e.g.
const Q_INVOKABLE QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
bool deleteVertex(int atVertex)
Deletes the vertex at the given position number and item (first number is index 0)
QMap< int, QVariant > QgsAttributeMap
@ DistanceFeet
Imperial feet.
void setXMaximum(double x)
Set the maximum x value.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsAttributeMap toMap() const
Returns a QgsAttributeMap of the attribute values.
static bool isSingleType(Type type)
Returns true if the WKB type is a single type.
Q_DECL_DEPRECATED OperationResult splitGeometry(const QVector< QgsPointXY > &splitLine, QVector< QgsGeometry > &newGeometries, bool topological, QVector< QgsPointXY > &topologyTestPoints, bool splitFeature=true)
Splits this geometry according to a given line.
QSet< QgsFeatureId > QgsFeatureIds
double yMaximum() const
Returns the y maximum value (top side of rectangle).
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 splitFeatures(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits features cut by the given line.
QgsCurve * clone() const override=0
Clones the geometry by performing a deep copy.
QgsFeatureIterator getSelectedFeatures(QgsFeatureRequest request=QgsFeatureRequest()) const
Returns an iterator of the selected features.
QgsUnitTypes::DistanceUnit mapUnits
bool nextFeature(QgsFeature &f)
QVector< QgsPoint > QgsPointSequence
@ InvalidBaseGeometry
The base geometry on which the operation is done is invalid or empty.
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 convertToMultiType()
Converts single type geometry into multitype geometry e.g.
OperationResult translate(double dx, double dy, double dz=0.0, double dm=0.0)
Translates this geometry by dx, dy, dz and dm.
QgsRectangle boundingBox() const override
Returns the minimal bounding box for the geometry.
double height() const
Returns the height of the rectangle.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
@ FetchFeatureFailed
Unable to fetch requested feature.
@ InvalidLayer
Edit failed due to invalid layer.
QgsVectorLayerEditUtils(QgsVectorLayer *layer)
QgsAbstractGeometry::vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
Q_DECL_DEPRECATED QgsGeometry::OperationResult addRing(const QVector< QgsPointXY > &ring, const QgsFeatureIds &targetFeatureIds=QgsFeatureIds(), QgsFeatureId *modifiedFeatureId=nullptr)
Adds a ring to polygon/multipolygon features.
int selectedFeatureCount() const
Returns the number of features that are selected in this layer.
EditResult
Result of an edit operation.
QgsAbstractGeometry::vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
@ Success
Edit operation was successful.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) FINAL
Adds a single feature to the sink.
bool isEmpty() const
Returns true if the rectangle is empty.
@ AddRingNotInExistingFeature
The input ring doesn't have any existing ring to fit into.
void set(QgsAbstractGeometry *geometry)
Sets the underlying geometry store.
double width() const
Returns the width of the rectangle.
void setYMinimum(double y)
Set the minimum y value.
void setYMaximum(double y)
Set the maximum y value.
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).
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.