Exporting multiple layers with different geometry types to one MapInfo TAB file in QGIS

exportlayersopen-source-gisqgistab

It is no problem in QGIS to open MapInfo .tab files with combined geometry type. If a single .tab file contains points, polylines and polygons then QGIS will load three separate layers for each geometry type.

But how can I export these layers to a single .tab file after editing? It is important because many organizations (business partners) still use MapInfo and they didn't want their geospatial data structure to be modied, changed (broken).
The problem is in the symbology retaining problem. QGIS saves simple polygon and polyline symbology settings when exporting layers (but not point layers) to MapInfo .tab format. (colour of polygons and the width and colour of outline; colour and width of polylines). The edited primary .tab file doesn't contain the symbology of added objects. That's why the primary .tab file must be exported and not simply edited.

Best Answer

You can export point, line, and polygon layers into separate files and combine them with ogr2ogr.

Test data

points.mif

Version 300
Charset "Neutral"
Delimiter ","
Columns 2
  R_G_B Char(254)
  COLOR Char(254)
Data

Point -90.5566923029394 14.5906248310583
    Symbol (35,0,12)
Point -90.5515144114431 14.6013641615691
    Symbol (35,0,12)
Point -90.5407750809323 14.5938849849634
    Symbol (35,0,12)

lines.mif

Version 300
Charset "Neutral"
Delimiter ","
Columns 2
  R_G_B Char(254)
  COLOR Char(254)
Data

Line -90.5439393479578 14.6041448810763 -90.5314740536149 14.6133500215141
    Pen (1,2,9288960)
Line -90.5536239227934 14.6182402523717 -90.5630208369904 14.6045284285946
    Pen (1,2,9288960)
Line -90.557651171735 14.5991587633392 -90.5396244383776 14.5850633920438
    Pen (1,2,9288960)

polygons.mif

Version 300
Charset "Neutral"
Delimiter ","
Columns 2
  R_G_B Char(254)
  COLOR Char(254)
Data

Region 1
  4
-90.5361725107134 14.6028024647625
-90.5243784245275 14.6012682746895
-90.5358848500747 14.5908166048174
-90.5361725107134 14.6028024647625
    Pen (1,2,0)
    Brush (2,255)
Region 1
  4
-90.5701164660778 14.5969533651093
-90.5593771355671 14.5942685324816
-90.5737601675012 14.5838168626095
-90.5701164660778 14.5969533651093
    Pen (1,2,0)
    Brush (2,255)
Region 1
  4
-90.5453776511512 14.6222675013133
-90.533200017447 14.6205415374812
-90.5498843344906 14.6101857544886
-90.5453776511512 14.6222675013133
    Pen (1,2,0)
    Brush (2,255)

ogr2ogr commands for combining points, lines, and polygons into layer "collect"

ogr2ogr -f "MapInfo File" collect.tab points.mif -nln collect
ogr2ogr -f "MapInfo File" -update -append collect.tab lines.mif -nln collect
ogr2ogr -f "MapInfo File" -update -append collect.tab polygons.mif -nln collect

ogrinfo that confirms that all features with individual styles are now on the same layer

ogrinfo collect.tab -al
INFO: Open of `collect.tab'
      using driver `MapInfo File' successful.

Layer name: collect
Geometry: Unknown (any)
Feature Count: 9
Extent: (-90.570000, 14.580000) - (-90.510000, 14.620000)
Layer SRS WKT:
ENGCRS["Nonearth",
    EDATUM[""],
    CS[Cartesian,2],
        AXIS["(E)",east,
            ORDER[1],
            LENGTHUNIT["Meter",1]],
        AXIS["(N)",north,
            ORDER[2],
            LENGTHUNIT["Meter",1]]]
Data axis to CRS axis mapping: 1,2
R_G_B: String (254.0)
COLOR: String (254.0)
OGRFeature(collect):1
  R_G_B (String) = FF0000
  COLOR (String) = 1
  Style = SYMBOL(a:0,c:#000000,s:12pt,id:"mapinfo-sym-35,ogr-sym-9")
  POINT (-90.57 14.6)

OGRFeature(collect):2
  R_G_B (String) = FF0000
  COLOR (String) = 1
  Style = SYMBOL(a:0,c:#000000,s:12pt,id:"mapinfo-sym-35,ogr-sym-9")
  POINT (-90.54 14.6)

OGRFeature(collect):3
  R_G_B (String) = FF0000
  COLOR (String) = 1
  Style = SYMBOL(a:0,c:#000000,s:12pt,id:"mapinfo-sym-35,ogr-sym-9")
  POINT (-90.54 14.6)

OGRFeature(collect):4
  R_G_B (String) = 8DBD00
  COLOR (String) = 62
  Style = PEN(w:1px,c:#8dbd00,id:"mapinfo-pen-2,ogr-pen-0",cap:r,j:r)
  LINESTRING (-90.54 14.61,-90.54 14.61)

OGRFeature(collect):5
  R_G_B (String) = 8DBD00
  COLOR (String) = 62
  Style = PEN(w:1px,c:#8dbd00,id:"mapinfo-pen-2,ogr-pen-0",cap:r,j:r)
  LINESTRING (-90.54 14.62,-90.57 14.61)

OGRFeature(collect):6
  R_G_B (String) = 8DBD00
  COLOR (String) = 62
  Style = PEN(w:1px,c:#8dbd00,id:"mapinfo-pen-2,ogr-pen-0",cap:r,j:r)
  LINESTRING (-90.57 14.6,-90.54 14.58)

OGRFeature(collect):7
  R_G_B (String) = 0000FF
  COLOR (String) = 5
  Style = BRUSH(fc:#0000ff,id:"mapinfo-brush-2,ogr-brush-0");PEN(w:1px,c:#000000,id:"mapinfo-pen-2,ogr-pen-0",cap:r,j:r)
  POLYGON ((-90.54 14.61,-90.51 14.6,-90.54 14.6,-90.54 14.61))

OGRFeature(collect):8
  R_G_B (String) = 0000FF
  COLOR (String) = 5
  Style = BRUSH(fc:#0000ff,id:"mapinfo-brush-2,ogr-brush-0");PEN(w:1px,c:#000000,id:"mapinfo-pen-2,ogr-pen-0",cap:r,j:r)
  POLYGON ((-90.57 14.6,-90.57 14.6,-90.57 14.58,-90.57 14.6))

OGRFeature(collect):9
  R_G_B (String) = 0000FF
  COLOR (String) = 5
  Style = BRUSH(fc:#0000ff,id:"mapinfo-brush-2,ogr-brush-0");PEN(w:1px,c:#000000,id:"mapinfo-pen-2,ogr-pen-0",cap:r,j:r)
  POLYGON ((-90.54 14.62,-90.54 14.62,-90.54 14.61,-90.54 14.62))
Related Question