QGIS Function to make strings ascii only
✓ Published0🌍 Public
GGeoWill
Last edited Sep 3, 2018
Created on Sep 3, 2018
This example demonstrates a custom QGIS function that converts place names into lowercase ASCII-only strings, replacing spaces with hyphens and translating accented characters like ß, à, and ñ to their closest ASCII equivalents. The function, defined with the `@qgsfunction` decorator and grouped under 'Custom', uses Python’s string methods `lower()`, `replace()`, and `translate()` with a manually defined `ascii_dict` mapping Unicode code points to replacement strings. It is designed for use in QGIS expression engines, taking a string input and returning the cleaned version. The code also includes a commented-out alternative using `encode('ascii', 'asciify')`, but the active path relies entirely on the translation dictionary.
AI-generated description