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
make sure eyou are using the right formatting in your label expressions.
Unfortunately, I cannot find any HTML codes for the characters I need.
Have you tried other fonts that contain those special characters?
Okay, I have found the relevant HTML codes. My label expression is as follows but no matter what font I try, it does not change the label.
Function FindLabel ([CmmntN1])
NewString = Replace([CmmntN1], "ⱡ", "ⱡ")
NewString = Replace([CmmntN1], "ʔ", "ʔ")
NewString = Replace([CmmntN1], "·", "·")
FindLabel = NewString
End Function
Now I realize, even after updating the attribute table with the correct symbols and saving the edits, when I reopen the attribute table, the characters return to ?.
If you are not getting attributes in your attribute table the only thing I can think of is the data type for that field is wrong.
The attributes are fine, just those few special characters change from ʔ to ?
Look at your field length in field view
Field is "text" and length is 80