23 QString QgsExportLayersInformationAlgorithm::name()
const
25 return QStringLiteral(
"exportlayersinformation" );
28 QString QgsExportLayersInformationAlgorithm::displayName()
const
30 return QObject::tr(
"Export layer(s) information" );
33 QStringList QgsExportLayersInformationAlgorithm::tags()
const
35 return QObject::tr(
"metadata,details,extent" ).split(
',' );
38 QString QgsExportLayersInformationAlgorithm::group()
const
40 return QObject::tr(
"Layer tools" );
43 QString QgsExportLayersInformationAlgorithm::groupId()
const
45 return QStringLiteral(
"layertools" );
48 void QgsExportLayersInformationAlgorithm::initAlgorithm(
const QVariantMap & )
54 QString QgsExportLayersInformationAlgorithm::shortHelpString()
const
56 return QObject::tr(
"Creates a polygon layer with features corresponding to the extent of selected layer(s).\n\n"
57 "Additional layer details - CRS, provider name, file path, layer name, subset filter, abstract and attribution - are attached as attributes to each feature." );
60 QgsExportLayersInformationAlgorithm *QgsExportLayersInformationAlgorithm::createInstance()
const
62 return new QgsExportLayersInformationAlgorithm();
67 const QList< QgsMapLayer * > layers = parameterAsLayerList( parameters, QStringLiteral(
"LAYERS" ), context );
70 if ( !mCrs.isValid() )
74 else if ( mCrs.authid() != QLatin1String(
"EPSG:4326" ) )
76 if ( mCrs != layer->crs() )
82 mLayers.emplace_back( layer->clone() );
85 if ( !mCrs.isValid() )
88 if ( mLayers.empty() )
89 feedback->
reportError( QObject::tr(
"No layers selected" ),
false );
97 outFields.
append(
QgsField( QStringLiteral(
"name" ), QVariant::String ) );
98 outFields.
append(
QgsField( QStringLiteral(
"source" ), QVariant::String ) );
99 outFields.
append(
QgsField( QStringLiteral(
"crs" ), QVariant::String ) );
100 outFields.
append(
QgsField( QStringLiteral(
"provider" ), QVariant::String ) );
101 outFields.
append(
QgsField( QStringLiteral(
"file_path" ), QVariant::String ) );
102 outFields.
append(
QgsField( QStringLiteral(
"layer_name" ), QVariant::String ) );
103 outFields.
append(
QgsField( QStringLiteral(
"subset" ), QVariant::String ) );
104 outFields.
append(
QgsField( QStringLiteral(
"abstract" ), QVariant::String ) );
105 outFields.
append(
QgsField( QStringLiteral(
"attribution" ), QVariant::String ) );
108 std::unique_ptr< QgsFeatureSink > outputSink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, outputDest, outFields,
111 const QList< QgsMapLayer * > layers = parameterAsLayerList( parameters, QStringLiteral(
"LAYERS" ), context );
113 const double step = layers.size() > 0 ? 100.0 / layers.size() : 1;
115 for (
const std::unique_ptr< QgsMapLayer > &layer : mLayers )
128 attributes << layer->name()
130 << layer->crs().authid();
131 if ( layer->dataProvider() )
134 attributes << layer->dataProvider()->name()
135 << parts[ QStringLiteral(
"path" ) ]
136 << parts[ QStringLiteral(
"layerName" ) ]
137 << parts[ QStringLiteral(
"subset" ) ];
141 attributes << QVariant() << QVariant() << QVariant() << QVariant();
143 attributes << layer->metadata().rights().join(
';' )
144 << layer->abstract();
150 if ( layer->crs() != mCrs )
153 transform.setBallparkTransformsAreAppropriate(
true );
156 rect = transform.transformBoundingBox( rect );
162 feedback->
pushInfo( QObject::tr(
"Extent of layer %1 could not be reprojected" ).arg( layer->name() ) );
168 throw QgsProcessingException( writeFeatureError( outputSink.get(), parameters, QStringLiteral(
"OUTPUT" ) ) );
172 outputs.insert( QStringLiteral(
"OUTPUT" ), outputDest );