23 QString QgsExtractBinaryFieldAlgorithm::name()
const
25 return QStringLiteral(
"extractbinary" );
28 QString QgsExtractBinaryFieldAlgorithm::displayName()
const
30 return QObject::tr(
"Extract binary field" );
33 QString QgsExtractBinaryFieldAlgorithm::shortHelpString()
const
35 return QObject::tr(
"This algorithm extracts contents from a binary field, saving them to individual files.\n\n"
36 "Filenames can be generated using values taken from "
37 "an attribute in the source table or based on a more complex expression." );
40 QString QgsExtractBinaryFieldAlgorithm::shortDescription()
const
42 return QObject::tr(
"This algorithm extracts contents from a binary field, saving them to individual files." );
45 QStringList QgsExtractBinaryFieldAlgorithm::tags()
const
47 return QObject::tr(
"blob,binaries,save,file,contents,field,column" ).split(
',' );
50 QString QgsExtractBinaryFieldAlgorithm::group()
const
52 return QObject::tr(
"Vector table" );
55 QString QgsExtractBinaryFieldAlgorithm::groupId()
const
57 return QStringLiteral(
"vectortable" );
60 QgsExtractBinaryFieldAlgorithm *QgsExtractBinaryFieldAlgorithm::createInstance()
const
62 return new QgsExtractBinaryFieldAlgorithm();
65 void QgsExtractBinaryFieldAlgorithm::initAlgorithm(
const QVariantMap & )
80 std::unique_ptr< QgsProcessingFeatureSource > input( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
84 const QString fieldName = parameterAsString( parameters, QStringLiteral(
"FIELD" ), context );
85 const int fieldIndex = input->fields().lookupField( fieldName );
89 const QString folder = parameterAsString( parameters, QStringLiteral(
"FOLDER" ), context );
90 if ( !QFileInfo::exists( folder ) )
93 const QDir dir( folder );
94 const QString filenameExpressionString = parameterAsString( parameters, QStringLiteral(
"FILENAME" ), context );
95 QgsExpressionContext expressionContext = createExpressionContext( parameters, context, input.get() );
97 QSet< QString > fields;
98 fields.insert( fieldName );
101 QgsExpression filenameExpression( filenameExpressionString );
102 filenameExpression.prepare( &expressionContext );
103 fields.unite( filenameExpression.referencedColumns() );
105 if ( !filenameExpression.needsGeometry() )
109 const double step = input->featureCount() > 0 ? 100.0 / input->featureCount() : 1;
122 const QByteArray ba = feat.
attribute( fieldIndex ).toByteArray();
127 const QString name = filenameExpression.evaluate( &expressionContext ).toString();
128 if ( filenameExpression.hasEvalError() )
130 feedback->
reportError( QObject::tr(
"Error evaluating filename: %1" ).arg( filenameExpression.evalErrorString() ) );
134 const QString path = dir.filePath( name );
136 if ( !file.open( QIODevice::WriteOnly | QFile::Truncate ) )
138 feedback->
reportError( QObject::tr(
"Could not open %1 for writing" ).arg( path ) );
144 feedback->
pushInfo( QObject::tr(
"Extracted %1" ).arg( path ) );
149 outputs.insert( QStringLiteral(
"FOLDER" ), folder );