Using QGIS 3.6.3, I have a layer with ten polygons. I want to use split vector layer to split the file into ten shapefiles, But the result output file is a Geopackage.

How can I get ten shapefiles by using split vector layer?

enter image description here

enter image description here

enter image description here

1 Answer 1


If you look at the Split vector layer tool script, you will see that .gpkg is hard-coded inside the script. This means there is no way to change the output format of the file directly from the GUI of script tool.

However, if you want the output to be shapefile not Geopakage, you need to change that inside the script. The script is called VectorSplit which is located - inside my machine - in the following path:


When you open the script in the text editor like Notepad++ look at the last defined function which is the following:

def processAlgorithm(self, parameters, context, feedback):
    source = self.parameterAsSource(parameters, self.INPUT, context)
    if source is None:
        raise QgsProcessingException(self.invalidSourceError(parameters, self.INPUT))

    fieldName = self.parameterAsString(parameters, self.FIELD, context)
    directory = self.parameterAsString(parameters, self.OUTPUT, context)


    fieldIndex = source.fields().lookupField(fieldName)
    uniqueValues = source.uniqueValues(fieldIndex)
    baseName = os.path.join(directory, '{0}'.format(fieldName))

    fields = source.fields()
    crs = source.sourceCrs()
    geomType = source.wkbType()

    total = 100.0 / len(uniqueValues) if uniqueValues else 1
    output_layers = []

    for current, i in enumerate(uniqueValues):
        if feedback.isCanceled():
        fName = '{0}_{1}.gpkg'.format(baseName, str(i).strip()) # Change gpkg to shp for shapefile
        feedback.pushInfo(self.tr('Creating layer: {}').format(fName))

        sink, dest = QgsProcessingUtils.createFeatureSink(fName, context, fields, geomType, crs)

        filter = '{} = {}'.format(QgsExpression.quotedColumnRef(fieldName), QgsExpression.quotedValue(i))
        req = QgsFeatureRequest().setFilterExpression(filter)

        count = 0
        for f in source.getFeatures(req):
            if feedback.isCanceled():
            sink.addFeature(f, QgsFeatureSink.FastInsert)
            count += 1
        feedback.pushInfo(self.tr('Added {} features to layer').format(count))
        del sink

        feedback.setProgress(int(current * total))

    return {self.OUTPUT: directory, self.OUTPUT_LAYERS: output_layers}

Change extension in the following line

fName = '{0}_{1}.gpkg'.format(baseName, str(i).strip())


fName = '{0}_{1}.shp'.format(baseName, str(i).strip())

Then save the script.

Finally, close QGIS and open it again and run Split vector layer tool. The output should be shapefiles not geopakage.

As a good practice, make a backup of the script tool before doing the above process.

enter image description here

  • 1
    It works,thanks very much. May 29, 2019 at 6:19
  • You are welcome. Glad it worked :)
    – ahmadhanb
    May 29, 2019 at 6:30
  • 1
    looks fantastic! smart approach
    – Taras
    May 29, 2019 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.