Skip to content

Commit

Permalink
MITAB: Add test with UTF-8 encoded files
Browse files Browse the repository at this point in the history
  • Loading branch information
drons committed Jun 25, 2024
1 parent 88157e8 commit d06db89
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
3 changes: 3 additions & 0 deletions autotest/ogr/data/mitab/utf8.mid
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"Значение А","Значение Б","Значение В","Значение Г","Значение Д"
"Значение 1","Значение 2","Значение 3","Значение 4","Значение 5"
"Полигон","Синий","Заливка","А а Б б","ЪЫЁЩ"
31 changes: 31 additions & 0 deletions autotest/ogr/data/mitab/utf8.mif
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Version 1520
Charset "UTF-8"
Delimiter ","
CoordSys Earth Projection 8, 1001, "m", 39, 0, 1, 7500000, 0 Bounds (-749281.53901, -10002137.4978) (15749281.539, 10002137.4978)
Columns 5
Поле_А Char(10)
Поле_Б Char(10)
Поле_В Char(10)
Поле_Г Char(10)
Поле_Д Char(10)
Data

Point 7404648.72 6144520.22
Symbol (35,16711680,12)
Pline 4
7404638.32 6144512.27
7404646.55 6144515.77
7404653.33 6144520.94
7404657.51 6144525.21
Pen (2,2,65280)
Region 1
6
7404649.37 6144522.85
7404646.78 6144518.96
7404642.44 6144519.88
7404642.59 6144522.85
7404645.79 6144523.76
7404649.37 6144522.85
Pen (1,2,0)
Brush (2,16777215,16777215)
Center 7404645.9 6144521.36
28 changes: 27 additions & 1 deletion autotest/ogr/ogr_mitab.py
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,7 @@ def test_ogr_mitab_45(tmp_vsimem, frmt, lyrCount):
# Test read MapInfo layers with encoding specified


@pytest.mark.parametrize("fname", ("tab-win1251.TAB", "win1251.mif"))
@pytest.mark.parametrize("fname", ("tab-win1251.TAB", "win1251.mif", "utf8.mif"))
def test_ogr_mitab_46(fname):

fldNames = ["Поле_А", "Поле_Б", "Поле_В", "Поле_Г", "Поле_Д"]
Expand Down Expand Up @@ -2268,6 +2268,32 @@ def test_ogr_mitab_tab_write_field_name_with_dot(tmp_vsimem):
ds = None


###############################################################################


@pytest.mark.parametrize("ext", ["mif", "tab"])
def test_ogr_mitab_write_utf8_field_name(tmp_vsimem, ext):

tmpfile = tmp_vsimem / f"ogr_mitab_tab_write_utf8_field_name.{ext}"
ds = ogr.GetDriverByName("MapInfo File").CreateDataSource(
tmpfile, options=["ENCODING=UTF-8", f"FORMAT={ext}"]
)
lyr = ds.CreateLayer("test")
lyr.CreateField(ogr.FieldDefn("地市", ogr.OFTInteger))
f = ogr.Feature(lyr.GetLayerDefn())
f["地市"] = 1
f.SetGeometryDirectly(ogr.CreateGeometryFromWkt("POINT(2 3)"))
lyr.CreateFeature(f)
with gdal.quiet_errors():
ds = None

ds = ogr.Open(tmpfile)
lyr = ds.GetLayer(0)
f = lyr.GetNextFeature()
assert f["地市"] == 1
ds = None


###############################################################################
# Test read text labels with local encoding from mif/mid file

Expand Down

0 comments on commit d06db89

Please sign in to comment.