3

I'm working with an Oracle Spatial View (Oracle Database 11g Enterprise, 64bit) in QGIS (2.18.0).

There was the bad case that I (and other user) was selecting a lot of points and accidentally moved them and saved the changes to the layer.

Now, I want to avoid this, with a database (trigger, constraint) or application (QGIS, PyQGIS) solution.

The user has to be allowed to move only one geometry feature at once. It should not be allowed to select two feature and move them.

How to distinguish between: 2 objects were changed at one time (not wanted) and objects were changed at different times which is ok.

My idea is to ask the user if the changes to the point geometry has to be saved after moving it. "Save Layer Edits" in QGIS has to disabled in some way and only the dialog saves the changes.

Or you restrict the user to select only one feature in this layer.

UPDATE - PyQGIS

The code checks how much features are selected, while the layer is in edit mode.

layer=None
for lyr in QgsMapLayerRegistry.instance().mapLayers().values():
    if lyr.name() == "POINTS":
        layer = lyr

if layer.isEditable():
    selected_features = layer.selectedFeatures()

    selected_features_list = []
    for i in selected_features:
        selected_features_list.append(i["POINT_ID"])

    if len(selected_features_list) > 1:
        QMessageBox.warning(iface.mainWindow(),'Warning', 'You have selected more than one point. You can only move one point at once.')
        layer.removeSelection()
else:
    pass

This check has to be done between clicking/holding the select tool and releasing.

How can this be programmatically done?

Your Answer

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

Browse other questions tagged or ask your own question.