9

I have OSM dataset containing names with national characters (this is CSV export, but I have it in SHP):

osm_id,code,fclass,population,name,longitude,latitude
276645544,1003,village,221,Krč,14.248410,49.194988
444571400,1003,village,88,Radonice,14.548085,49.143251
488567474,1003,village,115,Doubravka,14.363835,49.282158
488567478,1003,village,114,Koloměřice,14.399437,49.280328
488567484,1003,village,111,Údraž,14.309249,49.281551
491452727,1004,hamlet,33,Poněšice,14.481200,49.105121
601855465,1003,village,147,Hvožďany,14.433230,49.286094
631878480,1003,village,211,Myšenec,14.208999,49.223213

and would like to converte them to this form:

osm_id,code,fclass,population,name,longitude,latitude
276645544,1003,village,221,Krc,14.248410,49.194988
444571400,1003,village,88,Radonice,14.548085,49.143251
488567474,1003,village,115,Doubravka,14.363835,49.282158
488567478,1003,village,114,Kolomerice,14.399437,49.280328
488567484,1003,village,111,Udraz,14.309249,49.281551
491452727,1004,hamlet,33,Ponesice,14.481200,49.105121
601855465,1003,village,147,Hvozdany,14.433230,49.286094
631878480,1003,village,211,Mysenec,14.208999,49.223213

where accents are removed so instead of "č,š,ř,á" etc. you have "c,s,r,a". I does not have to be editing of current column - could be creating new column with converted names.

I am currently going to use some online tool like this one for the CSV file but it would be great if I could solve this in QGIS directly.

closed as off-topic by artwork21, mgri, Mapperz Mar 16 '17 at 14:19

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    why off topic? I am primarily asking for direct solution in QGIS without need to export my data to CSV and import again. – Juhele Mar 17 '17 at 10:54
9

Yes, it's possible with the unidecode library in python... (documentation). This tries to find the nearest ASCII equivalent to each unicode character.

from unidecode import unidecode

s="""
osm_id,code,fclass,population,name,longitude,latitude
276645544,1003,village,221,Krč,14.248410,49.194988
444571400,1003,village,88,Radonice,14.548085,49.143251
488567474,1003,village,115,Doubravka,14.363835,49.282158
488567478,1003,village,114,Koloměřice,14.399437,49.280328
488567484,1003,village,111,Údraž,14.309249,49.281551
491452727,1004,hamlet,33,Poněšice,14.481200,49.105121
601855465,1003,village,147,Hvožďany,14.433230,49.286094
631878480,1003,village,211,Myšenec,14.208999,49.223213
"""

print(unidecode(s))

output:-

osm_id,code,fclass,population,name,longitude,latitude
276645544,1003,village,221,Krc,14.248410,49.194988
444571400,1003,village,88,Radonice,14.548085,49.143251
488567474,1003,village,115,Doubravka,14.363835,49.282158
488567478,1003,village,114,Kolomerice,14.399437,49.280328
488567484,1003,village,111,Udraz,14.309249,49.281551
491452727,1004,hamlet,33,Ponesice,14.481200,49.105121
601855465,1003,village,147,Hvozdany,14.433230,49.286094
631878480,1003,village,211,Mysenec,14.208999,49.223213

This code will convert one CSV file into another:-

from unidecode import unidecode
with open("/path/to/original.csv", "r") as input_file:
    with open("/path/to/converted.csv","w") as output_file:
        output_file.write(unidecode(input_file.read()))
  • 1
    Hmm, looks like I cannot avoid export in CSV and import back. I will probably suggest such feature as improvement for QGIS. – Juhele Mar 17 '17 at 10:55

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