QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
23 QString QgsMergeVectorAlgorithm::name()
const
25 return QStringLiteral(
"mergevectorlayers" );
28 QString QgsMergeVectorAlgorithm::displayName()
const
30 return QObject::tr(
"Merge vector layers" );
33 QStringList QgsMergeVectorAlgorithm::tags()
const
35 return QObject::tr(
"vector,layers,collect,merge,combine" ).split(
',' );
38 QString QgsMergeVectorAlgorithm::group()
const
40 return QObject::tr(
"Vector general" );
43 QString QgsMergeVectorAlgorithm::groupId()
const
45 return QStringLiteral(
"vectorgeneral" );
48 void QgsMergeVectorAlgorithm::initAlgorithm(
const QVariantMap & )
51 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"CRS" ), QObject::tr(
"Destination CRS" ), QVariant(),
true ) );
55 QString QgsMergeVectorAlgorithm::shortHelpString()
const
57 return QObject::tr(
"This algorithm combines multiple vector layers of the same geometry type into a single one.\n\n"
58 "If attributes tables are different, the attribute table of the resulting layer will contain the attributes "
59 "from all input layers. New attributes will be added for the original layer name and source.\n\n"
60 "If any input layers contain Z or M values, then the output layer will also contain these values. Similarly, "
61 "if any of the input layers are multi-part, the output layer will also be a multi-part layer.\n\n"
62 "Optionally, the destination coordinate reference system (CRS) for the merged layer can be set. If it is not set, the CRS will be "
63 "taken from the first input layer. All layers will all be reprojected to match this CRS." );
66 QgsMergeVectorAlgorithm *QgsMergeVectorAlgorithm::createInstance()
const
68 return new QgsMergeVectorAlgorithm();
73 const QList< QgsMapLayer * > layers = parameterAsLayerList( parameters, QStringLiteral(
"LAYERS" ), context );
76 long totalFeatureCount = 0;
96 feedback->
pushDebugInfo( QObject::tr(
"Error retrieving map layer." ) );
116 throw QgsProcessingException( QObject::tr(
"All layers must have same geometry type! Encountered a %1 layer when expecting a %2 layer." )
148 for (
QgsField &destField : outputFields )
150 if ( destField.name().compare( sourceField.name(), Qt::CaseInsensitive ) == 0 )
153 if ( destField.type() != sourceField.type() )
155 feedback->
pushInfo( QObject::tr(
"%1 field in layer %2 has different data type than the destination layer (%3 instead of %4)" )
156 .arg( sourceField.name(), vl->
name(), sourceField.typeName(), destField.typeName() ) );
157 destField.setType( QVariant::String );
158 destField.setSubType( QVariant::Invalid );
159 destField.setLength( 0 );
166 outputFields.append( sourceField );
170 bool addLayerField =
false;
171 if ( outputFields.lookupField( QStringLiteral(
"layer" ) ) < 0 )
173 outputFields.append(
QgsField( QStringLiteral(
"layer" ), QVariant::String, QString() ) );
174 addLayerField =
true;
176 bool addPathField =
false;
177 if ( outputFields.lookupField( QStringLiteral(
"path" ) ) < 0 )
179 outputFields.append(
QgsField( QStringLiteral(
"path" ), QVariant::String, QString() ) );
191 double step = totalFeatureCount > 0 ? 100.0 / totalFeatureCount : 1;
204 feedback->
pushInfo( QObject::tr(
"Packaging layer %1/%2: %3" ).arg( layerNumber ).arg( layers.count() ).arg( layer->name() ) );
216 bool changed =
false;
239 for (
const QgsField &destField : outputFields )
241 if ( addLayerField && destField.name() == QLatin1String(
"layer" ) )
243 destAttributes.append( layer->name() );
246 else if ( addPathField && destField.name() == QLatin1String(
"path" ) )
248 destAttributes.append( layer->publicSource() );
252 QVariant destAttribute;
254 if ( sourceIndex >= 0 )
256 destAttribute = f.
attributes().at( sourceIndex );
258 destAttributes.append( destAttribute );
272 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
QgsCoordinateReferenceSystem crs
void setProgress(double progress)
Sets the current progress for the feedback object.
const QgsCoordinateReferenceSystem & outputCrs
Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
static QString displayString(Type type) SIP_HOLDGIL
Returns a display string type for a WKB type, e.g., the geometry name used in WKT geometry representa...
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
Base class for providing feedback from a processing algorithm.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
Container of fields for a vector layer.
static Type addZ(Type type) SIP_HOLDGIL
Adds the z dimension to a WKB type and returns the new type.
static QString geometryDisplayString(GeometryType type) SIP_HOLDGIL
Returns a display string for a geometry type.
Type
The WKB type describes the number of dimensions a geometry has.
static Type multiType(Type type) SIP_HOLDGIL
Returns the multi type for a WKB type.
long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
A parameter for processing algorithms which accepts multiple map layers.
bool isMultipart() const SIP_HOLDGIL
Returns true if WKB of the geometry is of WKBMulti* type.
A feature sink output for processing algorithms.
bool isMeasure() const SIP_HOLDGIL
Returns true if the geometry contains m values.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
This class wraps a request for features to a vector layer (or directly its vector data provider).
static Type addM(Type type) SIP_HOLDGIL
Adds the m dimension to a WKB type and returns the new type.
@ TypeVector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
A coordinate reference system parameter for processing algorithms.
Contains information about the context in which a processing algorithm is executed.
QString authid() const
Returns the authority identifier for the CRS.
static bool hasM(Type type) SIP_HOLDGIL
Tests whether a WKB type contains m values.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
This class represents a coordinate reference system (CRS).
bool is3D() const SIP_HOLDGIL
Returns true if the geometry is 3D and contains a z-value.
virtual void pushDebugInfo(const QString &info)
Pushes an informational message containing debugging helpers from the algorithm.
bool isCanceled() const
Tells whether the operation has been canceled already.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
bool nextFeature(QgsFeature &f)
A geometry is the spatial representation of a feature.
Represents a vector layer which manages a vector based data sets.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Base class for all map layer types.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
static GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
static bool hasZ(Type type) SIP_HOLDGIL
Tests whether a WKB type contains the z-dimension.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
static bool isMultiType(Type type) SIP_HOLDGIL
Returns true if the WKB type is a multi type.
Wrapper for iterator of features from vector data provider or vector layer.
Custom exception class for processing related exceptions.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
Encapsulate a field in an attribute table or data source.