0

I work with languages that use Unicode symbols in their placenames. I often receive layers with labels that are messed up, but they are messed up in the same way all the time eg: the place name shows Ñ but it should read K̲, or ñ should be k̲.

I have the code for a single find and replace, but I would like to batch find and replace all the problem letters at once. How do I string together several letter replacements?

This is the code I have to replace a single letter:

   replace("field",'find_value','replace_value')

But I would like it to fix all of these values at once:

  replace("Label",'Ñ','K̲')
  replace("Label",'Ý','X̲')
  replace("Label",'Ç','G̲')
  replace("Label",'ç','ɢ̲')
  • 5
    wouldn't it be better to fix the imported files encoding so it is not broken? – Ian Turton Jun 26 at 7:35
  • I don't know enough about these things to know how the file encoding gets broken. It has happened to a lot of shapefiles I get. They were all made a decade or so ago, and for whatever the reason, the attribute tables have altered unicode letters. It might be an ESRI to QGIS thing, but I don't have a way to test that. – CEdwards Jun 26 at 17:27
  • 1
    It just means that the default encoding is set wrong. Experiment with one of the shapefiles until it works and then set the default – Ian Turton Jun 26 at 18:27
  • I have since learned that the files are built to be used with a special font that was made to display/translate the unicode letters for this language (they show properly as labels when I use this particular font). But it is a font that does not display well for cartography (tall and thin with big serifs). So I would prefer to just quickly correct the formatting of the letters in the attribute table so that I can use any unicode font. – CEdwards Jun 26 at 19:21
2

You can use the map variant of replace, where the map is a series of key-value, the key being the string being searched for and the value being the replacement string

replace("Label",map('Ñ','K̲','Ý','X̲','Ç','G̲','ç','ɢ̲'))
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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