1

I am trying to save all the layers in Layers panel as MapInfo TAB file Then closed them all. But, Save as part doesn't work. There is no error but it doesn't save it. When I change the format to another format like "ESRI Shapefile" the code works well.

def packTables():

    from qgis.core import *
    from PyQt4.QtCore import *
    import os.path
    gda94CRS=QgsCoordinateReferenceSystem("EPSG:38356")
    for layer in iface.mapCanvas().layers():
        layerName=layer.name()
        layerCRS=layer.crs()
        layerSource=layer.source()
        destination="D:/1"  + "/"+layerName
        QgsVectorFileWriter.writeAsVectorFormat(layer, destination ,'System', gda94CRS,"Mapinfo TAB")
        QgsMapLayerRegistry.instance().removeMapLayer(layer)

packTables()
3
  • use print QgsVectorFileWriter.errorMessage() after the writeAsVectorFormat... It may have some hidden errors there
    – xlDias
    Aug 6 '18 at 20:42
  • Also, try changing your path to "C:/Users/1/Desktop/duct.tab". Unescaped backslashes can give you troubles
    – xlDias
    Aug 6 '18 at 20:44
  • I tried them all but it is not working. The fact is I tested following code and it works with any other format rather than "Mapinfo TAB" Aug 7 '18 at 2:19
1

To get this code to work the following line should change

QgsVectorFileWriter.writeAsVectorFormat(layer, destination ,'System', gda94CRS,"Mapinfo TAB")

it should change to

QgsVectorFileWriter.writeAsVectorFormat(layer, destination ,'System', gda94CRS,"Mapinfo File")
1
  • 1
    could you please explain why? the official ogr driver name is "MITAB", why is this not working but "Mapinfo File" is?
    – sn1ks
    Jan 19 at 12:59

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.