Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] replace illegal characters with underscore when generating
output filename in Split Vector Layer algorithm (fix #53856)

Also ignore invalid geometries, as we only want to split vector layer
  • Loading branch information
alexbruy authored and nyalldawson committed Sep 22, 2023
1 parent 9fc2c3d commit a3ca16e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/analysis/processing/qgsalgorithmsplitvectorlayer.cpp
Expand Up @@ -81,7 +81,7 @@ void QgsSplitVectorLayerAlgorithm::initAlgorithm( const QVariantMap & )

QVariantMap QgsSplitVectorLayerAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
std::unique_ptr< QgsFeatureSource > source( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
if ( !source )
throw QgsProcessingException( invalidSourceError( parameters, QStringLiteral( "INPUT" ) ) );

Expand Down Expand Up @@ -139,13 +139,15 @@ QVariantMap QgsSplitVectorLayerAlgorithm::processAlgorithm( const QVariantMap &p
}
else
{
fileName = QStringLiteral( "%1%2.%3" ).arg( baseName ).arg( ( *it ).toString() ).arg( outputFormat );
QString value = ( *it ).toString();
value.replace( QRegularExpression( "<|>|\\:|\\\\|\\/|\\||\\?|\\*|\"" ), QStringLiteral( "_" ) );
fileName = QStringLiteral( "%1%2.%3" ).arg( baseName ).arg( value ).arg( outputFormat );
}
feedback->pushInfo( QObject::tr( "Creating layer: %1" ).arg( fileName ) );

sink.reset( QgsProcessingUtils::createFeatureSink( fileName, context, fields, geometryType, crs ) );
const QString expr = QgsExpression::createFieldEqualityExpression( fieldName, *it );
QgsFeatureIterator features = source->getFeatures( QgsFeatureRequest().setFilterExpression( expr ) );
QgsFeatureIterator features = source->getFeatures( QgsFeatureRequest().setFilterExpression( expr ), QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks );
count = 0;
while ( features.nextFeature( feat ) )
{
Expand Down

0 comments on commit a3ca16e

Please sign in to comment.