Class: QgsVectorLayerEditUtils

class qgis.core.QgsVectorLayerEditUtils(layer: QgsVectorLayer)
class qgis.core.QgsVectorLayerEditUtils(QgsVectorLayerEditUtils)

Bases: sip.wrapper

Methods

addCurvedPart

Adds a new part polygon to a multipart feature

addCurvedRing

Adds a ring to polygon/multipolygon features

addPart

Adds a new part polygon to a multipart feature

addRing

Adds a ring to polygon/multipolygon features

addRingV2

Adds a ring to polygon/multipolygon features

addTopologicalPoints

Adds topological points for every vertex of the geometry.

deleteVertex

Deletes a vertex from a feature.

insertVertex

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

mergeFeatures

Merge features into a single one.

moveVertex

Moves the vertex at the given position number, ring and item (first number is index 0), and feature to the given coordinates

moveVertexV2

Moves the vertex at the given position number, ring and item (first number is index 0), and feature to the given coordinates

splitFeatures

Splits features cut by the given line

splitParts

Splits parts cut by the given line

translateFeature

Translates feature by dx, dy

addCurvedPart(self, ring: QgsCurve, featureId: int) Qgis.GeometryOperationResult

Adds a new part polygon to a multipart feature

Return type:

Qgis.GeometryOperationResult

Returns:

Note

available in python bindings as addCurvedPart

Parameters:
  • ring (QgsCurve) –

  • featureId (int) –

addCurvedRing(self, ring: QgsCurve, targetFeatureIds: object = QgsFeatureIds()) Tuple[Qgis.GeometryOperationResult, int]

Adds a ring to polygon/multipolygon features

Parameters:
  • ring (QgsCurve) – ring to add

  • targetFeatureIds (object = QgsFeatureIds()) – 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

Return type:

Tuple[Qgis.GeometryOperationResult, int]

Returns:

OperationResult result code: success or reason of failure

Note

available in python bindings as addCurvedRing

addPart(self, ring: Iterable[QgsPointXY], featureId: int) Qgis.GeometryOperationResult

Adds a new part polygon to a multipart feature

Returns:

Deprecated since version QGIS: 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.

addPart(self, ring: Iterable[QgsPoint], featureId: int) -> Qgis.GeometryOperationResult Adds a new part polygon to a multipart feature

Return type:

Qgis.GeometryOperationResult

Returns:

Note

available in python bindings as addPartV2

Parameters:
  • ring (Iterable[QgsPointXY]) –

  • featureId (int) –

addRing(self, ring: Iterable[QgsPointXY], targetFeatureIds: object = QgsFeatureIds()) Tuple[Qgis.GeometryOperationResult, int]

Adds a ring to polygon/multipolygon features

Parameters:
  • ring (Iterable[QgsPointXY]) – ring to add

  • targetFeatureIds (object = QgsFeatureIds()) – 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 QGIS: 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.

addRing(self, ring: Iterable[QgsPoint], targetFeatureIds: object = QgsFeatureIds()) -> Tuple[Qgis.GeometryOperationResult, int] Adds a ring to polygon/multipolygon features

Parameters:
  • ring – ring to add

  • targetFeatureIds – 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

Return type:

Tuple[Qgis.GeometryOperationResult, int]

Returns:

OperationResult result code: success or reason of failure

addRingV2(self, ring: QgsCurve, targetFeatureIds: object = QgsFeatureIds()) Tuple[Qgis.GeometryOperationResult, object]

Adds a ring to polygon/multipolygon features

Parameters:
  • ring (QgsCurve) – ring to add (ownership is transferred)

  • targetFeatureIds (object = QgsFeatureIds()) – 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.

Return type:

Tuple[Qgis.GeometryOperationResult, object]

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

New in version 3.28.

addTopologicalPoints(self, geom: QgsGeometry) int

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

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 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

Returns:

2 in case no vertices needed to be added

addTopologicalPoints(self, p: QgsPoint) -> int 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

Returns:

2 in case no vertices needed to be added

New in version 3.10.

addTopologicalPoints(self, ps: Iterable[QgsPoint]) -> int 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

New in version 3.16.

deleteVertex(self, featureId: int, vertex: int) Qgis.VectorEditResult

Deletes a vertex from a feature.

Parameters:
  • featureId (int) – ID of feature to remove vertex from

  • vertex (int) – index of vertex to delete

New in version 2.14.

Return type:

Qgis.VectorEditResult

insertVertex(self, x: float, y: float, atFeatureId: int, beforeVertex: int) bool

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

insertVertex(self, point: QgsPoint, atFeatureId: int, beforeVertex: int) -> bool 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:
  • x (float) –

  • y (float) –

  • atFeatureId (int) –

  • beforeVertex (int) –

Return type:

bool

mergeFeatures(self, targetFeatureId: int, mergeFeatureIds: object, mergeAttributes: object, unionGeometry: QgsGeometry) Tuple[bool, str]

Merge features into a single one.

Parameters:
  • targetFeatureId (int) – id of the target feature (will be updated)

  • mergeFeatureIds (object) – id list of features to merge (will be deleted)

  • mergeAttributes (object) – are the resulting attributes in the merged feature

  • unionGeometry (QgsGeometry) – is the resulting geometry of the merged feature

Return type:

Tuple[bool, str]

Returns:

  • True if the merge was successful, or False if the operation failed.

  • errorMessage: will be set to a descriptive error message if any occurs

New in version 3.30.

moveVertex(self, x: float, y: float, 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:
  • 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

Note

available in Python bindings as moveVertexV2

Parameters:
  • p (QgsPoint) –

  • atFeatureId (int) –

  • atVertex (int) –

Return type:

bool

splitFeatures(self, splitLine: Iterable[QgsPointXY], topologicalEditing: bool = False) Qgis.GeometryOperationResult

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

Returns:

QgsGeometry.OperationResult

Deprecated since version QGIS: 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.

splitFeatures(self, splitLine: Iterable[QgsPoint], topologicalEditing: bool = False) -> Qgis.GeometryOperationResult Splits features cut by the given line

Parameters:
  • splitLine – line that splits the layer features

  • topologicalEditingTrue if topological editing is enabled

Returns:

QgsGeometry.OperationResult

splitFeatures(self, curve: QgsCurve, preserveCircular: bool = False, topologicalEditing: bool = False) -> Tuple[Qgis.GeometryOperationResult, List[QgsPoint]] Splits features cut by the given curve

Parameters:

curve – line that splits the layer features

param[out] topologyTestPoints topological points to be tested against other layers :param preserveCircular: whether circular strings are preserved after splitting :param topologicalEditing: True if topological editing is enabled

Return type:

Qgis.GeometryOperationResult

Returns:

QgsGeometry.OperationResult

New in version 3.16.

splitParts(self, splitLine: Iterable[QgsPointXY], topologicalEditing: bool = False) Qgis.GeometryOperationResult

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

Returns:

Deprecated since version QGIS: 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.

splitParts(self, splitLine: Iterable[QgsPoint], topologicalEditing: bool = False) -> Qgis.GeometryOperationResult Splits parts cut by the given line

Parameters:
  • splitLine – line that splits the layer feature parts

  • topologicalEditingTrue if topological editing is enabled

Return type:

Qgis.GeometryOperationResult

Returns:

translateFeature(self, featureId: int, dx: float, dy: float) int

Translates feature by dx, dy

Parameters:
  • featureId (int) – id of the feature to translate

  • dx (float) – translation of x-coordinate

  • dy (float) – translation of y-coordinate

Return type:

int

Returns:

0 in case of success