mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
Make 'merge' algorithm store the original layer name and source
This commit is contained in:
parent
00ead638ee
commit
33aa798c2a
@ -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 @@ import os
|
||||
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 @@ class Merge(QgisAlgorithm):
|
||||
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 @@ class Merge(QgisAlgorithm):
|
||||
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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user