@@ -42,6 +42,7 @@ QString QgsMergeVectorAlgorithm::group() const
42
42
void QgsMergeVectorAlgorithm::initAlgorithm ( const QVariantMap & )
43
43
{
44
44
addParameter ( new QgsProcessingParameterMultipleLayers ( QStringLiteral ( " LAYERS" ), QObject::tr ( " Input layers" ), QgsProcessing::TypeVector ) );
45
+ addParameter ( new QgsProcessingParameterCrs ( QStringLiteral ( " CRS" ), QObject::tr ( " Destination CRS" ), QVariant (), true ) );
45
46
addParameter ( new QgsProcessingParameterFeatureSink ( QStringLiteral ( " OUTPUT" ), QObject::tr ( " Merged" ) ) );
46
47
}
47
48
@@ -50,9 +51,10 @@ QString QgsMergeVectorAlgorithm::shortHelpString() const
50
51
return QObject::tr ( " This algorithm combines multiple vector layers of the same geometry type into a single one.\n\n "
51
52
" If attributes tables are different, the attribute table of the resulting layer will contain the attributes "
52
53
" from all input layers. New attributes will be added for the original layer name and source.\n\n "
53
- " The layers will all be reprojected to match the coordinate reference system of the first input layer.\n\n "
54
54
" If any input layers contain Z or M values, then the output layer will also contain these values. Similarly, "
55
- " if any of the input layers are multi-part, the output layer will also be a multi-part layer." );
55
+ " if any of the input layers are multi-part, the output layer will also be a multi-part layer.\n\n "
56
+ " Optionally, the destination coordinate reference system (CRS) for the merged layer can be set. If it is not set, the CRS will be "
57
+ " taken from the first input layer. All layers will all be reprojected to match this CRS." );
56
58
}
57
59
58
60
QgsMergeVectorAlgorithm *QgsMergeVectorAlgorithm::createInstance () const
@@ -67,7 +69,10 @@ QVariantMap QgsMergeVectorAlgorithm::processAlgorithm( const QVariantMap ¶me
67
69
QgsFields outputFields;
68
70
long totalFeatureCount = 0 ;
69
71
QgsWkbTypes::Type outputType = QgsWkbTypes::Unknown;
70
- QgsCoordinateReferenceSystem outputCrs;
72
+ QgsCoordinateReferenceSystem outputCrs = parameterAsCrs ( parameters, QStringLiteral ( " CRS" ), context );
73
+
74
+ if ( outputCrs.isValid () )
75
+ feedback->pushInfo ( QObject::tr ( " Using specified destination CRS %1" ).arg ( outputCrs.authid () ) );
71
76
72
77
bool errored = false ;
73
78
@@ -92,8 +97,11 @@ QVariantMap QgsMergeVectorAlgorithm::processAlgorithm( const QVariantMap ¶me
92
97
93
98
QgsVectorLayer *vl = qobject_cast< QgsVectorLayer * >( layer );
94
99
95
- if ( !outputCrs.isValid () )
100
+ if ( !outputCrs.isValid () && vl->crs ().isValid () )
101
+ {
96
102
outputCrs = vl->crs ();
103
+ feedback->pushInfo ( QObject::tr ( " Taking destination CRS %1 from layer" ).arg ( outputCrs.authid () ) );
104
+ }
97
105
98
106
// check wkb type
99
107
if ( outputType != QgsWkbTypes::Unknown && outputType != QgsWkbTypes::NoGeometry )
@@ -138,8 +146,8 @@ QVariantMap QgsMergeVectorAlgorithm::processAlgorithm( const QVariantMap ¶me
138
146
found = true ;
139
147
if ( destField.type () != sourceField.type () )
140
148
{
141
- throw QgsProcessingException ( QObject::tr ( " %1 field in layer %2 has different data type than in other layers" )
142
- .arg ( sourceField.name () ) .arg ( i ) );
149
+ throw QgsProcessingException ( QObject::tr ( " %1 field in layer %2 has different data type than in other layers (%3 instead of %4) " )
150
+ .arg ( sourceField.name (), vl-> name () ) .arg ( sourceField. typeName () ). arg ( destField. typeName () ) );
143
151
}
144
152
break ;
145
153
}
0 commit comments