[Qgis-user] Batch "conversion"

Carson Farmer carson.farmer at gmail.com
Tue Apr 6 06:52:29 PDT 2010


Matej,

Something like the following might do it (not tested):

import os
import qgis.core
# dir_name is the path to your directory of TAB files
for layer_string in os.listdir(dir_name):
    whole_name = dir_name + layer_string
    layer_name = layer_string.replace(".tab","")
    layer = QgsVectorLayer(whole_name, layer_name, "ogr")
    QgsVectorFileWriter.writeAsShapefile(layer, dir_name + layer_name
+ ".shp", "UTF-8", layer.crs(), False)

That's a bit of a hack, but it should do it for you I think...


Cheers,

Carson


On Tue, Apr 6, 2010 at 1:21 PM, Matej <matej at matnet.net> wrote:
> Hi all!
>
> Sometimes it happens to me that I have a lot of TAB files to convert to SHP
> TABs can be opened only for reading but not writing and saving them to SHP
> solves this issue for us. However, clicking Save As for every layer and
> specifying the same name as TAB filename does (only the extension is
> different) and also all the projection settings are the same for all files.
> So I was thinking about some sort of batch "conversion".
>
> Would it be useful? Is is (I believe it is) possible to be implemented?
>
> Thanks,
> Matej
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user
>
>



-- 
Carson J. Q. Farmer
ISSP Doctoral Fellow
National Centre for Geocomputation
National University of Ireland, Maynooth,
http://www.carsonfarmer.com/



More information about the Qgis-user mailing list