Skip to content
Permalink
Browse files

Make 'merge' algorithm store the original layer name and source

  • Loading branch information
nyalldawson committed Jun 22, 2017
1 parent 00ead63 commit 33aa798c2aba649d53d1c1d80d7fe0dadaf03210
Showing with 18 additions and 1 deletion.
  1. +1 −1 python/plugins/processing/algs/help/qgis.yaml
  2. +17 −0 python/plugins/processing/algs/qgis/Merge.py
@@ -312,7 +312,7 @@ qgis:mergelines: >
qgis:mergevectorlayers: >
This algorithm combines multiple vector layers of the same geometry type into a single one.

If attributes tables are different, the attribute table of the resulting layer will contain the attributes from both input layers.
If attributes tables are different, the attribute table of the resulting layer will contain the attributes from all input layers. New attributes will be added for the original layer name and source.

The layers will all be reprojected to match the coordinate reference system of the first input layer.

@@ -30,6 +30,7 @@
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtCore import QVariant
from qgis.core import (QgsFields,
QgsField,
QgsFeatureRequest,
QgsProcessingUtils,
QgsProcessingParameterMultipleLayers,
@@ -104,6 +105,15 @@ def processAlgorithm(self, parameters, context, feedback):
if not found:
fields.append(sfield)

add_layer_field = False
if fields.lookupField('layer') < 0:
fields.append(QgsField('layer', QVariant.String, '', 100))
add_layer_field = True
add_path_field = False
if fields.lookupField('path') < 0:
fields.append(QgsField('path', QVariant.String, '', 200))
add_path_field = True

total = 100.0 / totalFeatureCount
dest_crs = layers[0].crs()
(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
@@ -118,6 +128,13 @@ def processAlgorithm(self, parameters, context, feedback):
sattributes = feature.attributes()
dattributes = []
for dindex, dfield in enumerate(fields):
if add_layer_field and dfield.name() == 'layer':
dattributes.append(layer.name())
continue
if add_path_field and dfield.name() == 'path':
dattributes.append(layer.publicSource())
continue

if (dfield.type() == QVariant.Int, QVariant.UInt, QVariant.LongLong, QVariant.ULongLong):
dattribute = 0
elif (dfield.type() == QVariant.Double):

0 comments on commit 33aa798

Please sign in to comment.
You can’t perform that action at this time.