Capitalizing Only the First Letter of the First Word in QGIS
In Geographic Information Systems (GIS), attribute data is rarely perfect. Often, you will import a dataset where text is in ALL CAPS or messy camelCase. While the title() function in QGIS capitalizes every word, professional cartography often requires Sentence case—where only the first letter of the first word is capitalized, and the rest remains lowercase. In 2026, the QGIS Expression Engine remains the most powerful tool for this cleanup.
1. The Problem with Standard QGIS Functions
QGIS provides several built-in string functions, but none perform "Sentence case" out of the box:
upper(): MAKES EVERYTHING CAPITAL.lower(): makes everything lowercase.title(): Makes Every Word Capitalized.
To achieve "Only the first letter of the first word," we must combine string manipulation functions to handle the head and the tail of the string separately.
2. The "Super User" Expression
Open the Field Calculator or the Labeling Expression dialog and use the following formula. Replace "YourField" with your actual attribute name:
upper(left("YourField", 1)) || lower(substr("YourField", 2))
How It Works:
- upper(left("YourField", 1)): This extracts the very first character and forces it to uppercase.
- ||: This is the string concatenation operator that joins the two parts together.
- lower(substr("YourField", 2)): This takes the entire string starting from the second character (position 2) and forces it to lowercase.
3. Handling Edge Cases: Trimming Whitespace
If your data has leading spaces, the left() function will capitalize the space instead of the letter, resulting in no visible change. To fix this, wrap your field in the trim() function:
upper(left(trim("YourField"), 1)) || lower(substr(trim("YourField"), 2))
4. Comparison of Text Formatting Results
| Original Data | QGIS Function | Resulting Output |
|---|---|---|
| MAIN STREET | title() |
Main Street |
| MAIN STREET | lower() |
main street |
| MAIN STREET | Sentence Case Expression | Main street |
5. Advanced: Applying to Labels Only
You don't always need to change the underlying data. You can apply this formatting dynamically in the Labeling Toolbar. This keeps your raw data intact while ensuring your map looks professional. Simply click the ε (Expression) button next to the Label field and paste the expression above.
Conclusion
Formatting text to capitalize only the first letter is a fundamental "Super User" skill for cleaning GIS datasets in 2026. By combining upper(), lower(), and substr(), you gain total control over your map's typography. This approach is essential for creating clean, readable legends and labels that follow standard grammatical rules rather than software defaults.
Keywords
QGIS capitalize first letter only, QGIS sentence case expression, format text QGIS field calculator, QGIS title vs sentence case, GIS string manipulation tutorial 2026, QGIS substr function example, clean attribute data QGIS, QGIS labeling expressions.
