24using namespace Qt::StringLiterals;
28QString QgsExtractBinaryFieldAlgorithm::name()
const
30 return u
"extractbinary"_s;
33QString QgsExtractBinaryFieldAlgorithm::displayName()
const
35 return QObject::tr(
"Extract binary field" );
38QString QgsExtractBinaryFieldAlgorithm::shortHelpString()
const
41 "This algorithm extracts contents from a binary field, saving them to individual files.\n\n"
42 "Filenames can be generated using values taken from "
43 "an attribute in the source table or based on a more complex expression."
47QString QgsExtractBinaryFieldAlgorithm::shortDescription()
const
49 return QObject::tr(
"Extracts contents from a binary field, saving them to individual files." );
52QStringList QgsExtractBinaryFieldAlgorithm::tags()
const
54 return QObject::tr(
"blob,binaries,save,file,contents,field,column" ).split(
',' );
57QString QgsExtractBinaryFieldAlgorithm::group()
const
59 return QObject::tr(
"Vector table" );
62QString QgsExtractBinaryFieldAlgorithm::groupId()
const
64 return u
"vectortable"_s;
67QgsExtractBinaryFieldAlgorithm *QgsExtractBinaryFieldAlgorithm::createInstance()
const
69 return new QgsExtractBinaryFieldAlgorithm();
72void QgsExtractBinaryFieldAlgorithm::initAlgorithm(
const QVariantMap & )
85 std::unique_ptr<QgsProcessingFeatureSource> input( parameterAsSource( parameters, u
"INPUT"_s, context ) );
89 const QString fieldName = parameterAsString( parameters, u
"FIELD"_s, context );
90 const int fieldIndex = input->fields().lookupField( fieldName );
94 const QString folder = parameterAsString( parameters, u
"FOLDER"_s, context );
95 if ( !QDir().mkpath( folder ) )
98 const QDir dir( folder );
99 const QString filenameExpressionString = parameterAsString( parameters, u
"FILENAME"_s, context );
100 QgsExpressionContext expressionContext = createExpressionContext( parameters, context, input.get() );
102 QSet<QString> fields;
103 fields.insert( fieldName );
106 QgsExpression filenameExpression( filenameExpressionString );
107 filenameExpression.prepare( &expressionContext );
108 fields.unite( filenameExpression.referencedColumns() );
110 if ( !filenameExpression.needsGeometry() )
114 const double step = input->featureCount() > 0 ? 100.0 / input->featureCount() : 1;
127 const QByteArray ba = feat.
attribute( fieldIndex ).toByteArray();
132 const QString name = filenameExpression.evaluate( &expressionContext ).toString();
133 if ( filenameExpression.hasEvalError() )
135 feedback->
reportError( QObject::tr(
"Error evaluating filename: %1" ).arg( filenameExpression.evalErrorString() ) );
139 const QString path = dir.filePath( name );
141 if ( !file.open( QIODevice::WriteOnly | QFile::Truncate ) )
143 feedback->
reportError( QObject::tr(
"Could not open %1 for writing" ).arg( path ) );
149 feedback->
pushInfo( QObject::tr(
"Extracted %1" ).arg( path ) );
154 outputs.insert( u
"FOLDER"_s, folder );
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Handles parsing and evaluation of expressions (formerly called "search strings").
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
Wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(Qgis::FeatureRequestFlags flags)
Sets flags that affect how features will be fetched.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
Contains information about the context in which a processing algorithm is executed.
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.
An expression parameter for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
A vector layer or feature source field parameter for processing algorithms.
A folder destination parameter, for specifying the destination path for a folder created by the algor...