2

I'm adding MapInfo TAB files to SQLite (SpatiaLite) database using those arguments:

ogr2ogr -f "SQLite" dataset.sqlite somelayer.tab -dsco spatialite=yes

Source file somelayer.tab have WindowsCyrillic encoding defined:

!table
!version 450
!charset WindowsCyrillic

Definition Table
  Type NATIVE Charset "WindowsCyrillic"
  Fields 1
    Name Char (100) ;

As a result, dataset.sqlite have somelayer table with VARCHAR Name column.

But I need store Name values in unicode.

How can I tell ogr2ogr use unicode NVARCHAR type for Name column and encode text from WindowsCyrillic (Windows-1251) to UTF-8 encoding for storing.

1 Answer 1

2

SQLite does not care about types and VARCHAR and NVARCHAR mean just the same for it https://stackoverflow.com/questions/3930501/difference-between-varchar-nvarchar-in-sqlite.

The real problem is in the GDAL MapInfo driver that does not handle character encodings. There are some workarounds:

  1. Convert MapInfo data into MID/MIF format with ogr2ogr and convert Windows-1251 into UTF-8 with iconv. Conversion with ogr2ogr from MID/MIF (UTF-8) into SpatiaLite should go right now.
  2. Alternatively, convert MapInfo data first into GML with ogr2ogr and convert the GML file info UTF-8 with iconv. Finally convert GML into SpatiaLite.
2
  • yes, I currently use slightly modified 1st workaround. I wrote single powershell script to convert whole folder to mif/mid using og2ogr, recode it to UTF-8 using .NET ($text = [IO.File]::ReadAllText($mid, $encoding); [IO.File]::WriteAllText($mid, $text, [Text.Encoding]::UTF8);) and then finally append to SQLite database using ogr2ogr. But I was hoping that GDAL MapInfo driver have some key to read specified encdoing and write in UTF-8.
    – Savvkin
    Commented Dec 10, 2014 at 9:33
  • Had a similar problem going from a Win-1252 .TAB file to Postgres, used option (2) from above. Code follows in case it helps anyone. Convert to GML: ogr2ogr -f GML original-1252.gml original-1252.TAB --config OGR_FORCE_ASCII NO Change encoding: iconv -f CP1252 -t UTF-8 original-1252.gml >converted-utf8.gml Finally load: ogr2ogr -f PostgreSQL %PG_CONECTION_DETAILS% converted-utf8.gml -nln schema.new_table_name
    – Rob
    Commented Jan 11, 2016 at 11:45

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.