1

I'm migrating from calling native MiTAB operations for exporting features to a MapInfo TAB file to using GDAL and the MapInfo driver. I'm using C# and MaxRev.Gdal.Core package (and MaxRev.Gdal.WindowsRuntime.Minimal)

But when I try to export features that has geometry collections with mixed geometry types, GDAL creates multiple features in the TAB file.

If I try a feature with a collection of polygons, all is good too.. 1 feature with 2 polygons.

My old code calling MiTAB directly works fine.

Simple code showing the issue

{
        // Register the OGR library
        Ogr.RegisterAll();

        // Create a new MapInfo Tab file
        DataSource ds = Ogr.GetDriverByName("MapInfo File").CreateDataSource(@"c:\temp\playground.tab", null);

        // Create a layer
        Layer layer = ds.CreateLayer("layer", null, wkbGeometryType.wkbUnknown, null);

        // Create a feature
        Feature feature = new Feature(layer.GetLayerDefn());

        // Create a MultiGeometry
        Geometry multiGeometry = new Geometry(wkbGeometryType.wkbGeometryCollection);

        
        // Add polygons and polylines to the MultiGeometry
        Geometry polygonGeometry = Geometry.CreateFromWkt("POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))");
        Geometry polylineGeometry = Geometry.CreateFromWkt("LINESTRING (2 0, 3 0, 3 1, 2 1)");

        multiGeometry.AddGeometry(polygonGeometry);
        multiGeometry.AddGeometry(polylineGeometry);

        // Set the MultiGeometry as the feature's geometry
        feature.SetGeometryDirectly(multiGeometry);

        // Create the feature in the layer
        layer.CreateFeature(feature);

        // Cleanup
        feature.Dispose();
        ds.Dispose();
    }
2
  • Have you checked that multiGeometry is really GEOMETRYCOLLECTION ( LINESTRING ( 2 0, 3 0, 3 1, 2 1 ), POLYGON (( 0 0, 0 1, 1 1, 1 0, 0 0 ))) once you have added the components with your code?
    – user30184
    Commented Jan 18 at 12:54
  • 1
    Yes multiGeometry.ExportToWkt(out wkt); gives me: GEOMETRYCOLLECTION (POLYGON ((0 0,0 1,1 1,1 0,0 0)),LINESTRING (2 0,3 0,3 1,2 1))
    – Mpalle
    Commented Jan 18 at 13:01

1 Answer 1

2

Maybe you have found a bug in the GDAL mitab driver if you have been able to build all kind of GeometryCollections by using the mitab library directly. GDAL really seems to split the member geometries into separate features.

I made a simple test with your geometry GEOMETRYCOLLECTION (POLYGON ((0 0,0 1,1 1,1 0,0 0)),LINESTRING (2 0,3 0,3 1,2 1)).

ogr2ogr -f "MapInfo File" geometrycollection.tab geometrycollection.json

ogrinfo geometrycollection.tab -al
INFO: Open of `geometrycollection.tab'
      using driver `MapInfo File' successful.
...
OGRFeature(geometrycollection):1
  def (String) =
  LINESTRING (2 0,3 0,3 1,2 1)

OGRFeature(geometrycollection):2
  def (String) =
  POLYGON ((0 0,0 1,1 1,1 0,0 0))

I suggest to write mail to the gdal-dev mailing list and ask.

1
  • 1
    Thanks, ill try that
    – Mpalle
    Commented Jan 18 at 20:58

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.