1

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()
   provider=layer.dataProvider()
   crs = layer.crs().toWkt() 
   pipe.set(provider.clone())
   pipe.set(renderer.clone())
   file_writer = QgsRasterFileWriter("%s\\%s.tif" %(myDir, layer.name() ))
   file_writer.writeRaster(pipe,
                       width,
                       height,
                       extent,
                       layer.crs())
   print "%s\\%s.tif" %(myDir, layer.name() )
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Shub
  • 932
  • 7
  • 26
  • 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
  • Yes, I am trying to edit the code I currently have to work with vectors instead of rasters. That should be useful, thank you. – Shub Jun 16 '17 at 13:11
  • In the post I linked to in my comment is some code I posted which saves all loaded layers in QGIS into .kml files. Perhaps you can test it :) – Joseph Jun 16 '17 at 13:13

0 Answers0