Skip to main content
added 54 characters in body
Source Link
Taras
  • 34.1k
  • 4
  • 73
  • 148
from qgis.core import *

suffix = "_foo"
pathToFile = "/path/to/wherever/"

layers = iface.legendInterface().layers()
for layer in layers:
    newName = layer.name() + suffix + ".shp"
    ret = QgsVectorFileWriter.writeAsVectorFormat(layer, pathToFile + newName, "utf-8", None, "ESRI Shapefile")
    if ret == QgsVectorFileWriter.NoError:
        print newName + " saved to " + pathToFile + "!"
from qgis.core import *

suffix = "_foo"
pathToFile = "/path/to/wherever/"

layers = iface.legendInterface().layers()

for layer in layers:
    newName = layer.name() + suffix + ".shp"
    ret = QgsVectorFileWriter.writeAsVectorFormat(layer, pathToFile + newName, "utf-8", None, "ESRI Shapefile")
    if ret == QgsVectorFileWriter.NoError:
        print newName + " saved to " + pathToFile + "!"

For Raster Layer use the QgsRasterFileWriterQgsRasterFileWriter

P.S.: You You can find a more detailed example in the CookbookPyQGIS Developer Cookbook.

from qgis.core import *

suffix = "_foo"
pathToFile = "/path/to/wherever/"

layers = iface.legendInterface().layers()
for layer in layers:
    newName = layer.name() + suffix + ".shp"
    ret = QgsVectorFileWriter.writeAsVectorFormat(layer, pathToFile + newName, "utf-8", None, "ESRI Shapefile")
    if ret == QgsVectorFileWriter.NoError:
        print newName + " saved to " + pathToFile + "!"

For Raster Layer use QgsRasterFileWriter

: You can find a more detailed example in the Cookbook.

from qgis.core import *

suffix = "_foo"
pathToFile = "/path/to/wherever/"

layers = iface.legendInterface().layers()

for layer in layers:
    newName = layer.name() + suffix + ".shp"
    ret = QgsVectorFileWriter.writeAsVectorFormat(layer, pathToFile + newName, "utf-8", None, "ESRI Shapefile")
    if ret == QgsVectorFileWriter.NoError:
        print newName + " saved to " + pathToFile + "!"

For Raster Layer use the QgsRasterFileWriter

P.S.: You can find a more detailed example in the PyQGIS Developer Cookbook.

Post Merged (destination) from gis.stackexchange.com/questions/137326/…
added 149 characters in body
Source Link
ymirsson
  • 884
  • 6
  • 9
from qgis.core import *

suffix = "_foo"
pathToFile = "/path/to/wherever/"

layers = iface.legendInterface().layers()
for layer in layers:
    newName = layer.name() + suffix + ".shp"
    ret = QgsVectorFileWriter.writeAsVectorFormat(layer, pathToFile + newName, "utf-8", None, "ESRI Shapefile")
    if ret == QgsVectorFileWriter.NoError:
        print newName + " saved to " + pathToFile + "!"

For Raster Layer use QgsRasterFileWriter

€: You can find a more detailed example in the Cookbook.

from qgis.core import *

suffix = "_foo"
pathToFile = "/path/to/wherever/"

layers = iface.legendInterface().layers()
for layer in layers:
    newName = layer.name() + suffix + ".shp"
    ret = QgsVectorFileWriter.writeAsVectorFormat(layer, pathToFile + newName, "utf-8", None, "ESRI Shapefile")
    if ret == QgsVectorFileWriter.NoError:
        print newName + " saved to " + pathToFile + "!"

For Raster Layer use QgsRasterFileWriter

from qgis.core import *

suffix = "_foo"
pathToFile = "/path/to/wherever/"

layers = iface.legendInterface().layers()
for layer in layers:
    newName = layer.name() + suffix + ".shp"
    ret = QgsVectorFileWriter.writeAsVectorFormat(layer, pathToFile + newName, "utf-8", None, "ESRI Shapefile")
    if ret == QgsVectorFileWriter.NoError:
        print newName + " saved to " + pathToFile + "!"

For Raster Layer use QgsRasterFileWriter

€: You can find a more detailed example in the Cookbook.

Source Link
ymirsson
  • 884
  • 6
  • 9

from qgis.core import *

suffix = "_foo"
pathToFile = "/path/to/wherever/"

layers = iface.legendInterface().layers()
for layer in layers:
    newName = layer.name() + suffix + ".shp"
    ret = QgsVectorFileWriter.writeAsVectorFormat(layer, pathToFile + newName, "utf-8", None, "ESRI Shapefile")
    if ret == QgsVectorFileWriter.NoError:
        print newName + " saved to " + pathToFile + "!"

For Raster Layer use QgsRasterFileWriter