Saturday 23 March 2019

pyqgis - Exporting several files at same time in QGIS?


I have a lot of .TAB files open in QGIS and I want to save them to .SHP so I can work with them in ArcMap.



Is there a way to save/export all these files at the same time or do I really have to "save as" separately for every single file?



Answer



Try this Frida:




  1. Create a folder to store your Shapefiles there (e.g., I've created the folder /tmp/data/, I use GNU/Linux).




  2. In QGIS, open the QGIS Python console.





  3. Write the following line, editing the right hand side to match the full path to your folder (make sure you include the trailing slash/backslash):


    myDir = '/tmp/data/'




  4. Press Enter.




  5. Copy the following lines to the QGIS Python console:


    for vLayer in iface.mapCanvas().layers():

    QgsVectorFileWriter.writeAsVectorFormat( vLayer,
    myDir + vLayer.name() + ".shp", "utf-8",
    vLayer.crs(), "ESRI Shapefile" )


  6. Press Enter a couple of times.




You should now have your Shapefiles inside the folder you created in step 1.


If you face troubles, let me know your OS and the full path to your folder.



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...