23 QString QgsSaveFeaturesAlgorithm::name()
const
25 return QStringLiteral(
"savefeatures" );
28 QString QgsSaveFeaturesAlgorithm::displayName()
const
30 return QObject::tr(
"Save vector features to file" );
33 QStringList QgsSaveFeaturesAlgorithm::tags()
const
35 return QObject::tr(
"save,write,export" ).split(
',' );
38 QString QgsSaveFeaturesAlgorithm::group()
const
40 return QObject::tr(
"Vector general" );
43 QString QgsSaveFeaturesAlgorithm::groupId()
const
45 return QStringLiteral(
"vectorgeneral" );
48 QString QgsSaveFeaturesAlgorithm::shortHelpString()
const
50 return QObject::tr(
"This algorithm saves vector features to a specified file dataset.\n\n"
51 "For dataset formats supporting layers, an optional layer name parameter can be used to specify a custom string.\n\n"
52 "Optional GDAL-defined dataset and layer options can be specified. For more information on this, "
53 "read the online GDAL documentation." );
56 QgsSaveFeaturesAlgorithm *QgsSaveFeaturesAlgorithm::createInstance()
const
58 return new QgsSaveFeaturesAlgorithm();
61 void QgsSaveFeaturesAlgorithm::initAlgorithm(
const QVariantMap & )
66 std::unique_ptr< QgsProcessingParameterString > param = qgis::make_unique< QgsProcessingParameterString >( QStringLiteral(
"LAYER_NAME" ), QObject::tr(
"Layer name" ), QVariant(),
false,
true );
68 addParameter( param.release() );
69 param = qgis::make_unique< QgsProcessingParameterString >( QStringLiteral(
"DATASOURCE_OPTIONS" ), QObject::tr(
"GDAL dataset options (separate individual options with semicolons)" ), QVariant(),
false,
true );
71 addParameter( param.release() );
72 param = qgis::make_unique< QgsProcessingParameterString >( QStringLiteral(
"LAYER_OPTIONS" ), QObject::tr(
"GDAL layer options (separate individual options with semicolons)" ), QVariant(),
false,
true );
74 addParameter( param.release() );
82 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
84 QString layerName = parameterAsString( parameters, QStringLiteral(
"LAYER_NAME" ), context ).trimmed();
85 QVariantMap createOptions;
86 if ( !layerName.isEmpty() )
88 createOptions[QStringLiteral(
"layerName" )] = layerName;
91 QStringList datasourceOptions = parameterAsString( parameters, QStringLiteral(
"DATASOURCE_OPTIONS" ), context ).trimmed().split(
';', QString::SkipEmptyParts );
92 QStringList layerOptions = parameterAsString( parameters, QStringLiteral(
"LAYER_OPTIONS" ), context ).trimmed().split(
';', QString::SkipEmptyParts );
96 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, source->fields(),
97 source->wkbType(), source->sourceCrs(), QgsFeatureSink::SinkFlags(), createOptions, datasourceOptions, layerOptions ) );
101 double step = source->featureCount() > 0 ? 100.0 / source->featureCount() : 1;
119 QString filePath = dest;
121 int separatorIndex = dest.indexOf(
'|' );
122 if ( separatorIndex > -1 )
124 QRegularExpression layerNameRx( QStringLiteral(
"\\|layername=([^\\|]*)" ) );
125 QRegularExpressionMatch match = layerNameRx.match( dest );
126 if ( match.hasMatch() )
128 layerName = match.captured( 1 );
130 filePath = dest.mid( 0, separatorIndex );
134 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
135 outputs.insert( QStringLiteral(
"FILE_PATH" ), filePath );
136 outputs.insert( QStringLiteral(
"LAYER_NAME" ), layerName );