26 QString QgsPackageAlgorithm::name()
const 28 return QStringLiteral(
"package" );
31 QString QgsPackageAlgorithm::displayName()
const 33 return QObject::tr(
"Package layers" );
36 QStringList QgsPackageAlgorithm::tags()
const 38 return QObject::tr(
"geopackage,collect,merge,combine" ).split(
',' );
41 QString QgsPackageAlgorithm::group()
const 43 return QObject::tr(
"Database" );
46 QString QgsPackageAlgorithm::groupId()
const 48 return QStringLiteral(
"database" );
51 void QgsPackageAlgorithm::initAlgorithm(
const QVariantMap & )
59 QString QgsPackageAlgorithm::shortHelpString()
const 61 return QObject::tr(
"This algorithm collects a number of existing layers and packages them together into a single GeoPackage database." );
64 QgsPackageAlgorithm *QgsPackageAlgorithm::createInstance()
const 66 return new QgsPackageAlgorithm();
71 bool overwrite = parameterAsBool( parameters, QStringLiteral(
"OVERWRITE" ), context );
72 QString packagePath = parameterAsString( parameters, QStringLiteral(
"OUTPUT" ), context );
73 if ( packagePath.isEmpty() )
77 if ( overwrite && QFile::exists( packagePath ) )
79 feedback->
pushInfo( QObject::tr(
"Removing existing file '%1'" ).arg( packagePath ) );
80 if ( !QFile( packagePath ).
remove() )
86 OGRSFDriverH hGpkgDriver = OGRGetDriverByName(
"GPKG" );
94 throw QgsProcessingException( QObject::tr(
"Creation of database failed (OGR error: %1)" ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) );
97 const QList< QgsMapLayer * > layers = parameterAsLayerList( parameters, QStringLiteral(
"LAYERS" ), context );
101 QStringList outputLayers;
111 feedback->
pushInfo( QObject::tr(
"Packaging layer %1/%2: %3" ).arg( i ).arg( layers.count() ).arg( layer ? layer->name() : QString() ) );
116 feedback->
pushDebugInfo( QObject::tr(
"Error retrieving map layer." ) );
121 switch ( layer->type() )
125 if ( !packageVectorLayer( qobject_cast< QgsVectorLayer * >( layer ), packagePath,
126 context, &multiStepFeedback ) )
129 outputLayers.append( QStringLiteral(
"%1|layername=%2" ).arg( packagePath, layer->name() ) );
136 feedback->
pushDebugInfo( QObject::tr(
"Raster layers are not currently supported." ) );
143 feedback->
pushDebugInfo( QObject::tr(
"Packaging plugin layers is not supported." ) );
149 feedback->
pushDebugInfo( QObject::tr(
"Packaging mesh layers is not supported." ) );
159 outputs.insert( QStringLiteral(
"OUTPUT" ), packagePath );
160 outputs.insert( QStringLiteral(
"OUTPUT_LAYERS" ), outputLayers );
168 options.
driverName = QStringLiteral(
"GPKG" );
177 const int fidIndex = fields.
lookupField( QStringLiteral(
"fid" ) );
191 feedback->
pushDebugInfo( QObject::tr(
"Packaging layer failed: %1" ).arg( error ) );
A boolean parameter for processing algorithms.
bool isCanceled() const
Tells whether the operation has been canceled already.
A parameter for processing algorithms which accepts multiple map layers.
QgsVectorFileWriter::ActionOnExistingFile actionOnExistingFile
Action on existing file.
Base class for all map layer types.
Base class for providing feedback from a processing algorithm.
Processing feedback object for multi-step operations.
QgsAttributeList attributes
Attributes to export (empty means all unless skipAttributeCreation is set)
void setCurrentStep(int step)
Sets the step which is being executed.
Container of fields for a vector layer.
Options to pass to writeAsVectorFormat()
QString defaultEncoding() const
Returns the default encoding to use for newly created files.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Custom exception class for processing related exceptions.
Create or overwrite layer.
QString driverName
OGR driver to use.
static QgsVectorFileWriter::WriterError writeAsVectorFormat(QgsVectorLayer *layer, const QString &fileName, const QString &fileEncoding, const QgsCoordinateReferenceSystem &destCRS=QgsCoordinateReferenceSystem(), const QString &driverName="GPKG", bool onlySelected=false, QString *errorMessage=nullptr, const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), bool skipAttributeCreation=false, QString *newFilename=nullptr, QgsVectorFileWriter::SymbologyExport symbologyExport=QgsVectorFileWriter::NoSymbology, double symbologyScale=1.0, const QgsRectangle *filterExtent=nullptr, QgsWkbTypes::Type overrideGeometryType=QgsWkbTypes::Unknown, bool forceMulti=false, bool includeZ=false, const QgsAttributeList &attributes=QgsAttributeList(), QgsVectorFileWriter::FieldValueConverter *fieldValueConverter=nullptr, QString *newLayer=nullptr)
Write contents of vector layer to an (OGR supported) vector format.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
A generic file based destination parameter, for specifying the destination path for a file (non-map l...
virtual void pushDebugInfo(const QString &info)
Pushes an informational message containing debugging helpers from the algorithm.
A multi-layer output for processing algorithms which create map layers, when the number and nature of...
QString fileEncoding
Encoding to use.
bool skipAttributeCreation
Only write geometries.
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
QString layerName
Layer name. If let empty, it will be derived from the filename.
std::unique_ptr< std::remove_pointer< OGRDataSourceH >::type, OGRDataSourceDeleter > ogr_datasource_unique_ptr
Scoped OGR data source.
QgsFeedback * feedback
Optional feedback object allowing cancellation of layer save.
Represents a vector layer which manages a vector based data sets.
Contains information about the context in which a processing algorithm is executed.
QgsAttributeList allAttributesList() const
Utility function to get list of attribute indexes.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.