3

I have a .TAB-file with MultiLines. When I load it to QGIS, in layer properties it says Geometry: Line (LineString) which is wrong. When I try to do some operations with geometries (like snap to layer) QGIS breaks all geometries into single lines.

I've tried to:

  1. Save the layer with the "force multi-type" option enabled
  2. Create a memory layer with multi-type geometry and save it as .TAB
  3. Create a .TAB with one multiline geometry feature

None of the options worked.

My final goal is just to save processed multi-type geometries back to .TAB file without splitting into single-type.

3
  • What format is the geometry in your .TAB file, is it WKT?
    – Matt
    Commented Oct 25, 2022 at 19:16
  • @Matt This is Mapinfo format. The question about how QGIS handles this type of source. I've already found out how to save my geometries with PyQgis and seems like no way to do it via GUI.
    – BlackTesta
    Commented Oct 27, 2022 at 10:43
  • Hi @BlackTesta Can you add your solution with PyQGIS as an answer to your own question, please? I will vote your answer up. It will be useful for others.
    – KVO
    Commented Dec 11, 2022 at 23:02

1 Answer 1

1

It's not an answer to my question. But @KVO asked for PyQGIS solution. Here is mine:

for layer in QgsProject.instance().mapLayers().values():
    source = layer.source()
    ext=source.split('|')[0].rpartition('.')[-1]
    if ext.lower() == 'tab':
        if layer.geometryType() == 2:
            newSource=source.replace('geometrytype=Polygon','geometrytype=MultiPolygon')
        elif layer.geometryType() == 1:
            newSource=source.replace('geometrytype=LineString','geometrytype=MultiLineString')
        layer.setDataSource(newSource,layer.name(),'ogr')
        layer.reload()
        layer.triggerRepaint()
2
  • Thank you for you response. What is about you question: the last QGIS version, which supported multipart geometry of TAB files was QGIS 3.12.3 Bucuresti. Because the editing tool Add part worked in it with TAB files. And in the version 3.14 Pi it was already unabled. I made a bug report on Github github.com/qgis/QGIS/issues/46644 But in the recent QGIS versions adding part was broken even for geopackage layers. github.com/qgis/QGIS/pull/54611
    – KVO
    Commented Oct 26, 2023 at 23:25
  • I haven't received your response a month ago, I only accidentally saw this post just now. Unfortunately, this @ symbol seems to be not working too. Everything was broken)))
    – KVO
    Commented Oct 26, 2023 at 23:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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