3

I am attempting to convert a few files from ESRI Shapefiles to MapInfo Tab via python. As I understand, the 'gdalogr:convertformat' processing algorithm can be used for this. My code looks something like this at the moment...

def convert_layer(layer,filetype, save_location):
    from processing.core.Processing import Processing
    Processing.initialize()
    print "Converting", layer, "to Mapinfo TAB..."
    processing.tools.general.runalg('gdalogr:convertformat',layer, filetype, "", save_location)

convert_layer("path/to/layer.shp", 5, "path/to/tab")

When I run this, QGIS reports that the conversion was successful, however no files are placed in the output folder.

To make matters more confusing, this same process seems to work fine in QGIS 2.14.

Has something changed between 2.14 and 2.18?

  • Are you running this in the Python Console or as a standalone script? – Joseph Jan 6 '17 at 15:14
  • I am running all code in the QGIS console – JamieTasker Jan 6 '17 at 15:14
3

If you're running your code in the Python Console in QGIS, you can shorten your code to:

import processing
def convert_layer(layer, filetype, save_location):
    print "Converting", layer, "to Mapinfo TAB..."
    processing.runalg('gdalogr:convertformat', layer, filetype, "", save_location)

convert_layer("path/to/layer", 5, "path/to/tab")

I tested the following code in QGIS 2.18.2 for Windows 7 64-bit and received a .tab file as output:

convert_layer("C:/Users/Me/Desktop/point_example.shp", 5, "C:/Users/Me/Desktop/output")

See if it works for you.

  • Thank you. It would appear as though 2.18.1 is bugged. Myself and a colleague both tried your code and got no error messages but no TAB file outputs. On my 2.14 install, your code worked perfectly. Looks as though the solution is either to downgrade to 2.14 or upgrade to 2.18.2! – JamieTasker Jan 6 '17 at 15:43
  • @JamieTasker - Most welcome! Hmm, in your /user/.qgis2/python/plugins directory, is there a folder named "processing"? If so, try removing this from the directory, load QGIS 2.18 and attempt the code again. – Joseph Jan 6 '17 at 15:48
  • Still no dice I'm afraid... interestingly I just tried to downgrade a PC to 2.14.10 and the problem still happens. It's bizarre that only my 2.14.4 install seems to function correctly... – JamieTasker Jan 6 '17 at 16:24
  • @JamieTasker - Bizarre indeed, perhaps try 2.18.2? – Joseph Jan 9 '17 at 10:30

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.