Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
    
You can find a sample greek shapefile here: geodata.gov.gr/geodata/… at the SHP button –  Andre Joost Dec 16 '12 at 6:27
    
... and the GML from the linkbutton next to it works in QGIS without any complaints. AAARGH!!!! –  Andre Joost Dec 17 '12 at 8:17
1  
I'd like to tahnk everyone for their help. I tried most of the solutions provided, expect for the .cpg one which I'll try in my laptop, some of them worked. For INSPIRE datasets, like the ones used from the geodata.gov.gr portal, it works when you select either UTF8 or ISO-8859-7 when opening the shapefile in QGIS. The problem lies with shapefiles produced without specifying the relevant encoding. Nevertheless it seems I can use most of my dataset, maybe it'll be easier in the next QGIS version. –  ZISIS Dec 18 '12 at 16:52
    
Please do give the .cpg method a try, since it essentially declares the shapefile's encoding - useful if the shapefile was produced without specifying a correct encoding. –  anoved Dec 21 '12 at 16:12
add comment

3 Answers 3

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.

Unicode attribute values, with and without UTF-8 .cpg file

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:

Greek shapefile with default encoding

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:

Greek shapefile with Greek code page specified

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:

Screenshot of sample Greek shapefile with cpg file open in qgis on linux

share|improve this answer
    
Unfortunately QGIS does not react on any .cpg file. –  Andre Joost Dec 15 '12 at 12:16
1  
On 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. –  anoved Dec 15 '12 at 16:08
1  
You can find a sample greek shapefile here: geodata.gov.gr/geodata/… at the SHP button. I did not suceed with the cpg file... –  Andre Joost Dec 15 '12 at 20:06
1  
Yes I can confirm the correct encoding of the Greek names. They appear correctly –  nickves Dec 16 '12 at 3:42
1  
@anoved: Thanks a lot! This works with Vietnamese on Ubuntu 12.04, Qgis 1.8.0. –  Cao Minh Tu Mar 8 '13 at 8:41
show 5 more comments

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.

share|improve this answer
    
ISO-8859-7 is the root of all evils. Windows still saves in that encoding by default –  nickves Dec 15 '12 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. –  Andre Joost Dec 15 '12 at 12:14
1  
I 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. –  nickves Dec 15 '12 at 12:34
add comment

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.

share|improve this answer
    
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... –  ZISIS Dec 14 '12 at 18:21
    
Try to save the shape file as a new one and set the encoding from the start to UTF... –  GR_ Dec 14 '12 at 18:29
    
what kind of encoding does the corresponding dbf- file have. is it utf-8 too? –  Kurt Dec 14 '12 at 18:36
    
Thanx again, but it doesn't work either. –  ZISIS Dec 14 '12 at 18:36
2  
take a look here. gis.stackexchange.com/questions/31885/… –  Kurt Dec 14 '12 at 20:21
show 6 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.