27 void QgsBookmarksToLayerAlgorithm::initAlgorithm(
const QVariantMap & )
29 std::unique_ptr< QgsProcessingParameterEnum > sourceParam = qgis::make_unique<QgsProcessingParameterEnum >( QStringLiteral(
"SOURCE" ), QObject::tr(
"Bookmark source" ), QStringList() <<
30 QObject::tr(
"Project bookmarks" ) << QObject::tr(
"User bookmarks" ),
true, QVariantList() << 0 << 1 );
31 QVariantMap wrapperMetadata;
32 wrapperMetadata.insert( QStringLiteral(
"useCheckBoxes" ),
true );
34 metadata.insert( QStringLiteral(
"widget_wrapper" ), wrapperMetadata );
35 sourceParam->setMetadata( metadata );
36 addParameter( sourceParam.release() );
41 QString QgsBookmarksToLayerAlgorithm::name()
const 43 return QStringLiteral(
"bookmarkstolayer" );
46 QString QgsBookmarksToLayerAlgorithm::displayName()
const 48 return QObject::tr(
"Convert spatial bookmarks to layer" );
51 QStringList QgsBookmarksToLayerAlgorithm::tags()
const 53 return QObject::tr(
"save,extract" ).split(
',' );
56 QString QgsBookmarksToLayerAlgorithm::group()
const 58 return QObject::tr(
"Vector general" );
61 QString QgsBookmarksToLayerAlgorithm::groupId()
const 63 return QStringLiteral(
"vectorgeneral" );
66 QString QgsBookmarksToLayerAlgorithm::shortHelpString()
const 68 return QObject::tr(
"This algorithm creates a new layer containing polygon features for stored spatial bookmarks.\n\n" 69 "The export can be filtered to only bookmarks belonging to the current project, to all user bookmarks, or a combination of both." );
72 QString QgsBookmarksToLayerAlgorithm::shortDescription()
const 74 return QObject::tr(
"Converts stored spatial bookmarks to a polygon layer." );
77 QIcon QgsBookmarksToLayerAlgorithm::icon()
const 82 QString QgsBookmarksToLayerAlgorithm::svgIconPath()
const 87 QgsBookmarksToLayerAlgorithm *QgsBookmarksToLayerAlgorithm::createInstance()
const 89 return new QgsBookmarksToLayerAlgorithm();
94 QList< int > sources = parameterAsEnums( parameters, QStringLiteral(
"SOURCE" ), context );
95 if ( sources.contains( 0 ) )
97 if ( sources.contains( 1 ) )
107 fields.
append(
QgsField( QStringLiteral(
"name" ), QVariant::String ) );
108 fields.
append(
QgsField( QStringLiteral(
"group" ), QVariant::String ) );
110 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, fields,
QgsWkbTypes::Polygon, crs ) );
114 int count = mBookmarks.count();
116 double step = count > 0 ? 100.0 / count : 1;
118 for (
const QgsBookmark &b : qgis::as_const( mBookmarks ) )
129 if ( b.extent().crs() !=
crs )
139 feedback->
reportError( QObject::tr(
"Could not reproject bookmark %1 to destination CRS" ).arg( b.name() ) );
153 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
162 void QgsLayerToBookmarksAlgorithm::initAlgorithm(
const QVariantMap & )
166 std::unique_ptr< QgsProcessingParameterEnum > sourceParam = qgis::make_unique<QgsProcessingParameterEnum >( QStringLiteral(
"DESTINATION" ), QObject::tr(
"Bookmark destination" ), QStringList() <<
167 QObject::tr(
"Project bookmarks" ) << QObject::tr(
"User bookmarks" ),
false, 0 );
168 addParameter( sourceParam.release() );
170 addParameter(
new QgsProcessingParameterExpression( QStringLiteral(
"NAME_EXPRESSION" ), QObject::tr(
"Name field" ), QVariant(), QStringLiteral(
"INPUT" ) ) );
171 addParameter(
new QgsProcessingParameterExpression( QStringLiteral(
"GROUP_EXPRESSION" ), QObject::tr(
"Group field" ), QVariant(), QStringLiteral(
"INPUT" ),
true ) );
176 QString QgsLayerToBookmarksAlgorithm::name()
const 178 return QStringLiteral(
"layertobookmarks" );
181 QString QgsLayerToBookmarksAlgorithm::displayName()
const 183 return QObject::tr(
"Convert layer to spatial bookmarks" );
186 QStringList QgsLayerToBookmarksAlgorithm::tags()
const 188 return QObject::tr(
"save,extract,store" ).split(
',' );
191 QString QgsLayerToBookmarksAlgorithm::group()
const 193 return QObject::tr(
"Vector general" );
196 QString QgsLayerToBookmarksAlgorithm::groupId()
const 198 return QStringLiteral(
"vectorgeneral" );
201 QString QgsLayerToBookmarksAlgorithm::shortHelpString()
const 203 return QObject::tr(
"This algorithm creates spatial bookmarks corresponding to the extent of features contained in a layer." );
206 QString QgsLayerToBookmarksAlgorithm::shortDescription()
const 208 return QObject::tr(
"Converts feature extents to stored spatial bookmarks." );
211 QIcon QgsLayerToBookmarksAlgorithm::icon()
const 216 QString QgsLayerToBookmarksAlgorithm::svgIconPath()
const 221 QgsLayerToBookmarksAlgorithm *QgsLayerToBookmarksAlgorithm::createInstance()
const 223 return new QgsLayerToBookmarksAlgorithm();
228 mDest = parameterAsEnum( parameters, QStringLiteral(
"DESTINATION" ), context );
229 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
234 QString nameExpressionString = parameterAsExpression( parameters, QStringLiteral(
"NAME_EXPRESSION" ), context );
235 QString groupExpressionString = parameterAsExpression( parameters, QStringLiteral(
"GROUP_EXPRESSION" ), context );
238 expressionContext.
appendScope( source->createExpressionContextScope() );
241 if ( !nameExpression.
prepare( &expressionContext ) )
246 std::unique_ptr< QgsExpression > groupExpression;
247 if ( !groupExpressionString.isEmpty() )
249 groupExpression = qgis::make_unique< QgsExpression >( groupExpressionString );
250 if ( !groupExpression->prepare( &expressionContext ) )
251 throw QgsProcessingException( QObject::tr(
"Invalid group expression: %1" ).arg( groupExpression->parserErrorString() ) );
252 requiredColumns.unite( groupExpression->referencedColumns() );
258 double step = source->featureCount() > 0 ? 100.0 / source->featureCount() : 1;
273 const QString name = nameExpression.
evaluate( &expressionContext ).toString();
282 if ( groupExpression )
284 group = groupExpression->evaluate( &expressionContext ).toString();
285 if ( !groupExpression->evalErrorString().isEmpty() )
287 feedback->
reportError( QObject::tr(
"Error evaluating group expression: %1" ).arg( groupExpression->evalErrorString() ) );
304 return QVariantMap();
321 for (
const QgsBookmark &b : qgis::as_const( mBookmarks ) )
325 res.insert( QStringLiteral(
"COUNT" ), mBookmarks.size() );
Class for parsing and evaluation of expressions (formerly called "search strings").
Wrapper for iterator of features from vector data provider or vector layer.
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.
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
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.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
An expression parameter for processing algorithms.
void setProgress(double progress)
Sets the current progress for the feedback object.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
QVariant evaluate()
Evaluate the feature and return the result.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QString evalErrorString() const
Returns evaluation error.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
A numeric output for processing algorithms.
Manages storage of a set of bookmarks.
void setName(const QString &name)
Sets the bookmark's name, which is a user-visible string identifying the bookmark.
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
const QgsCoordinateReferenceSystem & crs
bool hasGeometry() const
Returns true if the feature has an associated geometry.
QString parserErrorString() const
Returns parser error.
A feature sink output for processing algorithms.
const QgsBookmarkManager * bookmarkManager() const
Returns the project's bookmark manager, which manages bookmarks within the project.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
void setGroup(const QString &group)
Sets the bookmark's group, which is a user-visible string identifying the bookmark's category...
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Returns a copy of the geometry which has been densified by adding the specified number of extra nodes...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QString addBookmark(const QgsBookmark &bookmark, bool *ok=nullptr)
Adds a bookmark to the manager.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
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) ...
A QgsRectangle with associated coordinate reference system.
Encapsulate a field in an attribute table or data source.
QList< QgsBookmark > bookmarks() const
Returns a list of all bookmarks contained in the manager.
A coordinate reference system parameter for processing algorithms.
QgsExpressionContext & expressionContext()
Returns the expression context.
bool isCanceled() const
Tells whether the operation has been canceled already.
An input feature source (such as vector layers) parameter for processing algorithms.
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
This class represents a coordinate reference system (CRS).
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
static QgsBookmarkManager * bookmarkManager()
Returns the application's bookmark manager, used for storing installation-wide bookmarks.
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.
bool nextFeature(QgsFeature &f)
Contains information about the context in which a processing algorithm is executed.
Represents a spatial bookmark, with a name, CRS and extent.
void setExtent(const QgsReferencedRectangle &extent)
Sets the bookmark's spatial extent.