Suk0na
Suk0na

Reputation: 1

How to change the encoding of fields in .tab file C# + Gdal?

There is a service that exports layer objects to the MapInfo .tab format. This service uses the Gdal 3.3 library version. The service is deployed on a Linux server. There is a problem with exporting objects that have Cyrillic characters in their attribute names. No matter how I specify or explicitly translate the fields to UTF-8 before adding them to the layer, there is still no result. How do I specify an explicit UTF-8 encoding for the fields of my files so that this encoding is necessarily applied?

Fragment of service:

using (var myDriver = Ogr.GetDriverByName("MapInfo File"))
using (var myDataSource = myDriver.CreateDataSource("my_file.tab", new string[] { "ENCODING=UTF-8" }))
using (var myLayer = myDataSource.CreateLayer("LAYER_NAME", src, wkbGeometryType.wkbUnknown,
           new string[] { "ENCODING=UTF-8" }))
{
    foreach (var attr in attributes)
    {
        var featureDefinition = new FieldDefn(attr.Key, attributeType);
        myLayer.CreateField(featureDefinition, 0);
    }

    var layerDefinition = myLayer.GetLayerDefn();
    foreach (var layerObject in objects)
    {
        var feature = new Feature(layerDefinition);
        feature.SetGeometry(layerObject.Geometry);
        foreach (var (key, value) in layerObject.Attributes)
        {
            feature.SetField(key, value);
        }

        myLayer.CreateFeature(feature);
    }
}

But in QGIS with UTF-8 I have this result

Upvotes: 0

Views: 20

Answers (0)

Related Questions