I'd like to ask whether there is a way to read greek fonts in a shapefile's attribute table within QGIS 1.8.0.
You might try creating a file with the same base name as the shapefile but with a
.cpg extension, containing a single line of text identifying the encoding, be it
UTF-8 or something else. I am not sure if this will resolve the problem with QGIS, but I have had some success with this method to force multi-byte characters in attribute data to be interpreted correctly (typically in situations where attribute data was written in an encoding incompatible with the code page given in the DBF file header's LDID field).
See http://support.esri.com/en/knowledgebase/techarticles/detail/21106 for more info on
Update 1: Just to illustrate that QGIS does respond to the presence of
.cpg files, here is an attribute table screenshot of two identical test shapefiles. The only difference is that attrb has an
attrb.cpg file declaring
UTF-8. In this case, the
Unicode test characters are rendered correctly.
Both shapefiles have
87 as the value of the Language Driver ID (LDID) byte in the DBF header, indicating ISO-8859-1 encoding. Thus, at least in this case, providing a
.cpg allows the user to override the internally-declared encoding without actually modifying or re-saving the DBF file.
I do not have a shapefile containing Greek characters to test, but you might try declaring
8859-7 (ISO) or
1253 (ANSI) in place of
UTF-8 in the
Update 2: I downloaded a sample shapefile from the page Andre suggested (thanks!). As you can see, by default the fields containing Greek text do appeared garbled:
I then created a file named
nomoi_okxe.cpg in the same directory as the shapefile, containing the text
1253 (the Windows code page number for Greek). I then reopened the shapefile in QGIS:
That looks Greek to me!
ZISIS, is this sample shapefile representative of the files you need to work with?
Update 3: The examples above were based on QGIS 1.8.0 on Mac OS X 10.8.2. I have also tested this method with QGIS 1.7.5 on Linux Mint 14:
SOLUTION A for utf-8 encoded shapefiles
Supposed you are working on Windows, look for qgis.bat in bin directory, and open it with a text editor. after the first line, insert
and save. Qgis 1.8.0 has some problems with encoding, using your computers default font instead of the one you specify. It is fixed in Qgis Master (1.9.0) by now, which you can install with osgeo4w setup.
SOLUTION B for ISO-8859-7 encoded shapefiles
We had a similar issue lately on the mailing list:
It works on the cited shapefile only with Qgis Master (1.9.0):
In Settings -> Options -> General, there is a checkbox
[ ] Ignore shapefile encoding
Then open the shapefile in QGIS with ISO-8859-7.
With this option shapefile encoding is done the same way as in Qgis 1.7.4, that is leaving it to QGIS and not GDAL.
If you want to work on with QGIS Lisboa, save the shapefile as
UTF-8 and proceed with Solution A, until the next stable version of QGIS is released.
create a file named
< filename >.cpg and
1253 as content in the same folder as the shapefile.
convert the shapefile with ogr2ogr:
ogr2ogr -a_srs EPSG:2100 -f GML nomoi_utf.gml nomoi_okxe.shp
ogr2ogr --config SHAPE_ENCODING "UTF-8" -a_srs EPSG:2100 nomoi_utf.shp nomoi_utf.gml
This allows GDAL to encode ISO-8859-7 on reading, and writes UTF-8. Unfortunately, writing to shp in one step does not work the same way. You can use the GML or the utf.shapefile with Solution A.