1

This question already has an answer here:

I have a list of shapefiles stored in a group: pump

I want to save all shapefiles as a new shapefile with a new CRS.

For that, I wrote the following script:

import os as os
from qgis.core import *
import processing


root = QgsProject.instance().layerTreeRoot()
prjpath =QgsProject.instance().readPath('')

groups = ['pump']
groupPump = root.findGroup(groups[0])
pathPump = prjpath + '/layers/hydrology/' + groups[0]


crs = QgsCoordinateReferenceSystem(3857, QgsCoordinateReferenceSystem.EpsgCrsId)

def saveGroup(group, crs, savePath): 
    group = group 
    for layerId in group.findLayerIds():
        layer = QgsMapLayerRegistry.instance().mapLayer(layerId)
        layerName = QgsMapLayerRegistry.instance().mapLayer(layerId).name()
        path = savePath + '/'+layer.name() + '_' + crs.authid()[-4:] +'_' +'.shp'
        print path 
        QgsVectorFileWriter.writeAsVectorFormat(layer, path, "utf-8",crs, "ESRI Shapefile")
        path)

saveGroup(groupPump, crs, pathPump)

No error, nothing happens...What did I do wrong?

marked as duplicate by Joseph, BERA, aldo_tapia, whyzar, MaryBeth Dec 12 '17 at 18:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.