1

I am trying to create empty tab file with different approach's.

1st approach

fn = r'E:\data\spilce.tab'
shpfields = QgsFields()
id = QgsField('id', QVariant.Int)
shpfields.append(id)
gtp = QgsWkbTypes.Point
cr = QgsCoordinateReferenceSystem('EPSG:4326')
QgsVectorFileWriter(fn, 'utf-8', shpfields, gtp, cr, 'MapInfo File')

2nd approach

fn = r'E:\data\spilce.tab'
cr = QgsCoordinateReferenceSystem('EPSG:4326')
ipointlayer = QgsVectorLayer("Point?crs='EPSG:4326'", "temporary_points", "memory")
ipointlayer.dataProvider().addAttributes([QgsField("Id", QVariant.String)])
ipointlayer.updateFields()
QgsVectorFileWriter.writeAsVectorFormat(ipointlayer, fn, 'utf-8', cr, 'MapInfo File')

Above codes creating non-geometry tab files.

How to create Point Geometry TAB file?

2
  • Not sure how. Issue seems not related to PyQGIS itself. Created a tab file not empty by exporting a shp to Mapinfo Tab. Then, opened the new file, started editing and removed all features from the new layer, saved changes, removed the layer. Then, tried to add it again and QGIS considered this empty layer as attribute layer.
    – ThomasG77
    Mar 16 at 20:50
  • Tested the same code with Shapefile and GPKG. Driver specific but did not found explanation at the moment
    – ThomasG77
    Mar 16 at 22:14

Your Answer

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

Browse other questions tagged or ask your own question.