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.
3 Answers
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 .cpg
files.
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 .cpg
file.
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:
-
-
1On the contrary, QGIS 1.8 does recognize
.cpg
files (I've edited my answer with an example) - but since I don't have a Greek shapefile to test, I concede that it may not be any help in ZISIS' case.– anovedCommented Dec 15, 2012 at 16:08 -
1You can find a sample greek shapefile here: geodata.gov.gr/geodata/… at the SHP button. I did not suceed with the cpg file...– AndreJCommented Dec 15, 2012 at 20:06
-
1Yes I can confirm the correct encoding of the Greek names. They appear correctly– nickvesCommented Dec 16, 2012 at 3:42
-
1@anoved: Thanks a lot! This works with Vietnamese on Ubuntu 12.04, Qgis 1.8.0. Commented Mar 8, 2013 at 8:41
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
SET SHAPE_ENCODING=UTF-8
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:
http://lists.osgeo.org/pipermail/qgis-user/2012-November/020021.html
It works on the cited shapefile only with Qgis Master (1.9.0):
In Settings -> Options -> General, there is a checkbox
[ ] Ignore shapefile encoding
Uncheck it.
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.
SOLUTION C
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.
-
ISO-8859-7 is the root of all evils. Windows still saves in that encoding by default– nickvesCommented Dec 15, 2012 at 11:54
-
ISO-8859-7 is the standard encoding for Greek alphabet support. You can't blame Greek authorities to use that. And it depends on your locale settings what Windows uses apart from utf-8.– AndreJCommented Dec 15, 2012 at 12:14
-
1I don't blame them. Although (trust me on this!) the world would be a better place is everyone used the same encoding routines. You can't imagine how many localized char sets, are out there, and how much guess work it needs to get it right. For example, if you don't know about the magic number 8859-7 , you'll only see gibberish.– nickvesCommented Dec 15, 2012 at 12:34
This should be possible if you open the layer preferences, to to General and set the encoding to UTF-8.
Edit: Use OpenOffice to open the dbf, set the encoding to UTF-8 and then hit save. You may need to add and delete a letter to get the save-option.
-
Thanx, I tried it but doesn't work. There's also a 'greek' option but doesn't seem to work either. It should be possible but...– ZISISCommented Dec 14, 2012 at 18:21
-
Try to save the shape file as a new one and set the encoding from the start to UTF...– GR_Commented Dec 14, 2012 at 18:29
-
what kind of encoding does the corresponding dbf- file have. is it utf-8 too?– KurtCommented Dec 14, 2012 at 18:36
-
-
2
.cpg
method a try, since it essentially declares the shapefile's encoding - useful if the shapefile was produced without specifying a correct encoding.