Class: QgsVectorLayerEditUtils¶
Contains utility functions for editing vector layers.
Methods
Adds a new part polygon to a multipart feature |
|
Adds a ring to polygon/multipolygon features |
|
Adds a new part polygon to a multipart feature |
|
Adds a ring to polygon/multipolygon features |
|
Adds a ring to polygon/multipolygon features |
|
Adds topological points for every vertex of the geometry. |
|
Deletes a vertex from a feature. |
|
Insert a new vertex before the given vertex number, in the given ring, item (first number is index 0), and feature Not meaningful for Point geometries |
|
Merge features into a single one. |
|
Moves the vertex at the given position number, ring and item (first number is index 0), and feature to the given coordinates |
|
Moves the vertex at the given position number, ring and item (first number is index 0), and feature to the given coordinates |
|
Splits features cut by the given line |
|
Splits parts cut by the given line |
|
Translates feature by dx, dy |
- class qgis.core.QgsVectorLayerEditUtils[source]¶
Bases:
object
- addCurvedPart(self, ring: QgsCurve | None, featureId: int) Qgis.GeometryOperationResult ¶
Adds a new part polygon to a multipart feature
- Return type:
- Returns:
QgsGeometry
.SuccessQgsGeometry
.AddPartSelectedGeometryNotFoundQgsGeometry
.AddPartNotMultiGeometryQgsGeometry
.InvalidBaseGeometryQgsGeometry
.InvalidInput
- Parameters:
ring (Optional[QgsCurve])
featureId (int)
- addCurvedRing(self, ring: QgsCurve | None, targetFeatureIds: Any = QgsFeatureIds())¶
Adds a ring to polygon/multipolygon features
- Parameters:
ring (Optional[QgsCurve]) – ring to add
targetFeatureIds (Any = QgsFeatureIds()) -> (Qgis.GeometryOperationResult) – if specified, only these features will be the candidates for adding a ring. Otherwise all intersecting features are tested and the ring is added to the first valid feature.
modifiedFeatureId – if specified, feature ID for feature that ring was added to will be stored in this parameter
- Returns:
OperationResult result code: success or reason of failure
- addPart(self, ring: Iterable[QgsPointXY], featureId: int) Qgis.GeometryOperationResult [source]¶
Adds a new part polygon to a multipart feature
- Return type:
- Returns:
QgsGeometry
.SuccessQgsGeometry
.AddPartSelectedGeometryNotFoundQgsGeometry
.AddPartNotMultiGeometryQgsGeometry
.InvalidBaseGeometryQgsGeometry
.InvalidInput
Deprecated since version 3.12: Will be removed in QGIS 4.0. Use the variant which accepts
QgsPoint
objects instead ofQgsPointXY
.- Parameters:
ring (Iterable[QgsPointXY])
featureId (int)
- addPart(self, ring: Iterable[QgsPoint], featureId: int) Qgis.GeometryOperationResult [source]
Adds a new part polygon to a multipart feature
- Return type:
- Returns:
QgsGeometry
.SuccessQgsGeometry
.AddPartSelectedGeometryNotFoundQgsGeometry
.AddPartNotMultiGeometryQgsGeometry
.InvalidBaseGeometryQgsGeometry
.InvalidInput
Note
available in python bindings as addPartV2
- Parameters:
ring (Iterable[QgsPoint])
featureId (int)
- addRing(self, ring: Iterable[QgsPointXY], targetFeatureIds: Any = QgsFeatureIds())[source]¶
Adds a ring to polygon/multipolygon features
- Parameters:
ring (Iterable[QgsPointXY]) – ring to add
targetFeatureIds (Any = QgsFeatureIds()) -> (Qgis.GeometryOperationResult) – if specified, only these features will be the candidates for adding a ring. Otherwise all intersecting features are tested and the ring is added to the first valid feature.
modifiedFeatureId – if specified, feature ID for feature that ring was added to will be stored in this parameter
- Returns:
OperationResult result code: success or reason of failure
Deprecated since version 3.12: Will be removed in QGIS 4.0. Use the variant which accepts
QgsPoint
objects instead ofQgsPointXY
.
- addRing(self, ring: Iterable[QgsPoint], targetFeatureIds: Any = QgsFeatureIds())[source]
Adds a ring to polygon/multipolygon features
- Parameters:
ring (Iterable[QgsPoint]) – ring to add
targetFeatureIds (Any = QgsFeatureIds()) -> (Qgis.GeometryOperationResult) – if specified, only these features will be the candidates for adding a ring. Otherwise all intersecting features are tested and the ring is added to the first valid feature.
modifiedFeatureId – if specified, feature ID for feature that ring was added to will be stored in this parameter
- Returns:
OperationResult result code: success or reason of failure
- addRingV2(self, ring: QgsCurve | None, targetFeatureIds: Any = QgsFeatureIds())[source]¶
Adds a ring to polygon/multipolygon features
- Parameters:
ring (Optional[QgsCurve]) – ring to add (ownership is transferred)
targetFeatureIds (Any = QgsFeatureIds()) -> (Qgis.GeometryOperationResult) – if specified, only these features will be the candidates for adding a ring. Otherwise all intersecting features are tested and the ring is added to all valid features.
- Returns:
OperationResult result code: success or reason of failure
modifiedFeatureIds: feature IDS for features that ring was added to will be stored in this parameter
Added in version 3.28.
- addTopologicalPoints(self, geom: QgsGeometry) int [source]¶
Adds topological points for every vertex of the geometry.
- Parameters:
geom (
QgsGeometry
) – the geometry where each vertex is added to segments of other features- Returns:
0 in case of success
- Returns:
1 in case of error
- Return type:
int
- Returns:
2 in case no vertices needed to be added
Note
geom is not going to be modified by the function
- addTopologicalPoints(self, p: QgsPointXY) int [source]
Adds a vertex to segments which intersect point
p
but don’t already have a vertex there. If a feature already has a vertex at position p, no additional vertex is inserted. This method is useful for topological editing.- Returns:
0 in case of success
- Returns:
1 in case of error
- Return type:
int
- Returns:
2 in case no vertices needed to be added
- Parameters:
p (
QgsPointXY
)
- addTopologicalPoints(self, p: QgsPoint) int [source]
Adds a vertex to segments which intersect point
p
but don’t already have a vertex there. If a feature already has a vertex at position p, no additional vertex is inserted. This method is useful for topological editing.- Returns:
0 in case of success
- Returns:
1 in case of error
- Return type:
int
- Returns:
2 in case no vertices needed to be added
Added in version 3.10.
- Parameters:
p (
QgsPoint
)
- addTopologicalPoints(self, ps: Iterable[QgsPoint]) int [source]
Adds a vertex to segments which intersect point
p
but don’t already have a vertex there. If a feature already has a vertex at position p, no additional vertex is inserted. This method is useful for topological editing.- Returns:
0 in case of success
- Returns:
1 in case of error
- Return type:
int
- Returns:
2 in case vertex already exists or point does not intersect segment
Added in version 3.16.
- Parameters:
ps (Iterable[QgsPoint])
- deleteVertex(self, featureId: int, vertex: int) Qgis.VectorEditResult [source]¶
Deletes a vertex from a feature.
- Parameters:
featureId (int) – ID of feature to remove vertex from
vertex (int) – index of vertex to delete
- Return type:
- insertVertex(self, x: float, y: float, atFeatureId: int, beforeVertex: int) bool [source]¶
Insert a new vertex before the given vertex number, in the given ring, item (first number is index 0), and feature Not meaningful for Point geometries
- Parameters:
x (float)
y (float)
atFeatureId (int)
beforeVertex (int)
- Return type:
bool
- insertVertex(self, point: QgsPoint, atFeatureId: int, beforeVertex: int) bool [source]
Inserts a new vertex before the given vertex number, in the given ring, item (first number is index 0), and feature Not meaningful for Point geometries
- Parameters:
point (
QgsPoint
)atFeatureId (int)
beforeVertex (int)
- Return type:
bool
- mergeFeatures(self, targetFeatureId: int, mergeFeatureIds: Any, mergeAttributes: Any, unionGeometry: QgsGeometry)[source]¶
Merge features into a single one.
- Parameters:
targetFeatureId (int) – id of the target feature (will be updated)
mergeFeatureIds (Any) – id list of features to merge (will be deleted)
mergeAttributes (Any) – are the resulting attributes in the merged feature
unionGeometry (
QgsGeometry
) -> (bool) – is the resulting geometry of the merged feature
- Returns:
True
if the merge was successful, orFalse
if the operation failed.errorMessage: a descriptive error message if any occurs
Added in version 3.30.
- moveVertex(self, x: float, y: float, atFeatureId: int, atVertex: int) bool [source]¶
Moves the vertex at the given position number, ring and item (first number is index 0), and feature to the given coordinates
- Parameters:
x (float)
y (float)
atFeatureId (int)
atVertex (int)
- Return type:
bool
- moveVertexV2(self, p: QgsPoint, atFeatureId: int, atVertex: int) bool ¶
Moves the vertex at the given position number, ring and item (first number is index 0), and feature to the given coordinates
- Parameters:
p (QgsPoint)
atFeatureId (int)
atVertex (int)
- Return type:
bool
- splitFeatures(self, splitLine: Iterable[QgsPointXY], topologicalEditing: bool = False) Qgis.GeometryOperationResult [source]¶
Splits features cut by the given line
- Parameters:
splitLine (Iterable[QgsPointXY]) – line that splits the layer features
topologicalEditing (bool = False) –
True
if topological editing is enabled
- Return type:
- Returns:
QgsGeometry
.OperationResult
Deprecated since version 3.12: Will be removed in QGIS 4.0. Use the variant which accepts
QgsPoint
objects instead ofQgsPointXY
.
- splitFeatures(self, splitLine: Iterable[QgsPoint], topologicalEditing: bool = False) Qgis.GeometryOperationResult [source]
Splits features cut by the given line
- Parameters:
splitLine (Iterable[QgsPoint]) – line that splits the layer features
topologicalEditing (bool = False) –
True
if topological editing is enabled
- Return type:
- Returns:
QgsGeometry
.OperationResult
- splitFeatures(self, curve: QgsCurve | None, preserveCircular: bool = False, topologicalEditing: bool = False)[source]
Splits features cut by the given curve
- Parameters:
curve (Optional[QgsCurve]) – line that splits the layer features
preserveCircular (bool = False) – whether circular strings are preserved after splitting
topologicalEditing (bool = False) -> (Qgis.GeometryOperationResult) –
True
if topological editing is enabled
- Returns:
QgsGeometry
.OperationResulttopologyTestPoints: topological points to be tested against other layers
Added in version 3.16.
- splitParts(self, splitLine: Iterable[QgsPointXY], topologicalEditing: bool = False) Qgis.GeometryOperationResult [source]¶
Splits parts cut by the given line
- Parameters:
splitLine (Iterable[QgsPointXY]) – line that splits the layer feature parts
topologicalEditing (bool = False) –
True
if topological editing is enabled
- Return type:
- Returns:
QgsGeometry
.InvalidBaseGeometryQgsGeometry
.SuccessQgsGeometry
.InvalidInputQgsGeometry
.NothingHappened if a selection is present but no feature has been splitQgsGeometry
.InvalidBaseGeometryQgsGeometry
.GeometryEngineErrorQgsGeometry
.SplitCannotSplitPoint
Deprecated since version 3.12: Will be removed in QGIS 4.0. Use the variant which accepts
QgsPoint
objects instead ofQgsPointXY
.
- splitParts(self, splitLine: Iterable[QgsPoint], topologicalEditing: bool = False) Qgis.GeometryOperationResult [source]
Splits parts cut by the given line
- Parameters:
splitLine (Iterable[QgsPoint]) – line that splits the layer feature parts
topologicalEditing (bool = False) –
True
if topological editing is enabled
- Return type:
- Returns:
QgsGeometry
.InvalidBaseGeometryQgsGeometry
.SuccessQgsGeometry
.InvalidInputQgsGeometry
.NothingHappened if a selection is present but no feature has been splitQgsGeometry
.InvalidBaseGeometryQgsGeometry
.GeometryEngineErrorQgsGeometry
.SplitCannotSplitPoint