QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
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() )
174 if ( modifiedFeatureId )
175 *modifiedFeatureId = f.
id();
183 return addRingReturnCode;
189 for ( QVector<QgsPointXY>::const_iterator it = points.constBegin(); it != points.constEnd(); ++it )
193 return addPart( l, featureId );
202 bool firstPart =
false;
237 bool firstPart =
false;
289 for ( QVector<QgsPointXY>::const_iterator it = splitLine.constBegin(); it != splitLine.constEnd(); ++it )
300 bool preserveCircular =
false;
301 return splitFeatures( &lineString, topologyTestPoints, preserveCircular, topologicalEditing );
312 int numberOfSplitFeatures = 0;
320 if ( !selectedIds.isEmpty() )
337 else if ( bBox.
height() == 0.0 && bBox.
width() > 0 )
345 double bufferDistance = 0.000001;
347 bufferDistance = 0.00000001;
367 QVector<QgsGeometry> newGeometries;
370 splitFunctionReturn = featureGeom.
splitGeometry( curve, newGeometries, preserveCircular, topologicalEditing, featureTopologyTestPoints );
371 topologyTestPoints.append( featureTopologyTestPoints );
379 for (
const QgsGeometry &geom : std::as_const( newGeometries ) )
384 if ( topologicalEditing )
386 QgsPointSequence::const_iterator topol_it = featureTopologyTestPoints.constBegin();
387 for ( ; topol_it != featureTopologyTestPoints.constEnd(); ++topol_it )
392 ++numberOfSplitFeatures;
396 returnCode = splitFunctionReturn;
400 if ( !featuresDataToAdd.isEmpty() )
408 if ( numberOfSplitFeatures == 0 )
419 for ( QVector<QgsPointXY>::const_iterator it = splitLine.constBegin(); it != splitLine.constEnd(); ++it )
431 double xMin, yMin, xMax, yMax;
435 int numberOfSplitParts = 0;
445 if ( boundingBoxFromPointList( splitLine, xMin, yMin, xMax, yMax ) )
465 else if ( bBox.
height() == 0.0 && bBox.
width() > 0 )
473 double bufferDistance = 0.000001;
475 bufferDistance = 0.00000001;
489 QVector<QgsGeometry> newGeometries;
492 splitFunctionReturn = featureGeom.
splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints,
false );
499 for (
int i = 1; i < newGeometries.size(); ++i )
508 if ( topologicalEditing )
510 QgsPointSequence::const_iterator topol_it = topologyTestPoints.constBegin();
511 for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
516 ++numberOfSplitParts;
520 returnCode = splitFunctionReturn;
545 bool pointsAdded =
false;
557 return pointsAdded ? 0 : 2;
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 bool pointsAdded =
false;
613 for ( QMap<QgsFeatureId, int>::const_iterator it = segments.constBegin(); it != segments.constEnd(); ++it )
616 int segmentAfterVertex = it.value();
619 int atVertex, beforeVertex, afterVertex;
620 double sqrDistVertexSnap;
621 geom.
closestVertex( p, atVertex, beforeVertex, afterVertex, sqrDistVertexSnap );
623 if ( sqrDistVertexSnap < sqrSnappingTolerance )
626 if ( !mLayer->
insertVertex( p, fid, segmentAfterVertex ) )
628 QgsDebugMsg( QStringLiteral(
"failed to insert topo point" ) );
636 return pointsAdded ? 0 : 2;
649 bool pointsAdded =
false;
651 QgsPointSequence::const_iterator it = ps.constBegin();
652 while ( it != ps.constEnd() )
661 return pointsAdded ? 0 : 2;
670 bool QgsVectorLayerEditUtils::boundingBoxFromPointList(
const QgsPointSequence &list,
double &xmin,
double &ymin,
double &xmax,
double &ymax )
const
677 xmin = std::numeric_limits<double>::max();
678 xmax = -std::numeric_limits<double>::max();
679 ymin = std::numeric_limits<double>::max();
680 ymax = -std::numeric_limits<double>::max();
682 for ( QgsPointSequence::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
684 if ( it->x() < xmin )
688 if ( it->x() > xmax )
692 if ( it->y() < ymin )
696 if ( it->y() > ymax )
Abstract base class for curved geometry type.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
static bool isSingleType(Type type) SIP_HOLDGIL
Returns true if the WKB type is a single type.
QgsCoordinateReferenceSystem crs
bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) FINAL
Adds a list of features to the sink.
double geometryPrecision() const
The precision in which geometries on this layer should be saved.
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Qgis::GeometryOperationResult addPart(const QVector< QgsPointXY > &points, QgsWkbTypes::GeometryType geomType=QgsWkbTypes::UnknownGeometry)
Adds a new part to a the geometry.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
@ 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...
Qgis::VectorEditResult deleteVertex(QgsFeatureId featureId, int vertex)
Deletes a vertex from a feature.
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
QgsGeometryOptions * geometryOptions() const
Configuration and logic to apply automatically on any edit happening on this layer.
@ FetchFeatureFailed
Unable to fetch requested feature.
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.
Encapsulate geometry and attributes for new features, to be passed to createFeatures.
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.
A rectangle specified with double values.
Q_DECL_DEPRECATED Qgis::GeometryOperationResult splitGeometry(const QVector< QgsPointXY > &splitLine, QVector< QgsGeometry > &newGeometries, bool topological, QVector< QgsPointXY > &topologyTestPoints, bool splitFeature=true)
Splits this geometry according to a given line.
QgsPointXY closestVertex(const QgsPointXY &point, int &closestVertexIndex, int &previousVertexIndex, int &nextVertexIndex, double &sqrDist) const
Returns the vertex closest to the given point, the corresponding vertex index, squared distance snap ...
@ EmptyGeometry
Edit operation resulted in an empty geometry.
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...
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...
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
This class wraps a request for features to a vector layer (or directly its vector data provider).
Qgis::GeometryOperationResult addRing(const QVector< QgsPointXY > &ring)
Adds a new ring to this geometry.
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),...
QList< QgsVectorLayerUtils::QgsFeatureData > QgsFeaturesDataList
Alias for list of QgsFeatureData.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Q_DECL_DEPRECATED Qgis::GeometryOperationResult addRing(const QVector< QgsPointXY > &ring, const QgsFeatureIds &targetFeatureIds=QgsFeatureIds(), QgsFeatureId *modifiedFeatureId=nullptr)
Adds a ring to polygon/multipolygon features.
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.
@ InvalidLayer
Edit failed due to invalid layer.
GeometryOperationResult
Success or failure of a geometry operation.
bool deleteVertex(int atVertex)
Deletes the vertex at the given position number and item (first number is index 0)
QList< QgsFeature > QgsFeatureList
QMap< int, QVariant > QgsAttributeMap
@ DistanceFeet
Imperial feet.
void setXMinimum(double x) SIP_HOLDGIL
Set the minimum x value.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
@ EditFailed
Edit operation failed.
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double closestSegmentWithContext(const QgsPointXY &point, QgsPointXY &minDistPoint, int &nextVertexIndex, int *leftOrRightOfSegment=nullptr, double epsilon=DEFAULT_SEGMENT_EPSILON) const
Searches for the closest segment of geometry to the given point.
CORE_EXPORT QgsAttributeMap toMap() const
Returns a QgsAttributeMap of the attribute values.
@ AddRingNotInExistingFeature
The input ring doesn't have any existing ring to fit into.
@ Success
Edit operation was successful.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QSet< QgsFeatureId > QgsFeatureIds
Qgis::GeometryOperationResult translate(double dx, double dy, double dz=0.0, double dm=0.0)
Translates this geometry by dx, dy, dz and dm.
void setXMaximum(double x) SIP_HOLDGIL
Set the maximum x value.
A class to represent a 2D point.
void setYMaximum(double y) SIP_HOLDGIL
Set the maximum y value.
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
@ InvalidBaseGeometry
The base geometry on which the operation is done is invalid or empty.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Q_DECL_DEPRECATED Qgis::GeometryOperationResult splitFeatures(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits features cut by the given line.
The vertex_iterator class provides STL-style iterator for vertices.
bool nextFeature(QgsFeature &f)
void setYMinimum(double y) SIP_HOLDGIL
Set the minimum y value.
QVector< QgsPoint > QgsPointSequence
A geometry is the spatial representation of a feature.
Represents a vector layer which manages a vector based data sets.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
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)...
@ Success
Operation succeeded.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
VectorEditResult
Specifies the result of a vector layer edit operation.
QgsRectangle boundingBox() const override
Returns the minimal bounding box for the geometry.
Q_DECL_DEPRECATED Qgis::GeometryOperationResult addPart(const QVector< QgsPointXY > &ring, QgsFeatureId featureId)
Adds a new part polygon to a multipart feature.
static QgsFeatureList createFeatures(const QgsVectorLayer *layer, const QgsFeaturesDataList &featuresData, QgsExpressionContext *context=nullptr)
Creates a set of new features ready for insertion into a layer.
QgsVectorLayerEditUtils(QgsVectorLayer *layer)
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QgsAbstractGeometry::vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
int selectedFeatureCount() const
Returns the number of features that are selected in this layer.
QgsAbstractGeometry::vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
@ AddPartSelectedGeometryNotFound
The selected geometry cannot be found.
Wrapper for iterator of features from vector data provider or vector layer.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
@ NothingHappened
Nothing happened, without any error.
bool isEmpty() const
Returns true if the rectangle is empty.
@ InvalidInputGeometryType
The input geometry (ring, part, split line, etc.) has not the correct geometry type.
void set(QgsAbstractGeometry *geometry)
Sets the underlying geometry store.
Q_DECL_DEPRECATED Qgis::GeometryOperationResult splitParts(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits parts cut by the given line.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features