I have labels on my map that contain special characters as parts of place names (examples: ʔ, ·, ⱡ). They appear correct in the attribute table but on the display and when I export as a PDF, the characters change to "?".
Solved! Go to Solution.
Had to manually change the special characters to a different, unique string of characters (eg., "$#a", "$#b", etc.). Then, I managed some success with a label expression in Python:
def FindLabel([Label]):
new = [Label].replace("$#a", "ʔ").replace("$#b", "q̓").replace("$#c", "ō").replace("$#c", "ō").replace("$#d", "á").replace("$#e", "é").replace("$#f", "ŝ").replace("$#g", "ś").replace("$#h", "ū").replace("$#i", "·").replace("$#j", "ⱡ")
return new
For example: I would write the Label field for "abʔcⱡde" as "ab$#ac$#jde" and then use the expression above to plot the labels with the correct characters.
Happy to hear it's resolved. Although I think there should be a better way for the first part to not do that manually. I will add that later if I figure out.
By the way, to make this function more general to work in other cases and also to avoid writing very long lines which are hard to read and are prone to error, you can define all the changes in a dictionary and pass the key and value pairs of that dictionary to replace().
# a dictionary that can define required changes
# This way it can be edited easily
changes = {"$#a": "ʔ",
"$#b": "q̓",
"$#c": "ō",
"$#c": "ō",
"$#d": "á",
"$#e": "é",
"$#f": "ŝ",
"$#g": "ś",
"$#h": "ū",
"$#i": "·",
"$#j": "ⱡ"}
def fix_label_char(label:str, change_dict:dict, report:bool=False)->str:
"""Takes a str(text)and a dictionry of changes
then applies it to the text and
returns the new text (if any changes made),
otherwise original text gets returned.
It can also print the changes if report=True
report is off by default """
new_label = label
for key,val in change_dict.items():
new_label = new_label.replace(key, val)
# report section
if label == new_label and report:
print(f'No changes applied to {label}!')
elif label != new_label and report:
print(f'Changed {label} ---> {new_label}')
else:
pass
return new_label
Thanks! And yes, my coding experience is limited to R so I kind of just brute-forced my way through StackExchange to make that expression for this particular use-case. I just wished that the Arc attribute table would preserve the special characters.