Book Image

Building Mapping Applications with QGIS

By : Erik Westra
Book Image

Building Mapping Applications with QGIS

By: Erik Westra

Overview of this book

Table of Contents (16 chapters)
Building Mapping Applications with QGIS
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Getting Started with QGIS
Index

Using the layer editing mode


To let the user change the contents of a map layer, you first have to turn on the editing mode for that layer. The layer editing mode is similar to the way transactions are handled in a database:

The changes you make to the layer are held in memory until you decide to either commit the changes to the layer, or roll back the changes to discard them. The following pseudocode is an example of how to implement this using PyQGIS:

layer.startEditing()

# ...make changes...

if modified:
    reply = QMessageBox.question(window, "Confirm",
                                 "Save changes to layer?",
                                 QMessageBox.Yes | QMessageBox.No,
                                 QMessageBox.Yes)
    if reply == QMessageBox.Yes:
        layer.commitChanges()
    else:
        line.rollBack()
else:
     layer.rollBack()

As you can see, we turn on the editing mode for a given map layer by calling layer.startEditing(). As well as set up an internal editing...