I want to edit the code I have below to save vector files as vectors and also save vector files as KMZs.

The code I have does a mass save to my temporary folder but only for rasters.

myDir = r'C:\temp'
layers = layers = iface.mapCanvas().layers()
pipe = QgsRasterPipe()
for layer in layers:
   extent = layer.extent()
   width, height = layer.width(), layer.height()
   renderer = layer.renderer()
   crs = layer.crs().toWkt() 
   file_writer = QgsRasterFileWriter("%s\\%s.tif" %(myDir, layer.name() ))
   print "%s\\%s.tif" %(myDir, layer.name() )
  • I'm not sure if QGIS supports writing .kmz files (which are zipped .kml files). But you can certainly save your vector layers to .kmz files. – Joseph Jun 16 '17 at 12:32
  • What i've been doing is just right-clicking and save-as to KML file. I wondered if there was a faster way to do it without merging the vector layers. Sometimes I have upwards of 50 layers to save. – Shub Jun 16 '17 at 12:37
  • So you just want to convert all loaded layers into .kml files? – Joseph Jun 16 '17 at 12:41
  • Yes. And also I want to save the vectors as vectors so I don't need to do it one at a time. I figured I could edit the "pipe" variable to work with vectors but I couldn't get it to work. – Shub Jun 16 '17 at 13:01
  • Your code only affects rasters, most of it will either not work or is not necessary for vector layers. There is the Batch Save Layers plugin which allows you to save all loaded vector layers into KML files. Or you could check this post: Bulk file convertor QGIS plugin/program – Joseph Jun 16 '17 at 13:06

Your Answer

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

Browse other questions tagged or ask your own question.