3

I do QGIS based application, I need to implement the ability to modify the geometry of vector layers in manual mode (editing nodes), how to do it?

3

QGIS Vector Layer Class

You will need to become familiar with layer attributes and features. The QGIS Vector Layer Class Reference will be a good source of information.

Basic Workflow

The basic workflow will be to:

  1. Select the layer via the QgsVectorLayer class
  2. Get some or all features in the layer with the getFeatures()
  3. Work with the feature geometry (with insertVertex(), moveVertex(), deleteVertex(), etc.

Example

# Load a vector layer
layer = QgsVectorLayer('/path/to/layer.shp',"Legend Name", "ogr")

# E.g. Set up a rectangle for use as a bounding box query
filter_rectangle = QgsRectangle(-100, 50, -130, 60)   

# Create a feature request object
feature_query = QgsFeatureRequest().setFilterRect(filter_rectangle)

# Get a set of features for manipulation, using the feature query object
features = layer.getFeatures(feature_query)

# You can now iterate through the features
for feature in features:
    # Do something

Further Reading

The above code was adapted from the PyQGIS Programmer's Guide.

1

You can download the Digitizing Tools plugin. Once enabled, select Toggle Editing then you can play around with editing geometries, shapes etc with the available functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.