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) pathPump = prjpath + '/layers/hydrology/' + groups 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?