Date 2018/03/02
Author Alessandro Pasotti (@elpaso), Nyall Dawson (@nyalldawson )
Contact elpaso at itopen dot it, nyall dot dawson at gmail dotcom
maintainer @elpaso, @nyalldawson
Version QGIS 3.2
Given a layer opened for editing and a set of selected features, this enhancement will allow a user to execute suitable algorithms on the selected features directly modifying feature geometry in-place.
For an algorithm to be suitable for in-place modifications it needs to support operations on isolated features, it must not change the wkb type of the input geometry and must not add or remove or change the type of any field in the layer.
The proposed solution add a tri-state tool button to the processing toolbar, the button becomes checkable when the user selects some features in an editable layer.
When the button is pressed, the processing toolbar enters in modify-in-place mode and it filters the algorithms that are suitable to be executed on a set of features and allow geometries in-place modification of the geometries.
The algorithm dialog input and output fields will be hidden when the dialog is opened in this mode.
If the algorithm does not have any additional user-set parameters (excluding the usual input and output layer parameters), then the algorithm will be run immediately over the selected features without any dialog popup.
The locator input box could also be used as additional mean to run the algorithms for advanced users or touch typers.
The typical workflow will be:
- user makes a layer editable
- makes selection on the layer
- runs the algorithm in a special mode (* see note below)
- the selected features are iterated over, modifying each by pushing
them through the algorithm's
processFeature
method, and then storing them back in the layer's edit buffer viaQgsVectorLayer::updateFeature
(run in the main thread, not a task - we're editing the layer so we can't do it in the background.)
Existing algorithms that are suitable for in-place geometry modifications
are all algorithms which derive from QgsProcessingFeatureBasedAlgorithm
for example: buffering (for polygons), simplification, smoothing, translation, offsetting, densification, make valid, remove
duplicate vertices, remove hole, reverse line directions and multiparts to singleparts.
Currently, it is very difficult to perform "in-place", algorithm-based edits on geometries within QGIS. To perform a common task like reversing the direction of a set of linestrings requires users to run the corresponding processing algorithm over the selected features, causing a new layer to be created with the result. The original layer features must then be deleted, and the reversed features from the new layer manually copied and pasted back into the original layer. These manual tasks are tedious and error-prone.
Neither is it is not a feasible long-term solution to add additional editing tools to the QGIS Edit menu or Advanced Digitizing toolbar. These menus and toolbars are already home to many actions, and adding additional actions here causes UI clutter and makes QGIS more unfriendly for new users.
Similarly, relying on 3rd party plugins to perform these editing operations is not an ideal long-term solution either, as the plugins also must add additional actions to QGIS and also add to UI clutter.
By leveraging QGIS' processing algorithms, we can immediately expose dozens of desired in-place editing operations without any code duplication. 3rd party plugins can easily extend the feature by implementing their operations as processing algorithms derived from QgsFeatureBasedAlgorithm (which also has the side-benefit of allowing these plugin-provided operations to be fully operational within processing models and accessible for Python scripting). Furthermore, the QGIS algorithms are extensively unit tested, ensuring that the in-place editing operations will be error-free.
Affected files are mainly in python processing plugin, some signal/slot connections must also be created to keep the UI in sync with feature selection in an editable layer.
In the C++ side, QgsProcessingAlgorithm::Flag
requires a new flag to mark algorithms that are suitable
for in-place operations.
None
No issues.
(required)