[Qgis-developer] Insert/Update in existing layers using Processing

Arnaud Morvan arnaud.morvan at camptocamp.com
Tue Apr 12 08:49:21 PDT 2016


Hello,

Actually in QGIS, updating an existing layer with data coming from other 
layers, files or processing output is not trivial.
=> It is possible to copy/paste features from one layer to another, but 
no user friendly possibility to define fields mapping.
=> Processing algorithms always create new layers, but do not give the 
possibility to update an existing one.
=> "Import to Postgis" algorithm can be used for table creation too, no 
updating options.
=> DB Manager have the same limitations.

We want to improve this in QGIS and we have some propositions (see below).
Let me know what you think about this. Should we create a QEP ?


        1 - Create a new processing algorithm "Import into existing layer"

This algorithm would give the possibility to update / insert into an 
existing layer,
with data coming from file, loaded layer or processing output .
This would give the possibility to wrote, from processing, to any type 
of datasource that support writing.

     Here's the inputs :
         Source layer (vector): Vector layer for reading
         Source identifier (field): Primary key in source layer

         Destination layer (vector) : Vector layer for writing
         Destination identifier (field) : Primary key in destination layer

         Insert new features (checkbox) : Insert new features in 
destination layer.
         Update existing features (checkbox) : Update existing features 
in destination layer.
         Delete features (checkbox) : Should features, that do not exits 
in source, be deleted from destination ?

     No output, as a result, inserted and updated features could be 
selected.

The identifier fields give a one/one relationship between source and 
destination layer.

Regarding the writing method, I see two possibilities :

     * Use the edition buffer, the user could see the result before 
saving to disk or database.
         Note that this could use a lot of memory in case of treating a 
lot of data.

     * Use directly the provider methods.

Maybe we could propose a choice between this two methods.

Thereafter, the user should expect a field mapper from the source to the 
destination (possibly with the use of expressions).
For exporting, we can use the refactorfield as an final output algorithm.
For importing, fields already exists on destination, here it should be 
simpler than refactorfield mapper.
Note that we will not have source/destination fields definition in all 
cases, only for loaded layers.


        2 - Update input layer with "Import into existing layer" after
        existing algorithms


As a second time, we could add an option on some existing algorithm,
     with only one input layer,
     that do not change fields definition,
that add a checkbox or output option in algorithm dialog, to update the 
input layer as an output.

For example, I want to make a buffer on a selection in a loaded vector 
layer.
In most case, I want this to be done on the source layer, not in a new 
layer.
Processing do not give this possibility for now.

What I propose is not to change existing algorithms, but to add an 
output option in the dialog.
As a result, after running the base algorithm, an import would be done 
using the feature Id as a primary key to update the input layer using 
edition buffer.

This would be user friendly for common operations on existing layers.


        3 - Propose a field mapping for paste operation

This take place on the c++ part of QGIS, in the Edit / Paste features 
(Ctrl+V) action in main menu.
Actually, when we paste features from one layer to another, fields that 
do not exists on destination layer are lost without warning.
We should expect a field mapper dialog here, close to the one in 
previous proposition.

Best regards.

-- 
Arnaud Morvan
Ingénieur logiciel
Tél: +33 (0)4 58 48 20 32

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac Cedex
http://www.camptocamp.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160412/db2316f2/attachment.html>


More information about the Qgis-developer mailing list