0

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?

nmtoken
  • 13,355
  • 5
  • 38
  • 87
oskarlin
  • 1,941
  • 1
  • 28
  • 45
  • Created a batch script using the geojson method: https://gist.github.com/oskarlin/51e3758ce1f1d89440324eb0a564a65f – oskarlin Oct 30 '17 at 14:54
  • I have been using GML as an interim format and iconv for changing the character set. Your batch is at least as good. – user30184 Oct 30 '17 at 17:42
  • 1
    Create the text file named as your shape file and cpg extension file.cpg and put one line of text 8859-10 into it. This will help GDAL to get right encoding of your shape file. – Dmitry Baryshnikov Nov 01 '17 at 08:38
  • In my source files containing the latin6 encoding the CPG-files had this: "ISO 88591" in the CPG file. When I change it to "885910" it now works! – oskarlin Jan 10 '19 at 10:04

1 Answers1

1

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
oskarlin
  • 1,941
  • 1
  • 28
  • 45