[GIS] Converting encoding using ogr2ogr on macOS

macogrogr2ogr

I'm trying to convert my shapefiles from ISO-8859-10, also known as latin6 using ogr2ogr on my Mac like this (learned from here):

export SHAPE_ENCODING="latin6"
ogr2ogr file_utf8.shp file.shp -lco ENCODING=UTF-8

But, nothing is converted. Well, a new shapefile is created but it still has the same old encoding. I've tried with SHAPE_ENCODING="ISO-8859-10" and still no happy result. Then I tried just a random word like SHAPE_ENCODING="blablabla" but then ogr2ogr gives me an error:

Failed to create field name 'FIELD1' : cannot convert to blablabla

So it seems like ogr2ogr understands the latin6 encoding but then doesn't do the job for me. Maybe this is a macOS only problem?

If I do the conversion to GeoJSON with SHAPE_ENCODING="latin6" the GeoJSON file gets recoded to UTF-8 fine:

export SHAPE_ENCODING="latin6"
ogr2ogr -f GeoJSON file_utf8.geojson file.shp

Then I can convert the GeoJSON file back to Shape again:

export SHAPE_ENCODING="utf-8"
ogr2ogr -f "ESRI Shapefile" file_utf8.shp file_utf8.geojson

Is there a way of converting encoding without going through the GeoJSON conversion process?

Best Answer

Here's an answer based on Dimitry Baryshnikovs comment to my question. If there isn't a CPG file with the same name as the shape file, create one and add the line 885910.

In my case I already had CPG files but they were all wrong (consisted of the line ISO 88591) which caused the big problem. After altering my CPG files to 885910 I had no problem running the line of code:

ogr2ogr file_utf8.shp file.shp -lco ENCODING=UTF-8