27 QString QgsLayoutMapExtentToLayerAlgorithm::name()
const 29 return QStringLiteral(
"printlayoutmapextenttolayer" );
32 QString QgsLayoutMapExtentToLayerAlgorithm::displayName()
const 34 return QObject::tr(
"Print layout map extent to layer" );
37 QStringList QgsLayoutMapExtentToLayerAlgorithm::tags()
const 39 return QObject::tr(
"layout,composer,composition,visible" ).split(
',' );
42 QString QgsLayoutMapExtentToLayerAlgorithm::group()
const 44 return QObject::tr(
"Cartography" );
47 QString QgsLayoutMapExtentToLayerAlgorithm::groupId()
const 49 return QStringLiteral(
"cartography" );
52 QString QgsLayoutMapExtentToLayerAlgorithm::shortDescription()
const 54 return QObject::tr(
"Creates a polygon layer containing the extent of a print layout map item." );
57 void QgsLayoutMapExtentToLayerAlgorithm::initAlgorithm(
const QVariantMap & )
61 auto crsParam = qgis::make_unique< QgsProcessingParameterCrs >( QStringLiteral(
"CRS" ), QObject::tr(
"Override CRS" ), QVariant(), true );
63 addParameter( crsParam.release() );
71 QString QgsLayoutMapExtentToLayerAlgorithm::shortHelpString()
const 73 return QObject::tr(
"This algorithm creates a polygon layer containing the extent of a print layout map item (or items), " 74 "with attributes specifying the map size (in layout units), scale and rotatation.\n\n" 75 "If the map item parameter is specified, then only the matching map extent will be exported. If it " 76 "is not specified, all map extents from the layout will be exported.\n\n" 77 "Optionally, a specific output CRS can be specified. If it is not specified, the original map " 78 "item CRS will be used." );
81 QgsLayoutMapExtentToLayerAlgorithm *QgsLayoutMapExtentToLayerAlgorithm::createInstance()
const 83 return new QgsLayoutMapExtentToLayerAlgorithm();
89 QgsPrintLayout *layout = parameterAsLayout( parameters, QStringLiteral(
"LAYOUT" ), context );
91 throw QgsProcessingException( QObject::tr(
"Cannot find layout with name \"%1\"" ).arg( parameters.value( QStringLiteral(
"LAYOUT" ) ).toString() ) );
94 if ( !map && parameters.value( QStringLiteral(
"MAP" ) ).isValid() )
95 throw QgsProcessingException( QObject::tr(
"Cannot find matching map item with ID %1" ).arg( parameters.value( QStringLiteral(
"MAP" ) ).toString() ) );
97 QList< QgsLayoutItemMap *> maps;
105 mFeatures.reserve( maps.size() );
108 if ( !mCrs.isValid() )
109 mCrs = !overrideCrs.
isValid() ? map->crs() : overrideCrs;
112 if ( map->crs() != mCrs )
120 feedback->
reportError( QObject::tr(
"Error reprojecting map to destination CRS" ) );
125 mWidth = map->rect().width();
126 mHeight = map->rect().height();
127 mScale = map->scale();
128 mRotation = map->mapRotation();
142 fields.
append(
QgsField( QStringLiteral(
"map" ), QVariant::String ) );
143 fields.
append(
QgsField( QStringLiteral(
"width" ), QVariant::Double ) );
144 fields.
append(
QgsField( QStringLiteral(
"height" ), QVariant::Double ) );
145 fields.
append(
QgsField( QStringLiteral(
"scale" ), QVariant::Double ) );
146 fields.
append(
QgsField( QStringLiteral(
"rotation" ), QVariant::Double ) );
149 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, fields,
QgsWkbTypes::Polygon, mCrs ) );
159 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
161 outputs.insert( QStringLiteral(
"WIDTH" ), mFeatures.size() == 1 ? mWidth : QVariant() );
162 outputs.insert( QStringLiteral(
"HEIGHT" ), mFeatures.size() == 1 ? mHeight : QVariant() );
163 outputs.insert( QStringLiteral(
"SCALE" ), mFeatures.size() == 1 ? mScale : QVariant() );
164 outputs.insert( QStringLiteral(
"ROTATION" ), mFeatures.size() == 1 ? mRotation : QVariant() );
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
Base class for providing feedback from a processing algorithm.
Parameter is an advanced parameter which should be hidden from users by default.
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
A print layout parameter, allowing users to select a print layout.
void setProgress(double progress)
Sets the current progress for the feedback object.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
A numeric output for processing algorithms.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
A feature sink output for processing algorithms.
void layoutItems(QList< T *> &itemList) const
Returns a list of layout items of a specific type.
Layout graphical items for displaying a map.
Custom exception class for processing related exceptions.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false) ...
Encapsulate a field in an attribute table or data source.
A print layout item parameter, allowing users to select a particular item from a print layout...
This class represents a coordinate reference system (CRS).
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
Custom exception class for Coordinate Reference System related exceptions.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Contains information about the context in which a processing algorithm is executed.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.