24using namespace Qt::StringLiterals;
28QString QgsExportLayersInformationAlgorithm::name()
const
30 return u
"exportlayersinformation"_s;
33QString QgsExportLayersInformationAlgorithm::displayName()
const
35 return QObject::tr(
"Export layer(s) information" );
38QStringList QgsExportLayersInformationAlgorithm::tags()
const
40 return QObject::tr(
"metadata,details,extent" ).split(
',' );
43QString QgsExportLayersInformationAlgorithm::group()
const
45 return QObject::tr(
"Layer tools" );
48QString QgsExportLayersInformationAlgorithm::groupId()
const
50 return u
"layertools"_s;
53void QgsExportLayersInformationAlgorithm::initAlgorithm(
const QVariantMap & )
59QString QgsExportLayersInformationAlgorithm::shortHelpString()
const
61 return QObject::tr(
"This algorithm creates a polygon layer with features corresponding to the extent of selected layer(s).\n\n"
62 "Additional layer details - CRS, provider name, file path, layer name, subset filter, abstract and attribution - are attached as attributes to each feature." );
65QString QgsExportLayersInformationAlgorithm::shortDescription()
const
67 return QObject::tr(
"Creates a polygon layer with features corresponding to the extent of selected layer(s)." );
70QgsExportLayersInformationAlgorithm *QgsExportLayersInformationAlgorithm::createInstance()
const
72 return new QgsExportLayersInformationAlgorithm();
77 const QList<QgsMapLayer *> layers = parameterAsLayerList( parameters, u
"LAYERS"_s, context );
80 if ( !mCrs.isValid() )
84 else if ( mCrs.authid() !=
"EPSG:4326"_L1 )
86 if ( mCrs != layer->crs() )
92 mLayers.emplace_back( layer->clone() );
95 if ( !mCrs.isValid() )
98 if ( mLayers.empty() )
99 feedback->
reportError( QObject::tr(
"No layers selected" ),
false );
107 outFields.
append(
QgsField( u
"name"_s, QMetaType::Type::QString ) );
108 outFields.
append(
QgsField( u
"source"_s, QMetaType::Type::QString ) );
109 outFields.
append(
QgsField( u
"crs"_s, QMetaType::Type::QString ) );
110 outFields.
append(
QgsField( u
"provider"_s, QMetaType::Type::QString ) );
111 outFields.
append(
QgsField( u
"file_path"_s, QMetaType::Type::QString ) );
112 outFields.
append(
QgsField( u
"layer_name"_s, QMetaType::Type::QString ) );
113 outFields.
append(
QgsField( u
"subset"_s, QMetaType::Type::QString ) );
114 outFields.
append(
QgsField( u
"abstract"_s, QMetaType::Type::QString ) );
115 outFields.
append(
QgsField( u
"attribution"_s, QMetaType::Type::QString ) );
118 std::unique_ptr<QgsFeatureSink> outputSink( parameterAsSink( parameters, u
"OUTPUT"_s, context, outputDest, outFields,
Qgis::WkbType::Polygon, mCrs ) );
120 const QList<QgsMapLayer *> layers = parameterAsLayerList( parameters, u
"LAYERS"_s, context );
122 const double step = layers.size() > 0 ? 100.0 / layers.size() : 1;
124 for (
const std::unique_ptr<QgsMapLayer> &layer : mLayers )
137 attributes << layer->name()
139 << layer->crs().authid();
140 if ( layer->dataProvider() )
143 attributes << layer->dataProvider()->name()
145 << parts[u
"layerName"_s]
146 << parts[u
"subset"_s];
150 attributes << QVariant() << QVariant() << QVariant() << QVariant();
152 attributes << layer->metadata().rights().join(
';' )
153 << layer->serverProperties()->abstract();
159 if ( layer->crs() != mCrs )
162 transform.setBallparkTransformsAreAppropriate(
true );
165 rect = transform.transformBoundingBox( rect );
171 feedback->
pushInfo( QObject::tr(
"Extent of layer %1 could not be reprojected" ).arg( layer->name() ) );
180 outputSink->finalize();
183 outputs.insert( u
"OUTPUT"_s, outputDest );
@ MapLayer
Any map layer type (raster, vector, mesh, point cloud, annotation or plugin layer).
@ VectorPolygon
Vector polygon layers.
Represents a coordinate reference system (CRS).
Custom exception class for Coordinate Reference System related exceptions.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
Base class for all map layer types.
Contains information about the context in which a processing algorithm is executed.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
A feature sink output for processing algorithms.
A parameter for processing algorithms which accepts multiple map layers.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
A rectangle specified with double values.