QGIS-是否可以在属性表中将重音字符转换为普通字符?[关闭]


9

我有OSM数据集,其中包含带有国家字符的名称(这是CSV导出,但是我在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

并希望将它们转换为以下形式:

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

删除了重音符号,因此您将“ c,s,r,a”代替“č,š,ř,á”等。我不必编辑当前列-可以使用转换后的名称创建新列。

我目前打算使用像一些在线工具,这一个 CSV文件,但是这将是巨大的,如果我能在QGIS直接解决这个问题。


1
为什么没有话题?我主要是在寻求QGIS的直接解决方案,而无需将数据导出到CSV并再次导入。
Juhele

Answers:


9

是的,使用python ...中的unidecode库是可能的(文档)。这将尝试查找与每个Unicode字符等效的最接近的ASCII。

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))

输出:-

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

此代码会将一个CSV文件转换为另一个:-

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
嗯,看来我无法避免以CSV格式汇出并汇回。我可能会建议对QGIS进行改进等功能。
Juhele
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.